public JsonResult Update(UpdatePrivilegeModel model) { JsonResult json = new JsonResult(); if (string.IsNullOrEmpty(model.privilegeName)) { return(Json(new { success = false, msg = "权限名称不为空" }, "text/json")); } if (model.menuId == 0) { return(Json(new { success = false, msg = "请选择相应的菜单" }, "text/json")); } List <Privilege> mPrivilege = db.Privilege.Where(m => m.privilegeName == model.privilegeName).ToList(); if (mPrivilege != null & mPrivilege.Count > 1) { return(Json(new { success = false, msg = "该权限已经存在,请更换权限名称" }, "text/json")); } using (TransactionScope scope = new TransactionScope()) { try { Privilege privilege = db.Privilege.FirstOrDefault(m => m.privilegeId == model.privilegeId); if (privilege != null) { privilege.privilegeName = model.privilegeName; privilege.privilegeNote = model.privilegeNote; } db.Entry(privilege).State = EntityState.Modified; MenuPrivilege menuPrivilege = db.MenuPrivilege.Where(m => m.privilegeId == model.privilegeId).FirstOrDefault(); if (menuPrivilege != null) { menuPrivilege.menuId = model.menuId; menuPrivilege.privilegeId = model.privilegeId; } db.Entry(menuPrivilege).State = EntityState.Modified; if (db.SaveChanges() > 0) { json.Data = new { success = true, msg = "修改成功!" }; } else { json.Data = new { success = false, msg = "修改失败!" }; } } catch (DbEntityValidationException ex) { throw; } scope.Complete(); } return(json); }
public JsonResult Update(UpdateRoleModel model, string pIds) { JsonResult json = new JsonResult(); if (string.IsNullOrEmpty(model.roleName)) { return(Json(new { success = false, msg = "角色名称不为空" }, "text/json")); } List <Role> mrRole = db.Role.Where(m => m.roleName == model.roleName).ToList(); if (mrRole != null & mrRole.Count > 1) { return(Json(new { success = false, msg = "角色名称已经存在" }, "text/json")); } using (TransactionScope scope = new TransactionScope()) { try { Role role = db.Role.FirstOrDefault(m => m.roleName == model.roleName); if (role != null) { role.roleName = model.roleName; role.roleNote = model.roleNote; } db.Entry(role).State = EntityState.Modified; RolePrivilege rolePrivilege = db.RolePrivilege.Where(m => m.roleId == model.roleId).FirstOrDefault(); if (rolePrivilege != null) { rolePrivilege.privilegeIds = pIds; rolePrivilege.roleId = model.roleId; } db.Entry(rolePrivilege).State = EntityState.Modified; if (db.SaveChanges() > 0) { json.Data = new { success = true, msg = "修改成功!" }; } else { json.Data = new { success = false, msg = "修改失败!" }; } } catch (DbEntityValidationException ex) { throw; } scope.Complete(); } return(json); }
public JsonResult Update(UpdateMenuModel model) { JsonResult json = new JsonResult(); if (string.IsNullOrEmpty(model.menuName)) { return(Json(new { success = false, msg = "菜单名称不为空" }, "text/json")); } if (string.IsNullOrEmpty(model.menuUrl)) { return(Json(new { success = false, msg = "菜单Url不为空" }, "text/json")); } List <Menu> mMenu = db.Menu.Where(m => m.menuName == model.menuName).ToList(); if (mMenu != null & mMenu.Count > 1) { return(Json(new { success = false, msg = "该菜单已经存在,请更换菜单名称" }, "text/json")); } using (TransactionScope scope = new TransactionScope()) { try { Menu menu = db.Menu.FirstOrDefault(m => m.menuId == model.menuId); if (menu != null) { menu.menuName = model.menuName; menu.menuUrl = model.menuUrl; menu.menuNote = model.menuNote; menu.parentMenuId = model.parentMenuId; db.Entry(menu).State = EntityState.Modified; if (db.SaveChanges() > 0) { json.Data = new { success = true, msg = "修改成功!" }; } else { json.Data = new { success = false, msg = "修改失败!" }; } } else { json.Data = new { success = false, msg = "菜单不存在!" }; } } catch (DbEntityValidationException ex) { throw; } scope.Complete(); } return(json); }
public ActionResult Update(UpdateUserModel model) { JsonResult json = new JsonResult(); if (string.IsNullOrEmpty(model.userName)) { return(Json(new { success = false, msg = "用户名不能为空" }, "text/json")); } if (string.IsNullOrEmpty(model.UserProfile.password)) { return(Json(new { success = false, msg = "密码不能为空" }, "text/json")); } List <User> mUser = db.User.Where(m => m.userName == model.userName).ToList(); if (mUser != null && mUser.Count > 1) { return(Json(new { success = false, msg = "该用户已经存在,请更换用户名" }, "text/json")); } using (TransactionScope scope = new TransactionScope()) { try { User user = db.User.Where(m => m.userId == model.userId).FirstOrDefault(); if (user != null) { user.userName = model.userName; db.Entry(user).State = EntityState.Modified; } UserProfile userProfile = db.UserProfile.Where(m => m.userId == model.userId).FirstOrDefault(); if (userProfile != null) { userProfile.password = DESEncrypt.Encrypt(model.UserProfile.password, model.UserProfile.salt); userProfile.passwordChangedDate = DateTime.Now; userProfile.userNote = model.UserProfile.userNote; userProfile.avatar = model.UserProfile.avatar; db.Entry(userProfile).State = EntityState.Modified; } UserRole userRole = db.UserRole.Where(m => m.userId == model.userId).FirstOrDefault(); if (userRole != null) { userRole.roleId = model.roleId; db.Entry(userRole).State = EntityState.Modified; } if (db.SaveChanges() > 0) { json.Data = new { success = true, msg = "修改成功!" }; } else { json.Data = new { success = false, msg = "修改失败!" }; } } catch (DbEntityValidationException ex) { throw; } scope.Complete(); } return(json); }