public async Task <IActionResult> DeleteRole(string roleId) { var r = await _scontext.SecurityRoles.SingleOrDefaultAsync(rr => rr.RoleId == new Guid(roleId)); if (r != null) { var memberCount = _context.member.Where(mm => mm.mem_role_id == r.RoleId).Count(); if (memberCount != 0) { return(Json(new { result = "fail" })); } else { var rms = _scontext.SecurityRoleMenus.Where(rr => rr.RoleId == r.RoleId).ToList(); _scontext.RemoveRange(rms); _scontext.Remove(r); await _scontext.SaveChangesAsync(); return(Json(new { result = "success" })); } } else { return(Json(new { result = "fail" })); } }
public async Task <IActionResult> UpdateRoleMenus(string roleId, string menus) { Guid rId = new Guid(roleId); var rms = _scontext.SecurityRoleMenus.Where(rr => rr.RoleId == rId).ToList(); _scontext.RemoveRange(rms); await _scontext.SaveChangesAsync(); var menuar = menus.Split('|'); foreach (string menuId in menuar) { SecurityRoleMenus r = new SecurityRoleMenus(); r.RoleId = rId; r.MenuId = int.Parse(menuId); r.EditedBy = new Guid(HttpContext.Session.GetString("memberId")); r.EditedDate = DateTime.Now; _scontext.Add(r); } await _scontext.SaveChangesAsync(); return(Json(new { result = "success" })); }