Example #1
0
        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);
        }
Example #2
0
        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;
                }
            }
        }
Example #3
0
        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));
        }
Example #5
0
        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));
        }
Example #6
0
        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));
            }
        }
Example #7
0
        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();
        }
Example #8
0
        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();
        }
Example #9
0
        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));
        }
Example #10
0
        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}");
        }
Example #11
0
        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));
        }
Example #12
0
        public async Task <ActionResult <ResponseDto> > AddOrEditPower(PowerDto dto)
        {
            result.data = await bll.AddOrEditAsync(dto);

            return(result);
        }
Example #13
0
 public Task <bool> IsGrantedMermberAsync(string roleId, PowerDto power)
 {
     return(IsGrantedAsync(roleId, power));
 }
Example #14
0
        public async Task <IActionResult> UpdatePower([FromBody] PowerDto powerDto)
        {
            await _powerService.UpdatePower(powerDto);

            return(Created(Constants.HTTP_UPDATED, powerDto));
        }