예제 #1
0
        public Models.Order AddOrder(Models.Order order, Models.AppUser user, Models.Location location)
        {
            _context.Orders.Add(
                new Entities.Order {
                Total      = order.Total,
                LocationId = GetLocationID(location),
                UserId     = GetUserID(user),
            }
                );
            _context.SaveChanges();
            //get the order that was just created
            List <Entities.Order> orders = new List <Entities.Order>();

            foreach (Entities.Order o in _context.Orders)
            {
                orders.Add(o);
            }
            IEnumerable <Entities.Order> SortedOrders = from o in orders
                                                        group o by o.Id into sorto
                                                        select sorto.OrderByDescending(os => os.Id).First();

            int recentOrderId = SortedOrders.Max(x => x.Id);

            Entities.Order recentOrder = GetOrderById(recentOrderId);

            foreach (Models.Products prod in order.ProductList)
            {
                int prodId = GetProductID(prod);
                AddLineItem(prod, recentOrderId);
            }
            _context.SaveChanges();
            return(order);
        }
예제 #2
0
 public Models.Order CreateOrder(List <Models.Products> items, Models.AppUser cust, Models.Location loc)
 {
     Models.Order newOrder = new Models.Order(items, cust, loc);
     return(_repo.AddOrder(newOrder, newOrder.Customer, newOrder.Location));
 }