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.
84 lines
4.0 KiB
84 lines
4.0 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 Platform.Application.Models.IoTCenter;
|
|
using Platform.Areas.IoTCenter.Controllers;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace IoT.Shared.Areas.IoTCenter.Controlls
|
|
{
|
|
[Authorize]
|
|
[ApiController]
|
|
[Route("IoTCenter/[controller]/[action]")]
|
|
[Area("IoTCenter")]
|
|
[ControllerScope(ControllerScopeType.Platform)]
|
|
public class IoTParameterController : CrudController<IoTParameter, EditPlatformIoTParameterModel>
|
|
{
|
|
private readonly AjaxController _ajax;
|
|
private readonly IRepository<IoTProductCategory> _categoryRepo;
|
|
|
|
public IoTParameterController(IRepository<IoTParameter> repo, AjaxController ajax, IRepository<IoTProductCategory> categoryRepo) : base(repo)
|
|
{
|
|
this._ajax = ajax;
|
|
this._categoryRepo = categoryRepo;
|
|
}
|
|
|
|
public override IQueryable<IoTParameter> Include(IQueryable<IoTParameter> query)
|
|
{
|
|
return query.Include(o => o.IoTApi).ThenInclude(o => o.Product).ThenInclude(o => o.IoTProductCategory);
|
|
}
|
|
|
|
public override IQueryable<IoTParameter> Query(PagedListModel<EditPlatformIoTParameterModel> model, IQueryable<IoTParameter> query)
|
|
{
|
|
return base.Query(model, query)
|
|
.WhereIf(model.Query.CategoryId.HasValue, o => o.IoTApi.Product.IoTProductCategoryId == model.Query.CategoryId.Value)
|
|
.WhereIf(model.Query.ProductId.HasValue, o => o.IoTApi.IoTProductId == model.Query.ProductId.Value)
|
|
.WhereIf(model.Query.ApiId.HasValue, o => o.IoTApiId == model.Query.ApiId.Value)
|
|
.WhereIf(model.Query.Required.HasValue, o => o.Required == model.Query.Required.Value)
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Type), o => o.Type.Contains(model.Query.Type))
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name))
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Description), o => o.Description.Contains(model.Query.Description));
|
|
}
|
|
public override void EntityToModel(IoTParameter entity, EditPlatformIoTParameterModel model)
|
|
{
|
|
model.ProductId = entity.IoTApi.IoTProductId;
|
|
model.CategoryId = entity.IoTApi.Product.IoTProductCategoryId;
|
|
}
|
|
public override void ToDisplayModel(IoTParameter entity, EditPlatformIoTParameterModel model)
|
|
{
|
|
if (entity != null)
|
|
{
|
|
ViewData.Add(model.ApiId, entity.IoTApi.Name);
|
|
}
|
|
if (model.CategoryId.HasValue)
|
|
{
|
|
var name = this._categoryRepo.ReadOnlyTable()
|
|
.Where(o => o.ParentId != null)
|
|
.Where(o => o.Left <= entity.IoTApi.Product.IoTProductCategory.Left && o.Right >= entity.IoTApi.Product.IoTProductCategory.Right)
|
|
.ToList()
|
|
.ToTree()
|
|
.FirstOrDefault(o => o.Id == model.CategoryId.Value)?.GetDisplayName();
|
|
ViewData.Add(model.CategoryId, name);
|
|
}
|
|
if(model.ProductId.HasValue)
|
|
{
|
|
ViewData.Add(model.ProductId, entity.IoTApi.Product.Name);
|
|
}
|
|
}
|
|
|
|
public override void ToEditModel(IoTParameter entity, EditPlatformIoTParameterModel model)
|
|
{
|
|
ViewData.SelectList(o => model.CategoryId, () => this._ajax.GetIoTProductCategory(model.CategoryId).SelectList());
|
|
ViewData.SelectList(o => model.ProductId, () => this._ajax.GetIoTProductByCategory(model.CategoryId.Value, model.ProductId).SelectList(), model.CategoryId.HasValue);
|
|
ViewData.SelectList(o => model.ApiId, () => this._ajax.GetIoTApi(model.ProductId.Value, model.ApiId).SelectList(), model.ProductId.HasValue);
|
|
}
|
|
}
|
|
}
|