using Infrastructure.Application; using Infrastructure.Data; using Infrastructure.Extensions; using Infrastructure.Web.Mvc; using IoT.Shared.Application.Domain.Entities; using IoT.Shared.Application.Models; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using System; using System.Linq; namespace IoT.Shared.Areas.IoTCenter.Controlls { [Authorize] [ApiController] [Route("IoTCenter/[controller]/[action]")] [Area("IoTCenter")] [ControllerScope(ControllerScopeType.Platform)] public class IoTApiController : CrudController { private readonly AjaxBaseController _ajax; public IoTApiController(IRepository repo, AjaxBaseController ajax) : base(repo) { this._ajax = ajax; } public override IQueryable Include(IQueryable query) { return query.Include(o => o.Product); } public override IQueryable Query(PagedListModel model, IQueryable query) { ViewData.SelectList(o => model.Query.ProductId, () => this._ajax.GetIoTProduct(model.Query.ProductId).SelectList()); return query .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)) .WhereIf(!string.IsNullOrEmpty(model.Query.Command), o => o.Command.Contains(model.Query.Command)) .WhereIf(!string.IsNullOrEmpty(model.Query.Method), o => o.Method.Contains(model.Query.Method)); } public override void ToDisplayModel(IoTApi entity, EditIoTApiModel model) { ViewData.Add(model.ProductId, entity?.Product?.Name); } public override void ToEditModel(IoTApi entity, EditIoTApiModel model) { this.ToDisplayModel(entity, model); ViewData.SelectList(o => model.ProductId, () => this._ajax.GetIoTProduct(model.ProductId).SelectList()); } } }