public async Task <IActionResult> MenuFuntionRole(MenuRoleOuput menuOuputRole) { var MenuInputRole = new MenuRoleInput(); MenuInputRole.IdRole = menuOuputRole.IdRole; MenuInputRole.ListMenuChucNang = new List <GroupMenuChucNang>(menuOuputRole.ListMenuChucNang); var client = new RestClient(_config["UrlApi"]); var requestApi = new RestRequest("/api/MenuFunctions/save-menu-role", Method.POST); requestApi.AddHeader("Authorization", "Bearer " + AtUserToken); requestApi.AddJsonBody(MenuInputRole); // or automatically deserialize result var response = await client.ExecuteTaskAsync <AtResult <string> >(requestApi); var idRoleFuntion = response.Data.PayLoad; if (idRoleFuntion == null) { return(RedirectToAction("PageErros", "Home", new { statusCode = (int)AtNotify.KhongCoQuyenTruyCap })); } return(RedirectToAction("Index", "Role")); }
public async Task <IActionResult> MenuFuntionRole(string idRole) { var client = new RestClient(_config["UrlApi"]); var requestApi = new RestRequest("/api/MenuFunctions/menu-funtion-role/?idRole=" + idRole); requestApi.AddHeader("Authorization", "Bearer " + AtUserToken); // or automatically deserialize result var response = await client.ExecuteGetTaskAsync <AtResult <MenuRoleOuput> >(requestApi); var model = new MenuRoleOuput(); if (response.Data.PayLoad == null) { return(RedirectToAction("PageErros", "Home", new { statusCode = (int)AtNotify.KhongCoQuyenTruyCap })); } model = response.Data.PayLoad; return(View(model)); }
public async Task <MenuRoleOuput> GetListMenuRoleAsync(string idRole) { var listMenuGroud = await _context.MenuFunctionGroup.Where(c => c.Status == (int)AtRowStatus.Normal).AsNoTracking().ToListAsync(); var listMenu = await _context.MenuFunctionSubGroup.Where(c => c.Status == (int)AtRowStatus.Normal).Select(c => new ListSubMenuFuntion { IdMenuGroud = c.FK_MenuGroup, NameGroup = c.FK_MenuGroupNavigation.GroupName, IdSubMenu = c.Id, NameSubName = c.SubGroupName, MenuFunctions = c.MenuFunction.Where(c => c.Status == (int)AtRowStatus.Normal).Select(lc => new ListMenuFuntion { IdMenuFuntion = lc.Id, NameMenuFuntion = lc.Title, IsCheck = false }).ToList() }).AsNoTracking() .ToListAsync(); var MenuFuntion = new MenuRoleOuput(); MenuFuntion.ListMenuChucNang = new List <GroupMenuChucNang>(); foreach (var itemGroud in listMenuGroud) { var menuFuntion = new GroupMenuChucNang(); menuFuntion.IdMenuGroud = itemGroud.Id; menuFuntion.NameGroup = itemGroud.GroupName; menuFuntion.SubFunctions = listMenu.Where(c => c.IdMenuGroud == itemGroud.Id).ToList(); MenuFuntion.ListMenuChucNang.Add(menuFuntion); } var list_MenuFuntionRole = await _context.MenuFunction_Role .Where(c => c.FK_Role == idRole) .Select(c => c.FK_MenuFunction) .AsNoTracking() .ToListAsync(); foreach (var item in list_MenuFuntionRole) { foreach (var itemMenu in MenuFuntion.ListMenuChucNang) { foreach (var itemSub in itemMenu.SubFunctions) { foreach (var itemFun in itemSub.MenuFunctions) { if (item == itemFun.IdMenuFuntion) { itemFun.IsCheck = true; } } } } } MenuFuntion.IdRole = idRole; var roleName = await _context.Role.FirstOrDefaultAsync(c => c.Id == idRole); MenuFuntion.NameRole = roleName.RoleName; return(MenuFuntion); }