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 <ActionResult <AtResult <string> > > SaveMenuRole([FromBody] MenuRoleInput input) { if (await CheckPermission(_context)) { try { var output = await _logicMenu.SaveMenuRoleAsync(input, UserId); return(new AtResult <string>(output)); } catch (Exception ex) { throw ex; } } else { return(new AtResult <string>(AtNotify.KhongCoQuyenTruyCap)); } }
public async Task <string> SaveMenuRoleAsync(MenuRoleInput input, string userId) { try { var now = GetDateTimeFromServer(); var list_MenuFuntionRole = await _context.MenuFunction_Role .Where(c => c.FK_Role == input.IdRole) .AsNoTracking() .ToListAsync(); var listFuntion = new List <ListMenuFuntion>(); var newItem = new List <MenuFunction_Role>(); foreach (var item in input.ListMenuChucNang) { foreach (var itemSub in item.SubFunctions) { if (itemSub.MenuFunctions != null) { listFuntion.AddRange(itemSub.MenuFunctions.Where(c => c.IsCheck == true).ToList()); } } } foreach (var itemfunAccount in list_MenuFuntionRole) { var check = listFuntion.FirstOrDefault(c => c.IdMenuFuntion == itemfunAccount.FK_MenuFunction); if (check == null) { _context.MenuFunction_Role.Remove(itemfunAccount); } } foreach (var itemFuntion in listFuntion) { var check = list_MenuFuntionRole .FirstOrDefault(c => c.FK_Role == input.IdRole && c.FK_MenuFunction == itemFuntion.IdMenuFuntion); if (check == null) { newItem.Add(new MenuFunction_Role { FK_Role = input.IdRole, FK_MenuFunction = itemFuntion.IdMenuFuntion, CreateDate = now, }); } } await _context.MenuFunction_Role.AddRangeAsync(newItem); await _context.SaveChangesAsync(); await WrtiteAudittingLog(new MSC_AudittingLog { Description = "Phân quyền theo ROLE ID: " + input.IdRole, UserID = userId }, AtSerialNoConts.CODE_LOGC_UPDATE); return(input.IdRole); } catch (Exception ex) { throw ex; } }