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.
48 lines
1.9 KiB
48 lines
1.9 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 ProductController : SharedController<IoTProduct, EditProductModel>
|
|
{
|
|
private readonly AjaxBaseController _ajax;
|
|
|
|
public ProductController(IRepository<IoTProduct> repo, AjaxBaseController ajax, IServiceProvider sp) : base(repo, sp)
|
|
{
|
|
this._ajax = ajax;
|
|
}
|
|
|
|
public override IQueryable<IoTProduct> Include(IQueryable<IoTProduct> query)
|
|
{
|
|
return query.Include(o => o.Category);
|
|
}
|
|
|
|
public override IQueryable<IoTProduct> Query(PagedListModel<EditProductModel> model, IQueryable<IoTProduct> query)
|
|
{
|
|
return base.Query(model, query)
|
|
.WhereIf(model.Query.CategoryId.HasValue, o => o.CategoryId == model.Query.CategoryId.Value)
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name))
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Number), o => o.Number.Contains(model.Query.Number))
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Path), o => o.Path.Contains(model.Query.Path))
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.ApiJson), o => o.ApiJson.Contains(model.Query.ApiJson))
|
|
.OrderBy(o => o.DisplayOrder);
|
|
}
|
|
|
|
public override void ToDisplayModel(IoTProduct entity, EditProductModel model)
|
|
{
|
|
ViewData.Add(entity.CategoryId, entity.Category.Name);
|
|
}
|
|
|
|
public override void ToEditModel(IoTProduct entity, EditProductModel model)
|
|
{
|
|
ViewData.SelectList(o => model.CategoryId, () => this._ajax.GetCategorySelectList(model.CategoryId));
|
|
}
|
|
}
|
|
}
|