增加部门管理
This commit is contained in:
@@ -0,0 +1,158 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using COMCMS.Common;
|
||||
using COMCMS.Core;
|
||||
using XCode;
|
||||
using Newtonsoft.Json;
|
||||
using COMCMS.Web.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace COMCMS.Web.Areas.AdminCP.Controllers
|
||||
{
|
||||
public class DepartmentController : AdminBaseController
|
||||
{
|
||||
#region 部门管理
|
||||
/// <summary>
|
||||
/// 部门列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[MyAuthorize("viewlist", "department")]
|
||||
public IActionResult DepartmentList()
|
||||
{
|
||||
IList<Department> list = Department.GetListTree(0, -1, false, true);
|
||||
Core.Admin.WriteLogActions("查看部门列表页面;");
|
||||
return View(list);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
#region 添加部门
|
||||
[MyAuthorize("add", "department")]
|
||||
public IActionResult AddDepartment()
|
||||
{
|
||||
//获取上级栏目
|
||||
IList<Department> list = Department.GetListTree(0, 0, true, false);
|
||||
ViewBag.ListTree = list;
|
||||
Department entity = new Department();
|
||||
Core.Admin.WriteLogActions("查看添加部门页面;");
|
||||
return View(entity);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[MyAuthorize("add", "department", "JSON")]
|
||||
public IActionResult AddDepartment(Department model)
|
||||
{
|
||||
//获取上级栏目
|
||||
if (string.IsNullOrWhiteSpace(model.DepartmentName))
|
||||
{
|
||||
tip.Message = "部门名称不能为空!";
|
||||
return Json(tip);
|
||||
}
|
||||
|
||||
model.Insert();
|
||||
Core.Admin.WriteLogActions("添加部门(id:" + model.Id + ");");
|
||||
tip.Status = JsonTip.SUCCESS;
|
||||
tip.Message = "添加部门成功";
|
||||
tip.ReturnUrl = "close";
|
||||
|
||||
return Json(tip);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 编辑部门
|
||||
//编辑部门
|
||||
[HttpGet]
|
||||
[MyAuthorize("edit", "department")]
|
||||
public IActionResult EditDepartment(int id)
|
||||
{
|
||||
Department entity = Department.Find(Department._.Id == id);
|
||||
if (entity == null)
|
||||
{
|
||||
return EchoTipPage("系统找不到本记录!");
|
||||
}
|
||||
//获取上级栏目
|
||||
IList<Department> list = Department.GetListTree(0, 0, true, false);
|
||||
ViewBag.ListTree = list;
|
||||
Core.Admin.WriteLogActions("查看/编辑部门(id:" + id + ")页面;");
|
||||
return View(entity);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[MyAuthorize("edit", "department", "JSON")]
|
||||
public IActionResult EditDepartment(Department model)
|
||||
{
|
||||
if (model.Id <= 0)
|
||||
{
|
||||
tip.Message = "错误参数传递!";
|
||||
Json(tip);
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(model.DepartmentName))
|
||||
{
|
||||
tip.Message = "部门名称不能为空!";
|
||||
return Json(tip);
|
||||
}
|
||||
Department entity = Department.Find(Department._.Id == model.Id);
|
||||
if (entity == null)
|
||||
{
|
||||
tip.Message = "系统找不到本记录!";
|
||||
Json(tip);
|
||||
}
|
||||
//赋值
|
||||
|
||||
entity.DepartmentName = model.DepartmentName;
|
||||
entity.Pic = model.Pic;
|
||||
entity.DepartmentDescription = model.DepartmentDescription;
|
||||
entity.Rank = model.Rank;
|
||||
entity.Pic = model.Pic;
|
||||
entity.Tel = model.Tel;
|
||||
entity.Fax = model.Fax;
|
||||
entity.Email = model.Email;
|
||||
entity.IsNotAllowDel = Request.Form["IsNotAllowDel"] == "1" ? 1 : 0;
|
||||
//如果修改了路径
|
||||
if (entity.PId != model.PId)
|
||||
{
|
||||
entity.PId = model.PId;
|
||||
entity.Location = Department.GetNewLocation(model.PId);
|
||||
}
|
||||
entity.Save();
|
||||
|
||||
Core.Admin.WriteLogActions("修改部门(id:" + entity.Id + ");");
|
||||
tip.Status = JsonTip.SUCCESS;
|
||||
tip.Message = "修改部门成功";
|
||||
tip.ReturnUrl = "close";
|
||||
|
||||
return Json(tip);
|
||||
}
|
||||
|
||||
//删除栏目
|
||||
[HttpPost]
|
||||
[MyAuthorize("del", "department", "JSON")]
|
||||
public JsonResult DelDepartment(int id)
|
||||
{
|
||||
Department entity = Department.Find(Department._.Id == id);
|
||||
if (entity == null)
|
||||
{
|
||||
tip.Message = "系统找不到本部门!";
|
||||
return Json(tip);
|
||||
}
|
||||
if (Department.FindCount(Department._.PId == entity.Id, null, null, 0, 0) > 0)
|
||||
{
|
||||
tip.Message = "部门目有下级部门,不允许删除!";
|
||||
return Json(tip);
|
||||
}
|
||||
//删除文章
|
||||
|
||||
Core.Admin.WriteLogActions("删除部门(id:" + entity.Id + ");");
|
||||
entity.IsDel =1;
|
||||
entity.Update();
|
||||
tip.Status = JsonTip.SUCCESS;
|
||||
tip.Message = "删除部门成功";
|
||||
return Json(tip);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
@model Department
|
||||
@{
|
||||
ViewBag.title = "添加部门";
|
||||
}
|
||||
|
||||
<div class="wrapper wrapper-content">
|
||||
<div class="ibox float-e-margins">
|
||||
<div class="ibox-title">
|
||||
<h5>@ViewBag.Title</h5>
|
||||
<div class="ibox-tools">
|
||||
</div>
|
||||
</div>
|
||||
<div class="ibox-content">
|
||||
<form id="addDepartmentForm" class="form-horizontal m-t" method="post">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">上级部门:</label>
|
||||
<div class="col-sm-8">
|
||||
<select class="form-control m-b" name="PId" id="PId">
|
||||
<option value="0">一级部门</option>
|
||||
@foreach (var m in ViewBag.ListTree)
|
||||
{
|
||||
<option value="@m.Id">@m.DepartmentName</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">部门名称:</label>
|
||||
<div class="col-sm-8">
|
||||
<input asp-for="DepartmentName" maxlength="200" type="text" class="form-control" required aria-required="true" placeholder="填写部门名称">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">说明/备注:</label>
|
||||
<div class="col-sm-8">
|
||||
<input asp-for="DepartmentDescription" type="text" class="form-control" placeholder="部门副标题,非必填" maxlength="200">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group hidden">
|
||||
<label class="col-sm-3 control-label">部门图片:</label>
|
||||
<div class="col-sm-8">
|
||||
<div class="input-group">
|
||||
<input asp-for="Pic" maxlength="250" type="text" class="form-control upload-path" placeholder="请选择或上传一个图片" value="">
|
||||
<span class="input-group-addon my-upload-span upload-img"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">排序:</label>
|
||||
<div class="col-sm-8">
|
||||
<input asp-for="Rank" type="number" class="form-control" maxlength="20" placeholder="越小排得越前" aria-required="true">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">部门联系电话:</label>
|
||||
<div class="col-sm-8">
|
||||
<input asp-for="Tel" type="text" class="form-control" maxlength="30" placeholder="部门联系电话" aria-required="true">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">部门传真:</label>
|
||||
<div class="col-sm-8">
|
||||
<input asp-for="Fax" type="text" class="form-control" maxlength="30" placeholder="部门传真" aria-required="true">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">部门邮箱:</label>
|
||||
<div class="col-sm-8">
|
||||
<input asp-for="Email" type="text" class="form-control" maxlength="100" placeholder="部门邮箱" aria-required="true">
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-4 col-sm-offset-3">
|
||||
<button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 提交 </button>
|
||||
<button class="btn btn-default" type="button" onclick="closethisdialog();"><i class="fa fa-close"></i> 取消 </button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$(function () {
|
||||
$(".upload-img").InitUploader({ filesize: "10240", sendurl: "/AdminCP/Upload/DoWebuploaderImage", swf: "/js/webuploader/uploader.swf", filetypes: "gif,jpg,png,bmp", notwater: true });
|
||||
DoPost("addDepartmentForm");
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,66 @@
|
||||
@model IList<Department>
|
||||
@{
|
||||
ViewBag.title = "部门管理";
|
||||
}
|
||||
|
||||
<div class="wrapper wrapper-content">
|
||||
<div class="ibox float-e-margins">
|
||||
<div class="ibox-title">
|
||||
<h5>@ViewBag.Title</h5>
|
||||
</div>
|
||||
<div class="ibox-content">
|
||||
<div id="toolbar" class="btn-group">
|
||||
<button id="btn_add" type="button" class="btn btn-outline btn-default" onclick="showDialog('adddepartment','添加部门','/AdminCP/Department/AddDepartment',0,0);">
|
||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div id="toolbar2" class="btn-group pull-right">
|
||||
<button id="btn_refresh" type="button" class="btn btn-outline btn-default" onclick="refresh();">
|
||||
<span class="fa fa-refresh" aria-hidden="true"></span>刷新
|
||||
</button>
|
||||
</div>
|
||||
<table class="tree table table-striped table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>部门名称</th>
|
||||
<th>ID</th>
|
||||
<th class="text-center">排序</th>
|
||||
<th>联系电话</th>
|
||||
<th>说明/备注</th>
|
||||
<th width="200">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@if (Model.Count == 0)
|
||||
{
|
||||
<tr><td colspan="6" class="text-center">暂无记录...</td></tr>
|
||||
}
|
||||
@foreach (var m in Model)
|
||||
{
|
||||
<tr class="treegrid-@m.Id @(m.PId !=0?"treegrid-parent-"+m.PId:"") ">
|
||||
<td>@m.DepartmentName</td>
|
||||
<td>
|
||||
@m.Id
|
||||
</td>
|
||||
<td class="text-center">@m.Rank</td>
|
||||
<td>@m.Tel</td>
|
||||
<td>
|
||||
@m.DepartmentDescription
|
||||
</td>
|
||||
<td>
|
||||
<a href="javascript:;" class="btn btn-xs btn-primary" title="编辑" onclick="top.showDialog('eidtdepartment', '编辑部门详情', '/AdminCP/Department/EditDepartment?id=@m.Id', 0, 0)"><i class="fa fa-edit"></i> 编辑</a>
|
||||
<a href="javascript:;" class="btn btn-xs btn-danger" title="删除" onclick="doDel('/AdminCP/Department/DelDepartment',@m.Id);"><i class="fa fa-close"></i> 删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</table>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
$('.tree').treegrid();
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,91 @@
|
||||
@model Department
|
||||
@{
|
||||
ViewBag.title = "编辑部门详情";
|
||||
}
|
||||
|
||||
<div class="wrapper wrapper-content">
|
||||
<div class="ibox float-e-margins">
|
||||
<div class="ibox-title">
|
||||
<h5>@ViewBag.Title</h5>
|
||||
<div class="ibox-tools">
|
||||
</div>
|
||||
</div>
|
||||
<div class="ibox-content">
|
||||
<form id="editDepartmentForm" class="form-horizontal m-t" method="post">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">上级部门:</label>
|
||||
<div class="col-sm-8">
|
||||
<select class="form-control m-b" asp-for="PId">
|
||||
<option value="0">一级部门</option>
|
||||
@foreach (var m in ViewBag.ListTree)
|
||||
{
|
||||
<option value="@m.Id">@m.DepartmentName</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">部门名称:</label>
|
||||
<div class="col-sm-8">
|
||||
<input asp-for="DepartmentName" maxlength="200" type="text" class="form-control" required aria-required="true" placeholder="填写部门名称">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">说明/备注:</label>
|
||||
<div class="col-sm-8">
|
||||
<input asp-for="DepartmentDescription" type="text" class="form-control" placeholder="部门副标题,非必填" maxlength="200">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group hidden">
|
||||
<label class="col-sm-3 control-label">部门图片:</label>
|
||||
<div class="col-sm-8">
|
||||
<div class="input-group">
|
||||
<input asp-for="Pic" maxlength="250" type="text" class="form-control upload-path" placeholder="请选择或上传一个图片" value="">
|
||||
<span class="input-group-addon my-upload-span upload-img"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">排序:</label>
|
||||
<div class="col-sm-8">
|
||||
<input asp-for="Rank" type="number" class="form-control" maxlength="20" placeholder="越小排得越前" aria-required="true">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">部门联系电话:</label>
|
||||
<div class="col-sm-8">
|
||||
<input asp-for="Tel" type="text" class="form-control" maxlength="30" placeholder="部门联系电话" aria-required="true">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">部门传真:</label>
|
||||
<div class="col-sm-8">
|
||||
<input asp-for="Fax" type="text" class="form-control" maxlength="30" placeholder="部门传真" aria-required="true">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">部门邮箱:</label>
|
||||
<div class="col-sm-8">
|
||||
<input asp-for="Email" type="text" class="form-control" maxlength="100" placeholder="部门邮箱" aria-required="true">
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-4 col-sm-offset-3">
|
||||
<input type="hidden" asp-for="Id" />
|
||||
<button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 提交 </button>
|
||||
<button class="btn btn-default" type="button" onclick="closethisdialog();"><i class="fa fa-close"></i> 取消 </button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$(function () {
|
||||
$(".upload-img").InitUploader({ filesize: "10240", sendurl: "/AdminCP/Upload/DoWebuploaderImage", swf: "/js/webuploader/uploader.swf", filetypes: "gif,jpg,png,bmp", notwater: true });
|
||||
DoPost("editDepartmentForm");
|
||||
})
|
||||
</script>
|
||||
Reference in New Issue
Block a user