public JsonResult UpdatePost(Dic_Post post) { 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 (post.post_id == 0) { json.msg_text = "获取部门/科室的ID出错。"; json.msg_code = "IDError"; goto next; } var same = db.Dic_Post.Where(x => x.post_name == post.post_name && x.post_id != post.post_id); if (same.Count() > 0) { json.msg_text = "该名称已存在。"; json.msg_code = "NameExists"; goto next; } db.Entry(post).State = EntityState.Modified; try { db.SaveChanges(); DBCaches <Dic_Post> .ClearCache("cache_post"); } catch { json.msg_text = "更新,请重新操作。"; json.msg_code = "UpdateErr"; goto next; } SysLog.WriteLog(user, string.Format("更新职务[{0}]", post.post_name), IpHelper.GetIP(), "", 5, "", db); json.state = 1; json.msg_code = "success"; json.msg_text = "更新成功!"; next: return(Json(json, JsonRequestBehavior.AllowGet)); }
public JsonResult DeletePost(string pid) { int id = PageValidate.FilterParam(pid); 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; } Dic_Post model = db.Dic_Post.Find(id); if (model == null) { json.msg_text = "没有找到该职务,该职务可能已被删除。"; json.msg_code = "noThis"; goto next; } db.Dic_Post.Remove(model); try { db.SaveChanges(); DBCaches <Dic_Post> .ClearCache("cache_post"); } catch { json.msg_text = "删除失败,请重新操作。"; json.msg_code = "recyErr"; goto next; } SysLog.WriteLog(user, string.Format("删除职务[{0}]", model.post_name), IpHelper.GetIP(), "", 5, "", db); json.state = 1; json.msg_code = "success"; json.msg_text = "删除成功!"; next: return(Json(json, JsonRequestBehavior.AllowGet)); }
public ActionResult Post(Dic_Post model) { 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 = "没有权限执行当前操作。" })); } model.post_name = PageValidate.InputText(model.post_name, 50); if (db.Dic_Post.Where(x => x.post_name == model.post_name).Count() > 0) { ViewBag.msg = "名称已存在"; } else { db.Dic_Post.Add(model); try { db.SaveChanges(); DBCaches <Dic_Post> .ClearCache("cache_post"); } catch { ViewBag.msg = "职务添加失败,请重试。"; } SysLog.WriteLog(user, string.Format("添加职务[{0}]", model.post_name), IpHelper.GetIP(), "", 5, "", db); } ViewData["PostList"] = DBCaches <Dic_Post> .getCache("cache_post");// db.Dic_Post.ToList(); return(View(model)); }