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/Admin/Controlls/ProductController.cs

51 lines
2.0 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 ProductController : CrudController<Product, EditProductModel>
{
private readonly AjaxController _ajax;
public ProductController(IRepository<Product> repo, AjaxController ajax) : base(repo)
{
this._ajax = ajax;
}
public override IQueryable<Product> Include(IQueryable<Product> query)
{
return query.Include(o => o.Category);
}
public override IQueryable<Product> Query(PagedListModel<EditProductModel> model, IQueryable<Product> 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(Product entity, EditProductModel model)
{
ViewData.Add(entity.CategoryId, entity.Category.Name);
}
public override void ToEditModel(Product entity, EditProductModel model)
{
ViewData.SelectList(o => model.CategoryId, () => this._ajax.GetCategorySelectList(model.CategoryId));
}
}
}