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.
60 lines
2.6 KiB
60 lines
2.6 KiB
using Application.Domain.Entities;
|
|
using Application.Models;
|
|
using Infrastructure.Application;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Infrastructure.Web.Mvc;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Linq;
|
|
|
|
namespace IoT.Shared.Areas.Admin.Controlls
|
|
{
|
|
[Authorize]
|
|
[Area(nameof(Admin))]
|
|
public class ParameterController : CrudController<Parameter, EditParameterModel>
|
|
{
|
|
private readonly AjaxController _ajax;
|
|
|
|
public ParameterController(IRepository<Parameter> repo, AjaxController ajax) : base(repo)
|
|
{
|
|
this._ajax = ajax;
|
|
}
|
|
|
|
public override IQueryable<Parameter> Include(IQueryable<Parameter> query)
|
|
{
|
|
return query.Include(o => o.Api).ThenInclude(o => o.Product);
|
|
}
|
|
|
|
public override IQueryable<Parameter> Query(PagedListModel<EditParameterModel> model, IQueryable<Parameter> query)
|
|
{
|
|
return base.Query(model, query)
|
|
.WhereIf(model.Query.Required.HasValue, o => o.Required == model.Query.Required.Value)
|
|
.WhereIf(model.Query.ProductId.HasValue, o => o.Api.ProductId == model.Query.ProductId.Value)
|
|
.WhereIf(model.Query.ApiId.HasValue, o => o.ApiId == model.Query.ApiId.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))
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Minimum), o => o.Minimum == model.Query.Minimum)
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Maxinum), o => o.Maxinum == model.Query.Maxinum);
|
|
}
|
|
|
|
public override void ToDisplayModel(Parameter entity, EditParameterModel model)
|
|
{
|
|
if (entity != null)
|
|
{
|
|
model.ProductId = entity.Api.ProductId;
|
|
ViewData.Add(model.ApiId, entity.Api.Name);
|
|
ViewData.Add(model.ProductId, entity.Api.Product.Name);
|
|
}
|
|
}
|
|
|
|
public override void ToEditModel(Parameter entity, EditParameterModel model)
|
|
{
|
|
this.ToDisplayModel(entity, model);
|
|
ViewData.SelectList(o => model.ProductId, () => this._ajax.GetProductSelectList(model.ProductId));
|
|
ViewData.SelectList(o => model.ApiId, () => this._ajax.GetProductApiSelectList(model.ProductId.Value, model.ApiId), model.ProductId.HasValue);
|
|
}
|
|
}
|
|
} |