public ActionResult EditUserMenu(UserclaimViewModel model) { try { if (ModelState.IsValid) { var checkRole = _dbContext.tbl_Roles.Where(w => w.RoleId == model.RoleId).FirstOrDefault(); if (checkRole != null) { _dbContext.tbl_Userclaim.RemoveRange(_dbContext.tbl_Userclaim.Where(w => w.RoleId == model.RoleId)); _dbContext.SaveChanges(); foreach (var roleMenu in model.Menus) { if (roleMenu.Ischecked) { Userclaim claim = new Userclaim { MenuId = roleMenu.MenuId, RoleId = model.RoleId, IsActive = true, Columns = "", CreatedBy = _userId, CreatedDate = DateTime.Now, }; _dbContext.tbl_Userclaim.Add(claim); _dbContext.SaveChanges(); } } ViewBag.SuccessMessage = "Detail added successfully"; } else { return(RedirectToAction("UserMenuList", "UserSetting")); } } } catch (Exception ex) { return(RedirectToAction("UserMenuList", "UserSetting")); } return(View(model)); }
public ActionResult EditUserMenu(string id) { UserclaimViewModel model = new UserclaimViewModel(); try { if (ModelState.IsValid) { var roleId = Convert.ToInt32(id); var checkRole = _dbContext.tbl_Roles.Where(w => w.RoleId == roleId).FirstOrDefault(); if (checkRole != null) { model.RoleName = checkRole.Rolename; model.RoleId = roleId; var roleMenus = _dbContext.tbl_Userclaim.Where(w => w.RoleId == roleId).Select(s => s.MenuId).ToList(); model.Menus = (from menu in _dbContext.tbl_Menus select new MenuViewModel { MenuId = menu.MenuId, Name = menu.Name, Ischecked = (roleMenus.Contains(menu.MenuId) ? true : false), }).ToList(); } else { return(RedirectToAction("UserMenuList", "UserSetting")); } } } catch (Exception ex) { return(RedirectToAction("UserMenuList", "UserSetting")); } return(View(model)); }