public ActionResult Department(DepartMentModel info) { if (!User.Identity.IsAuthenticated) { return(RedirectToRoute(new { controller = "Login", action = "LogOut" })); } int user = PageValidate.FilterParam(User.Identity.Name); if (!RoleCheck.CheckHasAuthority(user, db, "系统管理")) { return(RedirectToRoute(new { controller = "Error", action = "Index", err = "没有权限执行当前操作。" })); } List <SelectOption> options = DropDownList.getDepartment(); ViewBag.Dept = DropDownList.SetDropDownList(options); Dic_Department model = new Dic_Department(); model.dept_name = PageValidate.InputText(info.deptName, 50); if (db.Dic_Department.Where(x => x.dept_name == model.dept_name && x.dept_parent_id == info.parentId).Count() > 0) { ViewBag.msg = "名称已存在"; } else { model.dept_parent_id = info.parentId; db.Dic_Department.Add(model); try { db.SaveChanges(); DBCaches2.ClearCache("cache_depts"); } catch { ViewBag.msg = "部门添加失败,请重试。"; } } SysLog.WriteLog(user, string.Format("添加部门[{0}]", model.dept_name), IpHelper.GetIP(), "", 5, "", db); ViewData["DeptList"] = DBCaches2.getDeptCache(); return(View(info)); }
public string Department(DepartMentModel Model) { string returnMessage = "true"; if (Model.ClassName == "" && Model.Department == "-1") { returnMessage = "false"; } else if (Model.ClassName == "") { returnMessage = "0"; } else if (Model.Department == "-1") { returnMessage = "-1"; } return(returnMessage); }
public JsonResult UpdateDept(DepartMentModel dept) { BaseJsonData json = new BaseJsonData(); if (!User.Identity.IsAuthenticated) { json.msg_text = "没有登陆或登陆失效,请重新登陆后操作。"; json.msg_code = "notLogin"; goto next; } int user = PageValidate.FilterParam(User.Identity.Name); if (!RoleCheck.CheckHasAuthority(user, db, "系统管理")) { json.msg_text = "没有权限。"; json.msg_code = "NoPower"; goto next; } if (dept.deptId == null || dept.deptId == 0) { json.msg_text = "获取部门/科室的ID出错。"; json.msg_code = "IDError"; goto next; } int id = (int)dept.deptId; Dic_Department model = db.Dic_Department.Find(id); if (model == null) { json.msg_text = "没有找到该部门/科室,该部门/科室可能已被删除。"; json.msg_code = "noThis"; goto next; } var same = db.Dic_Department.Where(x => x.dept_name == dept.deptName && x.dept_id != dept.deptId); if (same.Count() > 0) { json.msg_text = "该名称已存在。"; json.msg_code = "NameExists"; goto next; } model.dept_name = dept.deptName; model.dept_parent_id = dept.parentId; db.Entry(model).State = EntityState.Modified; try { db.SaveChanges(); DBCaches2.ClearCache("cache_depts"); } catch { json.msg_text = "更新,请重新操作。"; json.msg_code = "UpdateErr"; goto next; } SysLog.WriteLog(user, string.Format("更新部门[{0}]", model.dept_name), IpHelper.GetIP(), "", 5, "", db); json.state = 1; json.msg_code = "success"; json.msg_text = "更新成功!"; next: return(Json(json, JsonRequestBehavior.AllowGet)); }