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 void TakeFrom(Models.Location loc, Models.Products prod) { int locId = _repo.GetLocationID(loc); int prodId = _repo.GetProductID(prod); _repo.ReduceInventory(locId, prodId); }
public int GetLocationID(Models.Location location) { List <Entities.Location> locs = new List <Entities.Location>(); foreach (Entities.Location r in _context.Locations) { locs.Add(r); } int locId = (from Loca in locs where Loca.LocAddress == location.Address select Loca.Id).FirstOrDefault(); return(locId); }
public List <Entities.Inventory> ShowInventory(Models.Location loc) { int locId = GetLocationID(loc); List <Entities.Inventory> invent = new List <Entities.Inventory>(); foreach (Entities.Inventory i in _context.Inventories) { if (i.LocationId == locId) { invent.Add(i); } } return(invent); }
public string ShowInventory(Models.Location location) { List <Entities.Inventory> InventoryList = _repo.ShowInventory(location); string list = "Inventory: "; foreach (Entities.Inventory p in InventoryList) { p.Product = _repo.GetProduct(p.ProductId); list = list + $"\n{p.Product.ToString()}"; } return(list); }
public void RestockInventory(Models.Location loc) { int locationId = GetLocationID(loc); List <Entities.Inventory> inv = new List <Entities.Inventory>(); foreach (Entities.Inventory r in _context.Inventories) { inv.Add(r); } var updatequery = from rec in _context.Inventories where rec.LocationId == locationId && rec.Quantity < 10 select rec; foreach (Entities.Inventory item in updatequery) { item.Quantity += 10; } _context.SaveChanges(); }
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)); }
public void Replenish(Models.Location loc) { _repo.RestockInventory(loc); }