You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/IoT.Shared/Areas/IoTCenter/Controlls/ApiController.cs

52 lines
2.0 KiB

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<IoTApi, EditApiModel>
{
private readonly AjaxBaseController _ajax;
public ApiController(IRepository<IoTApi> repo, AjaxBaseController ajax, IServiceProvider sp) : base(repo, sp)
{
this._ajax = ajax;
}
public override IQueryable<IoTApi> Include(IQueryable<IoTApi> query)
{
return query.Include(o => o.Product);
}
public override IQueryable<IoTApi> Query(PagedListModel<EditApiModel> model, IQueryable<IoTApi> 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));
}
}
}