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);
        }
        public Entities.Order GetOrderById(int order)
        {
            List <Entities.Order> orders = new List <Entities.Order>();

            foreach (Entities.Order r in _context.Orders)
            {
                orders.Add(r);
            }
            Entities.Order record = (from rec in orders
                                     where rec.Id == order
                                     select rec).FirstOrDefault();
            return(record);
        }