Ejemplo n.º 1
0
        public ActionResult Sell()
        {
            int EmployeeId = (int)Session.Contents["EmployeeId"];
            var m = new _5Bites.Models.Store_.Sell.ViewModel();

            using (var db = new dbEntities())
            {
                var ss = db.EmployeeStores.Where(es => es.EmployeeId == EmployeeId).Select(es => es.Store);
                foreach (var s in ss)
                {
                    var sm = new Models.Store_.Sell.StoreModel();
                    sm.Id = s.Id;
                    sm.Bank = s.Bank;
                    sm.Name = s.Location.Name;
                    foreach (var i in s.Location.Inventories)
                    {
                        var pm = new Models.Store_.Sell.ProductModel();
                        pm.Id = i.Product.Id;
                        pm.Description = i.Product.Name;
                        pm.Price = i.Product.RetailPrice;
                        pm.Quantity = i.Quantity;
                        sm.Inventory.Add(pm);
                    }
                    m.Stores.Add(sm);
                }
            }

            return View(m);
        }
Ejemplo n.º 2
0
        public ActionResult Inventory()
        {
            var m = new _5Bites.Models.Store_.Inventory.ViewModel();
            using (var db = new dbEntities())
            {
                var ss = db.Stores.Include("Location");
                foreach (var s in ss)
                {
                    var sm = new Models.Store_.Inventory.StoreModel();
                    sm.Id = s.Id;
                    sm.Name = s.Location.Name;
                    foreach (var i in s.Location.Inventories)
                    {
                        var pm = new Models.Store_.Inventory.ProductModel();
                        pm.Description = i.Product.Name;
                        pm.Price = i.Product.RetailPrice;
                        pm.Quantity = i.Quantity;
                        sm.Inventory.Add(pm);
                    }
                    m.Stores.Add(sm);
                }
            }

            return View(m);
        }
Ejemplo n.º 3
0
        public ActionResult Transfer()
        {
            int EmployeeId = (int)Session.Contents["EmployeeId"];
            var m = new Models.Inventory_.Transfer.ViewModel();

            using (var db = new dbEntities())
            {
                var ps = db.Products;
                var ls = db.EmployeeLocations.Where(el => el.EmployeeId == EmployeeId).Select(el => el.Location);

                foreach (var l in ls)
                {
                    var lm = new Models.Inventory_.Transfer.LocationModel();
                    lm.Id = l.Id;
                    lm.Name = l.Name;
                    foreach (var p in ps)
                    {
                        var pm = new Models.Inventory_.Transfer.ProductModel();
                        pm.Id = p.Id;
                        pm.Name = p.Name;
                        pm.OldQuantity = p.Inventories.SingleOrDefault(i => i.Location == l).Quantity;
                        pm.Quantity = pm.OldQuantity;
                        lm.Inventory.Add(pm);
                    }
                    m.Locations.Add(lm);
                }
            }

            return View(m);
        }
Ejemplo n.º 4
0
 public ActionResult Transactions()
 {
     var m = new Models.Home.Transactions.ViewModel();
     using (var db = new dbEntities())
     {
         var ts = db.Transactions;
         foreach (var t in ts)
         {
             var tm = new Models.Home.Transactions.TransactionModel();
             tm.EmployeeName = t.Employee.Username;
             tm.StoreName = t.Store.Location.Name;
             tm.ProductName = t.Product.Name;
             tm.Quantity = t.Quantity;
             tm.Timestamp = t.Timestamp;
             m.Transactions.Add(tm);
         }
     }
     return View(m);
 }
Ejemplo n.º 5
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();
        }
Ejemplo n.º 6
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);
        }