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.3 KiB
60 lines
2.3 KiB
using Infrastructure.Application;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Infrastructure.Web.Mvc;
|
|
using IoT.Shared.Application.Domain.Entities;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Platform.Application.Models;
|
|
using Platform.Areas.IoTCenter.Controllers;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace Platform.Areas.UserCenter.Controllers
|
|
{
|
|
[Authorize]
|
|
[ApiController]
|
|
[Route("UserCenter/[controller]/[action]")]
|
|
[Area("UserCenter")]
|
|
[ControllerScope(ControllerScopeType.Platform)]
|
|
public class AreaController : TreeCrudController<Area, EditAreaModel>
|
|
{
|
|
private readonly AjaxController _ajax;
|
|
|
|
public AreaController(IRepository<Area> repo, AjaxController ajax) : base(repo)
|
|
{
|
|
this._ajax = ajax;
|
|
}
|
|
|
|
public override IQueryable<Area> Query(PagedListModel<EditAreaModel> model, IQueryable<Area> query)
|
|
{
|
|
return query
|
|
.Where(o => o.ParentId != null)
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name))
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Number), o => o.Name.Contains(model.Query.Number))
|
|
.WhereIf(model.Query.Type.HasValue, o => o.Type == model.Query.Type.Value)
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.CustomType), o => o.CustomType.Contains(model.Query.CustomType))
|
|
.WhereIf(model.Query.ParentId.HasValue, o => o.ParentId == model.Query.ParentId.Value)
|
|
.OrderBy(o => o.ParentId).ThenBy(o => o.DisplayOrder);
|
|
}
|
|
|
|
public override void ToDisplayModel(Area entity, EditAreaModel model)
|
|
{
|
|
if (model.ParentId.HasValue)
|
|
{
|
|
var name = this.Repo.ReadOnlyTable()
|
|
.Where(o => o.Left < entity.Left && o.Left > 1).ToList()
|
|
.ToList()
|
|
.ToTree()
|
|
.FirstOrDefault(o => o.Id == model.ParentId.Value)?.GetDisplayName();
|
|
ViewData.Add(model.ParentId.Value, name);
|
|
}
|
|
}
|
|
|
|
public override void ToEditModel(Area entity, EditAreaModel model)
|
|
{
|
|
ViewData.SelectList(o => model.ParentId, () => this._ajax.GetArea(model.ParentId).SelectList());
|
|
}
|
|
}
|
|
} |