Esempio n. 1
0
        public async Task <Order> Create(Order order, int customerId)
        {
            Customer customer = await _context.Customers.FindAsync(customerId);

            Order newOrder = new Order()
            {
                ArrivalDate = order.ArrivalDate,
                RequestDate = order.RequestDate,
                ArrivalHour = order.ArrivalHour,
                CustomerId  = customerId,
                Customer    = customer
            };

            _context.Orders.Add(newOrder);
            await _context.SaveChangesAsync();

            return(newOrder);
        }
Esempio n. 2
0
        public async Task <Customer> Put(Customer customerFromInput, int id)
        {
            Customer customer = await _context.Customers.FindAsync(id);

            customer.Firstname = customerFromInput.Firstname;
            customer.Username  = customerFromInput.Username;
            customer.Password  = customerFromInput.Password;

            /*customer.Orders =  _context.Orders.Select(x =>
             * new
             * {
             *  x.CustomerId,
             *  x.ArrivalDate,
             *  x.ArrivalHour,
             *  x.RequestDate
             * }).Where(x => x.CustomerId == id);*/
            await _context.SaveChangesAsync();

            return(customer);
        }