Beispiel #1
0
        public async Task <IActionResult> ReturnMovieAsync([FromBody] ReturnMovieInputModel inputModel,
                                                           CancellationToken cancellationToken = default)
        {
            var result = await _movieRentalService.ReturnMovieAsync(inputModel, cancellationToken);

            return(Ok(result));
        }
        public async Task <MovieRentalReturnedReponsesDTO> ReturnMovieAsync(ReturnMovieInputModel inputModel, CancellationToken cancellationToken = default)
        {
            inputModel.EnsureIsValid();

            var movieRental = await _repository.Query <MovieRental>().FirstOrDefaultAsync(c => c.MovieId == inputModel.MovieId &&
                                                                                          c.CustomerId == inputModel.CustomerId && c.ReturnedAt == null, cancellationToken);

            if (movieRental == null)
            {
                return(null);
            }

            movieRental.WasReturned();

            await _repository.UpdateAsync(movieRental, cancellationToken);

            var passedDeliveryDay = movieRental.ReturnedAt > movieRental.CreatedAt.AddDays(movieRental.DaysInRental);

            return(new MovieRentalReturnedReponsesDTO(passedDeliveryDay));
        }