public async Task <IActionResult> GetCustomer(int id) { var customer = await _repository.GetCustomerAsync(id); if (customer == null) { return(NotFound()); } var customerToReturn = _mapper.Map <CustomerDto>(customer); return(Ok(customerToReturn)); }
public async Task <IActionResult> AddRental([FromBody] RentalForCreationDto rentalForCreationDto) { if (rentalForCreationDto == null) { return(BadRequest()); } var customer = await _repository.GetCustomerAsync(rentalForCreationDto.CustomerId); if (customer == null) { return(NotFound()); } var movie = await _repository.GetMovieAsync(rentalForCreationDto.MovieId); if (movie == null) { return(NotFound()); } if (movie.NumberInStock == 0) { return(BadRequest("Movie out of stock")); } var rental = _mapper.Map <Rental>(rentalForCreationDto); rental.RentalFee = movie.DailyRentalRate; _repository.AddRental(rental); movie.NumberInStock--; await _unitOfWork.CompleteAsync(); var rentalToReturn = _mapper.Map <RentalDto>(rental); return(CreatedAtRoute("GetRental", new { id = rentalToReturn.Id }, rentalToReturn)); }