Exemplo n.º 1
0
        public IActionResult Accept(int id)
        {
            var user = userRepository.GetUserFromPrincipal(HttpContext.User);

            if (!userRepository.IsActiveUser(user))
            {
                return(new UnauthorizedResult());
            }

            if (!userRepository.IsRecipient(user))
            {
                return(BadRequest("You are not authorized to pickup donations."));
            }

            var donation = donationRepository.GetById(id);

            if (donation == null)
            {
                return(new NotFoundResult());
            }

            if (donation.RecipientId.HasValue || donation.Status != DonationStatus.Listed)
            {
                return(BadRequest("Donation is not available"));
            }

            donationRepository.AcceptDonation(id, user.Id);
            return(Ok());
        }