@ -7,6 +7,8 @@ using IoT.Shared.Application.Models;
using Microsoft.AspNetCore.Authorization ;
using Microsoft.AspNetCore.Mvc ;
using Microsoft.EntityFrameworkCore ;
using Platform.Application.Models.IoTCenter ;
using Platform.Areas.IoTCenter.Controllers ;
using System ;
using System.Linq ;
@ -17,24 +19,27 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls
[Route("IoTCenter/[controller] / [ action ] ")]
[Area("IoTCenter")]
[ControllerScope(ControllerScopeType.Platform)]
public class IoTApiController : CrudController < IoTApi , Edit ApiModel>
public class IoTApiController : CrudController < IoTApi , Edit PlatformIoT ApiModel>
{
private readonly AjaxBaseController _ajax ;
private readonly AjaxController _ajax ;
private readonly IRepository < IoTProductCategory > _categoryRepo ;
public IoTApiController ( IRepository < IoTApi > repo , Ajax Base Controller ajax ) : base ( repo )
public IoTApiController ( IRepository < IoTApi > repo , Ajax Controller ajax , IRepository < IoTProductCategory > categoryRepo ) : base ( repo )
{
this . _ajax = ajax ;
this . _categoryRepo = categoryRepo ;
}
public override IQueryable < IoTApi > Include ( IQueryable < IoTApi > query )
{
return query . Include ( o = > o . Product ) ;
return query . Include ( o = > o . Product ) .ThenInclude ( o = > o . Category ) ;
}
public override IQueryable < IoTApi > Query ( PagedListModel < Edit ApiModel> model , IQueryable < IoTApi > query )
public override IQueryable < IoTApi > Query ( PagedListModel < Edit PlatformIoT ApiModel> model , IQueryable < IoTApi > query )
{
ViewData . SelectList ( o = > model . Query . ProductId , ( ) = > this . _ajax . GetIoTProduct ( model . Query . ProductId ) . SelectList ( ) ) ;
return query
. WhereIf ( model . Query . CategoryId . HasValue , o = > o . Product . CategoryId = = model . Query . CategoryId . Value )
. WhereIf ( model . Query . ProductId . HasValue , o = > o . ProductId = = model . Query . ProductId . Value )
. WhereIf ( ! string . IsNullOrEmpty ( model . Query . Name ) , o = > o . Name . Contains ( model . Query . Name ) )
. WhereIf ( ! string . IsNullOrEmpty ( model . Query . Path ) , o = > o . Path . Contains ( model . Query . Path ) )
@ -42,15 +47,37 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls
. WhereIf ( ! string . IsNullOrEmpty ( model . Query . Method ) , o = > o . Method . Contains ( model . Query . Method ) ) ;
}
public override void ToDisplayModel ( IoTApi entity , Edit ApiModel model )
public override void ToDisplayModel ( IoTApi entity , Edit PlatformIoT ApiModel model )
{
ViewData . Add ( model . ProductId , entity ? . Product ? . Name ) ;
model . CategoryId = entity ? . Product ? . CategoryId ;
if ( entity ! = null )
{
ViewData . Add ( model . ProductId . Value , entity . Product . Name ) ;
}
if ( model . CategoryId . HasValue )
{
var name = this . _categoryRepo . ReadOnlyTable ( )
. Where ( o = > o . ParentId ! = null )
. Where ( o = > o . Left < = entity . Product . Category . Left & & o . Right > = entity . Product . Category . Right )
. ToList ( )
. ToTree ( )
. FirstOrDefault ( o = > o . Id = = model . CategoryId . Value ) ? . GetDisplayName ( ) ;
ViewData . Add ( model . CategoryId . Value , name ) ;
}
}
public override void ToEditModel ( IoTApi entity , EditApiModel model )
public override void ToEditModel ( IoTApi entity , Edit PlatformIoT ApiModel model )
{
this . ToDisplayModel ( entity , model ) ;
ViewData . SelectList ( o = > model . ProductId , ( ) = > this . _ajax . GetIoTProduct ( model . ProductId ) . SelectList ( ) ) ;
model . CategoryId = entity ? . Product ? . CategoryId ;
ViewData . SelectList ( o = > model . CategoryId , ( ) = > this . _ajax . GetIoTProductCategory ( model . CategoryId ) . SelectList ( ) ) ;
if ( model . CategoryId . HasValue )
{
ViewData . SelectList ( o = > model . ProductId , ( ) = > this . _ajax . GetIoTProductByCategory ( model . CategoryId . Value , model . ProductId ) . SelectList ( ) ) ;
}
else
{
ViewData . Add ( model . ProductId , entity ? . Product ? . Name ) ;
}
}
}
}