using DTO;
|
using IServices;
|
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.Extensions.Logging;
|
using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Threading.Tasks;
|
using zhengcaioa.IService;
|
using zhengcaioa.Models;
|
|
namespace zhengcaioa.Controllers.settings
|
{
|
|
public class AreaController : Controller
|
{
|
private readonly ILogger<AreaController> _logger;
|
private readonly IAreaService _areaService;
|
|
|
|
[CheckLogin]
|
public AreaController(ILogger<AreaController> logger, IAreaService areaService)
|
{
|
_logger = logger;
|
_areaService = areaService;
|
}
|
[CheckLogin]
|
public IActionResult Index()
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
List<ActionEntity> actionlist = new List<ActionEntity>();
|
ActionEntity actionEntity = new ActionEntity();
|
actionEntity.OpenType = 0;
|
actionEntity.ActionUrl = "";
|
actionEntity.ActionFun = "Search";
|
actionEntity.PageIco = "fa fa-search";
|
actionEntity.ActionName = "查询";
|
actionlist.Add(actionEntity);
|
ActionEntity actionEntity1 = new ActionEntity();
|
actionEntity1.OpenType = 0;
|
actionEntity1.ActionUrl = "";
|
actionEntity1.ActionFun = "Add";
|
actionEntity1.PageIco = "fa fa-plus";
|
actionEntity1.ActionName = "新增";
|
actionlist.Add(actionEntity1);
|
ViewData["ActionInfo"] = actionlist;
|
return View();
|
}
|
|
[CheckLogin]
|
public string GetList(AreaDTOSearch search)
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
//JsonResult jsonResult = new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver());
|
return JsonConvert.SerializeObject(_areaService.SearchByPaging(search));
|
}
|
|
|
#region 编辑
|
[CheckLogin]
|
public ActionResult Edit()
|
{
|
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
List<ActionEntity> actionlist = new List<ActionEntity>();
|
ActionEntity actionEntity = new ActionEntity();
|
actionEntity.OpenType = 0;
|
actionEntity.ActionUrl = "";
|
actionEntity.ActionFun = "Save";
|
actionEntity.PageIco = "glyphicon glyphicon-ok";
|
actionEntity.ActionName = "保存";
|
actionlist.Add(actionEntity);
|
ActionEntity actionEntity1 = new ActionEntity();
|
actionEntity1.OpenType = 0;
|
actionEntity1.ActionUrl = "";
|
actionEntity1.ActionFun = "Nullify";
|
actionEntity1.PageIco = "fa fa-remove";
|
actionEntity1.ActionName = "删除";
|
actionlist.Add(actionEntity1);
|
ViewData["ActionInfo"] = actionlist;
|
ViewBag.ParentId = _areaService.GetList().Select(x => new { code = x.CodeId, label = x.Name }).ToList();
|
|
return View();
|
}
|
|
|
|
|
|
|
[CheckLogin]
|
public IActionResult Get(string id = null)
|
{
|
AreaDTO AreaDTO = new AreaDTO();
|
if (!String.IsNullOrEmpty(id))
|
{
|
AreaDTO = _areaService.Get(id);
|
}
|
|
// ViewData.Model = PltUserDTO;
|
return new JsonResult(AreaDTO);
|
}
|
|
|
/// <summary>
|
/// 保存
|
/// </summary>
|
/// <param name="data">岗位实体类对象</param>
|
/// <returns></returns>
|
[HttpPost]
|
[CheckLogin]
|
public IActionResult Save(AreaDTO data)
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
|
|
ResultEntity resultEntity = _areaService.save(data);
|
|
return new JsonResult(resultEntity);
|
}
|
#endregion
|
|
/// <summary>
|
/// 删除主信息
|
/// </summary>
|
/// <param name="info">实体</param>
|
/// <returns></returns>
|
///
|
[CheckLogin]
|
public IActionResult Nullify(string Id = "")
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
return new JsonResult(_areaService.ModifyStatus(Id, curentuser.Id));
|
}
|
|
|
|
|
public IActionResult GetListArea()
|
{
|
ReturnMsg<List<AreaDTO>> returnMsg = new ReturnMsg<List<AreaDTO>>();
|
returnMsg.code = 1;
|
returnMsg.error = "";
|
|
|
List <AreaDTO> areaDTOs = _areaService.GetList();
|
|
List<AreaDTO> areaDTOshengs = areaDTOs.Where(x => x.ParentId == "0 ").ToList();
|
|
|
foreach(var areaDTOsheng in areaDTOshengs)
|
{
|
var childs = areaDTOs.Where(x => x.ParentId == areaDTOsheng.CodeId).ToList();
|
foreach(var child in childs)
|
{
|
child.Children = areaDTOs.Where(x => x.ParentId == child.CodeId).ToList();
|
}
|
areaDTOsheng.Children = childs;
|
}
|
|
|
|
|
|
returnMsg.returnObj = areaDTOshengs;
|
returnMsg.count = areaDTOs.Count;
|
|
return new JsonResult(returnMsg);
|
}
|
}
|
}
|