// GET: StockItem/Edit/5
 public ActionResult Edit(int id)
 {
     using (StockItemContext stockItem = new StockItemContext())
     {
         return(View(stockItem.StockItems.Where(x => x.stkId == id).FirstOrDefault()));
     }
 }
 // GET: StockItem
 public ActionResult Index()
 {
     using (StockItemContext stockItem = new StockItemContext())
     {
         return(View(stockItem.StockItems.ToList()));
     }
 }
 public ActionResult DeleteSup(int id)
 {
     using (StockItemContext stockItem = new StockItemContext())
     {
         return(View(stockItem.Suppliers.Where(x => x.SupId == id).FirstOrDefault()));
     }
 }
 public ActionResult DeleteUnitOfSale(int id)
 {
     using (StockItemContext stockItem = new StockItemContext())
     {
         return(View(stockItem.UnitOfSales.Where(x => x.UoSId == id).FirstOrDefault()));
     }
 }
        public StockItemsStatusController(StockItemContext context)
        {
            this.context = context;

            if (!context.StockItems.Any())
            {
                context.StockItems.Add(new StockItem()
                {
                    Id = 1, InStock = true, ProductId = 1
                });
                context.SaveChanges();
            }
        }
 public ActionResult EditUnitOfSale(int id, UnitOfSale unitOfSales)
 {
     try
     {
         using (StockItemContext stockItem = new StockItemContext())
         {
             stockItem.Entry(unitOfSales).State = EntityState.Modified;
             stockItem.SaveChanges();
         }
         return(RedirectToAction("UnitOfSaleIndex"));
     }
     catch
     {
         return(View());
     }
 }
 public ActionResult EditSup(int id, Supplier suppliers)
 {
     try
     {
         using (StockItemContext stockItem = new StockItemContext())
         {
             stockItem.Entry(suppliers).State = EntityState.Modified;
             stockItem.SaveChanges();
         }
         return(RedirectToAction("SupplierIndex"));
     }
     catch
     {
         return(View());
     }
 }
        public ActionResult Create(StockItem StockItem)
        {
            try
            {
                using (StockItemContext stockItem = new StockItemContext())
                {
                    stockItem.StockItems.Add(StockItem);
                    stockItem.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult UnitOfSaleIndex()
        {
            StockItemContext    db          = new StockItemContext();
            List <UnitOfSale>   UnitOfSales = db.UnitOfSales.ToList();
            UnitOfSaleViewModel UoSvm       = new UnitOfSaleViewModel();

            List <UnitOfSaleViewModel>
            UnitOfSaleViewModel = UnitOfSales.Select(x => new UnitOfSaleViewModel
            {
                UoSId       = x.UoSId,
                Code        = x.Code,
                Description = x.Description
            }).ToList();


            return(View(UnitOfSaleViewModel));
        }
        public ActionResult CreateUnitOfSale(UnitOfSale unitOfSale)
        {
            try
            {
                using (StockItemContext stockItem = new StockItemContext())
                {
                    stockItem.UnitOfSales.Add(unitOfSale);
                    stockItem.SaveChanges();
                }

                return(RedirectToAction("UnitOfSaleIndex"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult CreateSup(Supplier supplier)
        {
            try
            {
                using (StockItemContext stockItem = new StockItemContext())
                {
                    stockItem.Suppliers.Add(supplier);
                    stockItem.SaveChanges();
                }

                return(RedirectToAction("SupplierIndex"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult DeleteUnitOfSale(int id, FormCollection collection)
        {
            try
            {
                using (StockItemContext stockItemContext = new StockItemContext())
                {
                    UnitOfSale unitOfSale = stockItemContext.UnitOfSales.Where(x => x.UoSId == id).FirstOrDefault();
                    stockItemContext.UnitOfSales.Remove(unitOfSale);
                    stockItemContext.SaveChanges();
                }

                return(RedirectToAction("UnitOfSaleIndex"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult DeleteSup(int id, FormCollection collection)
        {
            try
            {
                using (StockItemContext stockItemContext = new StockItemContext())
                {
                    Supplier suppliers = stockItemContext.Suppliers.Where(x => x.SupId == id).FirstOrDefault();
                    stockItemContext.Suppliers.Remove(suppliers);
                    stockItemContext.SaveChanges();
                }

                return(RedirectToAction("SupplierIndex"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult SupplierIndex()
        {
            StockItemContext  db        = new StockItemContext();
            List <Supplier>   Suppliers = db.Suppliers.ToList();
            SupplierViewModel spvm      = new SupplierViewModel();

            List <SupplierViewModel>
            SupplierViewModel = Suppliers.Select(x => new SupplierViewModel
            {
                SupId       = x.SupId,
                Code        = x.Code,
                Description = x.Description,
                CostPrice   = x.CostPrice
            }).ToList();


            return(View(SupplierViewModel));
        }