예제 #1
0
        protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, EditLotRequirement requirement, int lotId)
        {
            var p = await _lotService.GetLotById(lotId);

            var category = await _categoryService.GetCategoryById(p.CategoryId);

            var auctionId   = category.ParentAuction.Id;
            var canModerate = ModeratorOfAuctionHelper.CanModerateAuction(context.User, auctionId);

            if (canModerate)
            {
                context.Succeed(requirement);
                return;
            }

            var userId = context.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var user   = await _userService.FindByIdAsync(userId);

            var lots = user.Lots.Where(p => p.LotId == lotId).Count();

            if (lots > 0)
            {
                context.Succeed(requirement);
                return;
            }
        }
 protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, ModeratorOfAuctionRequirement requirement, int auctionId)
 {
     if (ModeratorOfAuctionHelper.CanModerateAuction(context.User, auctionId))
     {
         context.Succeed(requirement);
     }
     return(Task.CompletedTask);
 }
예제 #3
0
        protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, EditCategoryRequirement requirement, int categoryId)
        {
            var category = await _categoryService.GetCategoryById(categoryId);

            var auctionId   = category.ParentAuction.Id;
            var canModerate = ModeratorOfAuctionHelper.CanModerateAuction(context.User, auctionId);

            if (canModerate)
            {
                context.Succeed(requirement);
                return;
            }

            var userId  = context.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var isOwner = category.StartedBy.Id == userId;

            if (isOwner)
            {
                context.Succeed(requirement);
                return;
            }
        }