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.
54 lines
1.9 KiB
54 lines
1.9 KiB
using Application.Domain.Entities;
|
|
using Infrastructure.Application;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Infrastructure.Web.Mvc;
|
|
using IoT.Shared.Application.Models;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Platform.Areas.IoTCenter.Controllers;
|
|
using System.Linq;
|
|
|
|
namespace Platform.Areas.Admin.Controllers
|
|
{
|
|
[Authorize]
|
|
[ApiController]
|
|
[Route("Admin/[controller]/[action]")]
|
|
[Area("Admin")]
|
|
[ControllerScope(ControllerScopeType.Platform)]
|
|
public class DictionaryItemController : CrudController<DictionaryItem, EditDictionaryItemModel>
|
|
{
|
|
private readonly AjaxController _ajax;
|
|
|
|
public DictionaryItemController(IRepository<DictionaryItem> repo, AjaxController ajax) : base(repo)
|
|
{
|
|
this._ajax = ajax;
|
|
}
|
|
|
|
public override IQueryable<DictionaryItem> Query(PagedListModel<EditDictionaryItemModel> model, IQueryable<DictionaryItem> query)
|
|
{
|
|
return base.Query(model, query)
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name))
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Value), o => o.Name.Contains(model.Query.Value));
|
|
}
|
|
|
|
public override IQueryable<DictionaryItem> Include(IQueryable<DictionaryItem> query)
|
|
{
|
|
return query.Include(o=>o.Category);
|
|
}
|
|
|
|
public override void ToDisplayModel(DictionaryItem entity, EditDictionaryItemModel model)
|
|
{
|
|
if(model.CategoryId.HasValue)
|
|
{
|
|
ViewData.Add(model.CategoryId.HasValue, entity.Category.Name);
|
|
}
|
|
}
|
|
|
|
public override void ToEditModel(DictionaryItem entity, EditDictionaryItemModel model)
|
|
{
|
|
this.ViewData.SelectList(o => model.CategoryId, () => this._ajax.GetDictionaryCategory(model.CategoryId).SelectList());
|
|
}
|
|
}
|
|
} |