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.
82 lines
3.5 KiB
82 lines
3.5 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.Linq;
|
|
|
|
namespace Platform.Areas.Admin.Controllers
|
|
{
|
|
[Authorize]
|
|
[ApiController]
|
|
[Route("Admin/[controller]/[action]")]
|
|
[Area("Admin")]
|
|
[ControllerScope(ControllerScopeType.Platform)]
|
|
public class BuildingController : TreeCrudController<Building, EditBuildingModel>
|
|
{
|
|
private readonly AjaxController _ajax;
|
|
private readonly IRepository<Organ> _organRepo;
|
|
|
|
public BuildingController(IRepository<Building> repo, AjaxController ajax, IRepository<Organ> organRepo) : base(repo)
|
|
{
|
|
this._ajax = ajax;
|
|
this._organRepo = organRepo;
|
|
}
|
|
|
|
public override IQueryable<Building> Include(IQueryable<Building> query)
|
|
{
|
|
return query.Include(o => o.Organ);
|
|
}
|
|
|
|
public override IQueryable<Building> Query(PagedListModel<EditBuildingModel> model, IQueryable<Building> query)
|
|
{
|
|
return query
|
|
.Where(o => o.ParentId != null)
|
|
.WhereIf(model.Query.ParentId.HasValue, o => o.ParentId == model.Query.ParentId.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(model.Query.Type.HasValue, o => o.Type == model.Query.Type.Value)
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.CustomType), o => o.CustomType.Contains(model.Query.CustomType))
|
|
.OrderBy(o => o.Organ.Id).ThenBy(o => o.ParentId).ThenBy(o => o.Type).ThenBy(o => o.CustomType).ThenBy(o => o.DisplayOrder);
|
|
}
|
|
|
|
public override void ToDisplayModel(Building entity, EditBuildingModel model)
|
|
{
|
|
if (entity.ParentId.HasValue)
|
|
{
|
|
var name = this.Repo.ReadOnlyTable()
|
|
.Where(o=>o.ParentId!=null)
|
|
.Where(o => o.Left < entity.Left && o.Right > entity.Right)
|
|
.ToList()
|
|
.ToTree()
|
|
.FirstOrDefault(o => o.Id == model.ParentId.Value)?.GetDisplayName();
|
|
ViewData.Add(model.ParentId.Value, name);
|
|
}
|
|
if (entity != null)
|
|
{
|
|
var name = this._organRepo.ReadOnlyTable()
|
|
.Where(o => o.ParentId != null)
|
|
.Where(o => o.Left <= entity.Organ.Left && o.Right >= entity.Organ.Right)
|
|
.ToList()
|
|
.ToTree()
|
|
.FirstOrDefault(o => o.Id == entity.OrganId)?.GetDisplayName();
|
|
ViewData.Add(model.OrganId, name);
|
|
}
|
|
}
|
|
|
|
public override void ToEditModel(Building entity, EditBuildingModel model)
|
|
{
|
|
base.ToEditModel(entity, model);
|
|
this.ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList());
|
|
if (model.OrganId.HasValue)
|
|
{
|
|
ViewData.SelectList(o => model.ParentId, () => this._ajax.GetBuilding(model.OrganId.Value, model.ParentId).SelectList());
|
|
}
|
|
}
|
|
}
|
|
} |