public async Task <ResultPageDto <List <Power> > > PowerList(PowerDto dto) { var resultPage = new ResultPageDto <List <Power> >(); //resultPage.pi=page.pi; //resultPage.ps=page.ps; resultPage.total = await db.Power.CountAsync(); if (resultPage.total == 0) { return(resultPage); } var power = db.Power.Include(x => x.RoleMenu).ThenInclude(x => x.Menu).Where(o => 1 == 1); if (!string.IsNullOrEmpty(dto.Name) && dto.Name != "ascend" && dto.Name != "descend") { power = power.Where(Company => Company.Name.Contains(dto.Name)); } else if (dto.Name == "ascend") { power = power.OrderBy(m => m.Name); } else if (dto.Name == "ascend") { power = power.OrderByDescending(m => m.Name); } else { } resultPage.list = await power.Skip(dto.ps *(dto.pi - 1)).Take(dto.ps).ToListAsync(); return(resultPage); }
public async Task <int> AddOrEditAsync(PowerDto dto) { using (var tran = await db.Database.BeginTransactionAsync()) { try { var dbPower = await db.Power.FindAsync(dto.Id); if (dbPower == null) { dbPower = new Power() { Id = dto.Id, Name = dto.Name }; await AddAsync(dbPower); } else { dbPower.Name = dto.Name; await EditAsync(dbPower); } await ChangePowerMenu(dbPower.Id, dto.MenuIds); await tran.CommitAsync(); return(1); } catch (System.Exception ex) { await tran.RollbackAsync(); throw ex; } } }
public async Task <ActionResult <ResponseDto> > Powers(PowerDto dto) { var data = _mapper.Map <ResultPageDto <List <Power> >, ResultPageDto <List <PowerDto> > >(await bll.PowerList(dto)); result.data = data; return(result); }
public IActionResult DomainAndApp() { PowerDto dto = new PowerDto(); var menus = userService.FindUserMenus(GetUserDto(), false); if (menus.Where(p => !string.IsNullOrWhiteSpace(p.Url) && p.Url.Contains("DomainAndApp") && p.Url.Contains("AddDomain")).Any()) { dto.AddDomain = true; } if (menus.Where(p => !string.IsNullOrWhiteSpace(p.Url) && p.Url.Contains("DomainAndApp") && p.Url.Contains("EditDomain")).Any()) { dto.EditDomain = true; } if (menus.Where(p => !string.IsNullOrWhiteSpace(p.Url) && p.Url.Contains("DomainAndApp") && p.Url.Contains("DeleteDomain")).Any()) { dto.DeleteDomain = true; } if (menus.Where(p => !string.IsNullOrWhiteSpace(p.Url) && p.Url.Contains("DomainAndApp") && p.Url.Contains("AddApplication")).Any()) { dto.AddApplication = true; } if (menus.Where(p => !string.IsNullOrWhiteSpace(p.Url) && p.Url.Contains("DomainAndApp") && p.Url.Contains("EditApplication")).Any()) { dto.EditApplication = true; } if (menus.Where(p => !string.IsNullOrWhiteSpace(p.Url) && p.Url.Contains("DomainAndApp") && p.Url.Contains("DeleteApplication")).Any()) { dto.DeleteApplication = true; } return(View(dto)); }
public async Task <bool> IsGrantedAsync(string roleId, PowerDto power) { //Get cached role permissions var cacheItem = await GetRolePermissionCacheItemAsync(roleId); //Check the permission return(cacheItem.GrantedPowers.Contains(power.PowerCode)); }
private async Task CheckPowerFields(PowerDto powerDto) { await _elementService.FindById(powerDto.ElementId); if (string.IsNullOrEmpty(powerDto.Name) || string.IsNullOrEmpty(powerDto.Strength.ToString()) || string.IsNullOrEmpty(powerDto.MainTrait) || string.IsNullOrEmpty(powerDto.ElementId.ToString()) || string.IsNullOrEmpty(powerDto.Details)) { throw new NullParameterException($"There are null parameters"); } if (powerDto.Strength < 1 || powerDto.Strength > 100) { throw new OutOfRangeException(nameof(PowerDto.Strength)); } }
public async Task UpdatePower(PowerDto powerDto) { await CheckPowerFields(powerDto); var powerForUpdate = await FindById(powerDto.Id); powerForUpdate.MainTrait = powerDto.MainTrait; powerForUpdate.Name = powerDto.Name; powerForUpdate.Strength = powerDto.Strength; powerForUpdate.Details = powerDto.Details; powerForUpdate.ElementId = powerDto.ElementId; _context.Powers.Update(powerForUpdate); await _context.SaveChangesAsync(); }
public async Task CreatePower(PowerDto powerDto) { await CheckPowerFields(powerDto); Power newPower = new Power { Name = powerDto.Name, Details = powerDto.Details, Strength = powerDto.Strength, MainTrait = powerDto.MainTrait, ElementId = powerDto.ElementId }; await _context.AddAsync(newPower); await _context.SaveChangesAsync(); }
public IActionResult Index() { PowerDto dto = new PowerDto(); var menus = userService.FindUserMenus(GetUserDto(), false); if (menus.Where(p => !string.IsNullOrWhiteSpace(p.Url) && p.Url.Contains("User") && p.Url.Contains("Add")).Any()) { dto.Add = true; } if (menus.Where(p => !string.IsNullOrWhiteSpace(p.Url) && p.Url.Contains("User") && p.Url.Contains("Edit")).Any()) { dto.Edit = true; } if (menus.Where(p => !string.IsNullOrWhiteSpace(p.Url) && p.Url.Contains("User") && p.Url.Contains("Delete")).Any()) { dto.Delete = true; } return(View(dto)); }
protected virtual async Task <bool> IsGrantedAsync(string userId, PowerDto power) { var isGranted = false; if (power == null) { throw new ArgumentNullException("系统不存在该权限码"); } //Get cached user permissions var cacheItem = await GetUserPowerCacheItemAsync(userId); if (cacheItem == null) { throw new LotteryAuthorizeException($"没有权限{power.PowerName}"); } //Check for user-specific value if (cacheItem.GrantedPermissions.Contains(power.PowerCode)) { isGranted = true; } if (cacheItem.ProhibitedPermissions.Contains(power.PowerCode)) { isGranted = false; } //Check for roles foreach (var roleId in cacheItem.RoleIds) { if (await _roleManager.IsGrantedAsync(roleId, power)) { isGranted = true; } } if (isGranted) { return(true); } throw new LotteryAuthorizeException($"没有权限{power.PowerName}"); }
public IActionResult Index() { PowerDto dto = new PowerDto(); var menus = userService.FindUserMenus(UserInfo, false); if (menus.Where(p => !string.IsNullOrWhiteSpace(p.Url) && p.Url.Contains("/StreamProxy") && p.Url.Contains("/Add")).Any()) { dto.Add = true; } if (menus.Where(p => !string.IsNullOrWhiteSpace(p.Url) && p.Url.Contains("/StreamProxy") && p.Url.Contains("/Edit")).Any()) { dto.Edit = true; } if (menus.Where(p => !string.IsNullOrWhiteSpace(p.Url) && p.Url.Contains("/StreamProxy") && p.Url.Contains("/Delete")).Any()) { dto.Delete = true; } if (menus.Where(p => !string.IsNullOrWhiteSpace(p.Url) && p.Url.Contains("/StreamProxy") && p.Url.Contains("/ViewDetail")).Any()) { dto.RolePower = true; } return(View(dto)); }
public async Task <ActionResult <ResponseDto> > AddOrEditPower(PowerDto dto) { result.data = await bll.AddOrEditAsync(dto); return(result); }
public Task <bool> IsGrantedMermberAsync(string roleId, PowerDto power) { return(IsGrantedAsync(roleId, power)); }
public async Task <IActionResult> UpdatePower([FromBody] PowerDto powerDto) { await _powerService.UpdatePower(powerDto); return(Created(Constants.HTTP_UPDATED, powerDto)); }