Exemplo n.º 1
0
        public async Task <ValidationContext> Handle(RejectMovieRequestCommand command, CancellationToken cancellationToken)
        {
            var result = new ValidationContext();

            if (string.IsNullOrEmpty(command.Comment))
            {
                result.AddError("Invalid request", "A comment must be specified when rejecting a request");
            }

            var request = await _requestService.GetRequestById(command.RequestId);

            if (request == null)
            {
                result.AddError("Invalid request", "No request was found with the given Id");
            }

            if (request?.RequestStatus == RequestStatuses.Completed)
            {
                result.AddError("Invalid request", "Request has already been completed");
            }

            if (!result.IsSuccessful)
            {
                return(result);
            }

            // ReSharper disable once PossibleNullReferenceException
            request.RequestStatus = RequestStatuses.Rejected;
            request.Comment       = command.Comment;

            await _unitOfWork.CommitAsync();

            return(result);
        }
        private async Task <MovieRequestRow> ValidateRequestExists(DeleteMovieRequestCommand command, ValidationContext resultContext)
        {
            var request = await _requestService.GetRequestById(command.Id);

            if (request == null)
            {
                resultContext.AddError("Invalid request id", "A request for the given id was not found.");
            }

            return(request);
        }
Exemplo n.º 3
0
        public async Task <ValidationContext> Handle(ApproveMovieRequestCommand command, CancellationToken cancellationToken)
        {
            var result = new ValidationContext();

            var request = await _requestService.GetRequestById(command.RequestId);

            result.AddErrorIf(() => request == null, "Invalid request", "No request was found with the given Id");
            result.AddErrorIf(() => request?.RequestStatus == RequestStatuses.Completed, "Invalid request", "Request has already been completed");

            if (!result.IsSuccessful)
            {
                return(result);
            }

            request.RequestStatus = RequestStatuses.Approved;

            await _unitOfWork.CommitAsync();

            return(result);
        }
 private void GivenNoRequestIsFound()
 {
     _requestService.GetRequestById(Arg.Any <int>()).ReturnsNull();
 }