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/IoTNode/Areas/IoTCenter/Controllers/IoTApiController.cs

57 lines
2.2 KiB

using Infrastructure.Application;
using Infrastructure.Data;
using Infrastructure.Extensions;
using Infrastructure.Web.Mvc;
using 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<IoTApi, EditIoTApiModel>
{
private readonly AjaxBaseController _ajax;
public IoTApiController(IRepository<IoTApi> repo, AjaxBaseController ajax) : base(repo)
{
this._ajax = ajax;
}
public override IQueryable<IoTApi> Include(IQueryable<IoTApi> query)
{
return query.Include(o => o.Product);
}
public override IQueryable<IoTApi> Query(PagedListModel<EditIoTApiModel> model, IQueryable<IoTApi> query)
{
ViewData.SelectList(o => model.Query.IoTProductId, () => this._ajax.GetIoTProduct(model.Query.IoTProductId).SelectList());
return query
.WhereIf(model.Query.IoTProductId.HasValue, o => o.IoTProductId == model.Query.IoTProductId.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.IoTProductId, entity?.Product?.Name);
}
public override void ToEditModel(IoTApi entity, EditIoTApiModel model)
{
this.ToDisplayModel(entity, model);
ViewData.SelectList(o => model.IoTProductId, () => this._ajax.GetIoTProduct(model.IoTProductId).SelectList());
}
}
}