public IActionResult MenuInsert(NavigationMenuType Model) { if (!Model.IsNested) { if (Model.ParentId == null) { ModelState.AddModelError("", "Please Select a parent"); } } if (!ModelState.IsValid) { ViewBag.Roles = _context.Roles.ToList(); ViewBag.Parents = _context.NavigationMenus.Where(s => s.Parent == null && s.Type == UserSecurity.Models.MenuType.PCMSWEBLeft).ToList(); return(View(Model)); } foreach (var m in Model.SelectedRoles) { Model.Roles.Add(new UserSecurity.Models.IdentityContextModels.NavigationMenuItemRole { RoleId = m, }); } Model.Type = UserSecurity.Models.MenuType.PCMSWEBLeft; _context.NavigationMenus.Add(Model); _context.SaveChanges(); return(RedirectToAction("MenuInsert", new { clientName = Model.ClientName })); }
public IActionResult MenuInsert(string clientName) { ViewBag.Roles = _context.Roles.ToList(); ViewBag.Parents = _context.NavigationMenus.Where(s => s.Parent == null && s.Type == UserSecurity.Models.MenuType.PCMSWEBLeft).ToList(); var viewModel = new NavigationMenuType { ClientName = clientName }; return(View(viewModel)); }
public IActionResult EditMenu(NavigationMenuType Model) { if (Model.IsNested) { if (Model.ParentId == null) { ModelState.AddModelError("", "Please Select a parent"); } } if (!ModelState.IsValid) { ViewBag.Roles = _context.Roles.ToList(); ViewBag.Parents = _context.NavigationMenus.Where(s => s.Parent == null && s.Type == UserSecurity.Models.MenuType.PCMSWEBLeft).ToList(); return(View(Model)); } var item = _context.NavigationMenus.Where(s => s.Id == Model.Id).Include(s => s.Roles).First(); item.DisplayName = Model.DisplayName; item.Sequence = Model.Sequence; item.IsNested = Model.IsNested; item.Link = Model.Link; item.MaterialIcon = Model.MaterialIcon; var lRole = item.Roles.ToList(); foreach (var m in lRole) { item.Roles.Remove(m); } _context.Update(item); _context.SaveChanges(); foreach (var m in Model.SelectedRoles) { item.Roles.Add(new UserSecurity.Models.IdentityContextModels.NavigationMenuItemRole { RoleId = m, }); } _context.Update(item); _context.SaveChanges(); return(RedirectToAction("SettingClient", "Client", new { clientName = item.ClientName })); }