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.
41 lines
1.3 KiB
41 lines
1.3 KiB
using Application.Domain.Entities;
|
|
using Application.Models;
|
|
using Infrastructure.Application;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Infrastructure.Web.Mvc;
|
|
using IoT.Shared.Areas.Admin.Controllers;
|
|
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, PagedListModel<EditProductModel>, EditProductModel, 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 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));
|
|
}
|
|
}
|
|
} |