Пример #1
0
        public IHttpActionResult Add(AddCustomer customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var customerToAdd = new DAL.Models.Customer
            {
                Name    = customer.Name,
                Company = customer.Company,
                Email   = customer.Email,
                Phone   = customer.Phone
            };

            var customerAdded = _db.Customers.Add(customerToAdd);

            _db.SaveChanges();

            var customerToReturn = new Customer
            {
                Id      = customerAdded.Id,
                Name    = customerAdded.Name,
                Phone   = customerAdded.Phone,
                Email   = customerAdded.Email,
                Company = customerAdded.Company
            };

            return(Ok(new { Data = customerToReturn }));
        }
Пример #2
0
 public Customer Convert(DAL.Models.Customer customer)
 {
     return(new Customer(
                idCustomer: customer.IdCustomer,
                name: customer.Name,
                email: customer.Email,
                dateOfBirth: customer.DateOfBirth));
 }
Пример #3
0
        public async Task <Rental> RegisterRentalAndCreateCustomer(DateTime from, DateTime to, int carMilageKm, NewCustomer newCustomer, long rentalCarId)
        {
            var customer = new DAL.Models.Customer()
            {
                Name        = newCustomer.Name,
                Email       = newCustomer.Email,
                DateOfBirth = newCustomer.DateOfBirth,
            };

            await this.unitOfWork.Customer.Add(customer);

            await this.unitOfWork.CompleteAsync();

            return(await this.RegisterRental(from, to, carMilageKm, customer.IdCustomer, rentalCarId));
        }