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/Platform/Areas/IoTCenter/Controllers/OrganSceneController.cs

57 lines
2.1 KiB

using Infrastructure.Application;
using Infrastructure.Data;
using Infrastructure.Extensions;
using Infrastructure.Web.Mvc;
using IoT.Shared.Application.Domain.Entities;
using IoT.Shared.Areas.IoTCenter.Controlls;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Platform.Application.Models;
using System.Linq;
namespace Platform.Areas.IoTCenter.Controllers
{
[Authorize]
[ApiController]
[Route("IoTCenter/[controller]/[action]")]
[Area("IoTCenter")]
public class OrganSceneController : CrudController<OrganIoTScene, EditOrganSceneModel>
{
private readonly AjaxController _ajax;
public OrganSceneController(IRepository<OrganIoTScene> repo, AjaxController ajax) : base(repo)
{
this._ajax = ajax;
}
public override IQueryable<OrganIoTScene> Include(IQueryable<OrganIoTScene> query)
{
return query.Include(o => o.Organ);
}
public override IQueryable<OrganIoTScene> Query(PagedListModel<EditOrganSceneModel> model, IQueryable<OrganIoTScene> query)
{
ViewData.SelectList(o => model.Query.OrganId, () => this._ajax.GetOrgan(model.Query.OrganId).SelectList());
return query
.WhereIf(model.Query.OrganId.HasValue, o => o.OrganId == model.Query.OrganId.Value)
.WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name))
.WhereIf(model.Query.Hidden.HasValue, o => o.Hidden == model.Query.Hidden.Value)
.OrderBy(o => o.DisplayOrder);
}
public override void ToDisplayModel(OrganIoTScene entity, EditOrganSceneModel model)
{
if (entity != null)
{
ViewData.Add(model.OrganId, entity.Organ.Name);
}
}
public override void ToEditModel(OrganIoTScene entity, EditOrganSceneModel model)
{
ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList());
}
}
}