using Infrastructure.Application; using Infrastructure.Data; using Infrastructure.Extensions; using IoT.Shared.Application.Domain.Entities; using IoT.Shared.Application.Models; using Microsoft.EntityFrameworkCore; using System; using System.Linq; namespace IoT.Shared.Areas.IoTCenter.Controlls { public class ApiController : SharedController { private readonly AjaxBaseController _ajax; public ApiController(IRepository repo, AjaxBaseController ajax, IServiceProvider sp) : base(repo, sp) { 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.GetProductSelectList(model.Query.ProductId)); 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, EditApiModel model) { if (entity != null) { ViewData.Add(model.ProductId, entity.Product.Name); } } public override void ToEditModel(IoTApi entity, EditApiModel model) { this.ToDisplayModel(entity, model); ViewData.SelectList(o => model.ProductId, () => this._ajax.GetProductSelectList(model.ProductId)); } } }