Example #1
0
        public NewEntryVM UpdateEntry(int id, NewEntryVM vm)
        {
            try
            {
                _updateItem.UpdateStockItem(vm.StockItems);

                //_updateItem.UpdateMaterial(vm.Materials);
                vm.Materials.Id = 0;

                _context.Materials.Add(vm.Materials);
                _context.SaveChanges();

                StockMaterials stockMaterials = new StockMaterials
                {
                    StockItemId = vm.StockItems.Id,
                    MaterialId  = vm.Materials.Id
                };

                _context.StockMaterials.Add(stockMaterials);

                _context.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.Beep();
            }
            return(vm);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            StockMaterials stockmaterials = db.StockMaterials.Find(id);

            db.StockMaterials.Remove(stockmaterials);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        //
        // GET: /StockMaterials/Delete/5

        public ActionResult Delete(int id = 0)
        {
            StockMaterials stockmaterials = db.StockMaterials.Find(id);

            if (stockmaterials == null)
            {
                return(HttpNotFound());
            }
            return(View(stockmaterials));
        }
 public ActionResult Edit(StockMaterials stockmaterials)
 {
     if (ModelState.IsValid)
     {
         db.Entry(stockmaterials).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(stockmaterials));
 }
        public ActionResult Create(StockMaterials stockmaterials)
        {
            if (ModelState.IsValid)
            {
                db.StockMaterials.Add(stockmaterials);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(stockmaterials));
        }
Example #6
0
        public NewEntryVM CreateNewEntry(NewEntryVM vm)
        {
            _context.StockItems.Add(vm.StockItems);
            _context.Materials.Add(vm.Materials);

            _context.SaveChanges(); // changes are saved to context to update the Id fields

            StockMaterials stockMaterials = new StockMaterials
            {
                StockItemId = vm.StockItems.Id,
                MaterialId  = vm.Materials.Id
            };

            _context.StockMaterials.Add(stockMaterials);

            _context.SaveChanges();

            return(vm);
        }