Пример #1
0
        public ActionResult Purchase(Models.Inventory_.Purchase.ViewModel m)
        {
            if (ModelState.IsValid)
            {
                using (var db = new dbEntities())
                {
                    foreach (var lm in m.Locations)
                    {
                        foreach (var pm in lm.Inventory)
                        {
                            db.Inventories.Single(i => i.LocationId == lm.Id && i.ProductId == pm.Id).Quantity += pm.Quantity;
                        }
                    }
                    db.SaveChanges();
                }

                return RedirectToAction("Purchase", "Inventory");
            }
            return View();
        }
Пример #2
0
        public ActionResult Sell(_5Bites.Models.Store_.Sell.ViewModel m)
        {
            if (ModelState.IsValid)
            {
                int EmployeeId = (int)Session.Contents["EmployeeId"];

                using (var db = new dbEntities())
                {
                    foreach (var sm in m.Stores)
                    {
                        var s = db.Stores.Single(s_ => s_.Id == sm.Id);
                        foreach (var pm in sm.Inventory.Where(pm => pm.QuantitySold != 0))
                        {
                            var t = new Transaction();
                            t.ProductId = pm.Id;
                            t.StoreId = sm.Id;
                            t.EmployeeId = EmployeeId;
                            t.Quantity = pm.QuantitySold;
                            t.Timestamp = DateTime.Now;
                            db.Transactions.Add(t);

                            s.Location.Inventories.Single(i => i.ProductId == pm.Id).Quantity -= pm.QuantitySold;
                        }
                        s.Bank += sm.Inventory.Sum(pm => pm.QuantitySold * pm.Price);
                    }
                    db.SaveChanges();
                }

                return RedirectToAction("Sell", "Store");
            }
            return View(m);
        }