Ejemplo n.º 1
0
        public Rental(RentalParams rental, Customer customer, Movie movie)
        {
            this.DateRented   = rental.DateRented ?? DateTime.Now;
            this.DateReturned = rental.DateReturned;
            this.RentalFee    = rental.RentalFee;

            this.Customer = new CustomerDTO
            {
                Id     = customer.Id,
                Name   = customer.Name,
                Phone  = customer.Phone,
                IsGold = customer.IsGold
            };
            this.Movie = new MovieDTO
            {
                Id              = movie.Id,
                Title           = movie.Title,
                DailyRentalRate = movie.DailyRentalRate
            };
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <Rental> > Post(RentalParams rentalParams)
        {
            var customer = await _customerRepository.Get(rentalParams.CustomerId);

            if (customer == null)
            {
                return(BadRequest("No customer found with the given id"));
            }

            var movie = await _movieRepository.Get(rentalParams.MovieId);

            if (movie == null)
            {
                return(BadRequest("No movie found with the given id"));
            }

            var rental = new Rental(rentalParams, customer, movie);
            await _rentalRepository.Add(rental);

            return(Ok(rental));
        }