Exemplo n.º 1
0
        private Book CreateBooking(BookRequestDto bookRequestDto)
        {
            var car = CarRepository.GetById(bookRequestDto.carId);
            int?customerId;

            if (CustomerRepository.IsCustomerExist(bookRequestDto.CustomerEmail))
            {
                customerId = CustomerRepository.GetCustomerId(bookRequestDto.CustomerEmail);
            }
            else
            {
                List <CustomerProperties> customerProperties = new List <CustomerProperties> {
                    new CustomerProperties {
                        TypeId = 1, Value = bookRequestDto.CustomerAge
                    },
                    new CustomerProperties {
                        TypeId = 2, Value = bookRequestDto.CustomerLicenseAge
                    }
                };

                var customer = new Customer //TODO: check customer exist
                {
                    CustomerEmail       = bookRequestDto.CustomerEmail,
                    CustomerPhoneNumber = bookRequestDto.CustomerPhoneNumber,
                    CustomerName        = bookRequestDto.CustomerName,
                    CustomerProperties  = customerProperties
                };
                CustomerRepository.AddAndSave(customer);
                customerId = customer.Id;
            }

            var book = new Book
            {
                RentStartDate   = bookRequestDto.RentStartDate,
                RentEndDate     = bookRequestDto.RentEndDate,
                ReferenceNumber = CreateReferenceNumber(),
                BeforeKm        = car.CarKm,
                AfterKm         = car.CarKm,
                CustomerId      = (int)customerId,
                CarId           = car.Id
            };

            return(book);
        }