예제 #1
0
        public async Task <ActionResult <ApiResponse> > AcceptBusinessRequest(int businessId)
        {
            Business business = await _businessRepository.GetByIdAsync(businessId);

            if (!await _businessService.AcceptBusinessRequest(business))
            {
                return(new BadRequestObjectResult(new ApiResponse(400, "Cannot accept this business")));
            }
            ;

            User user = await _userManager.FindByIdAsync(business.OwnerId);

            if (await _userManager.IsInRoleAsync(user, "BusinessOwner"))
            {
                return(new OkObjectResult(new ApiResponse(200, "You accepted business request")));
            }

            IdentityResult addRoleResult = await _userManager.AddToRoleAsync(user, "BusinessOwner");

            return(addRoleResult.Succeeded
                                ? new OkObjectResult(new ApiResponse(200, "You accepted business request"))
                                : new BadRequestObjectResult(new ApiResponse(400, "Cannot accept this business")));
        }