public ActionResult New() { var viewModel = new StationeryFormViewModel() { Suppliers = _context.Supplier.ToList(), Categories = _context.Stationery.Select(m => m.Category).Distinct().ToList(), Units = _context.Stationery.Select(m => m.UnitOfMeasure).Distinct().ToList() }; return(View("StationeryForm", viewModel)); }
public ActionResult Save(Stationery stationery) { string a = stationery.ItemId; if (!ModelState.IsValid) { var viewModel = new StationeryFormViewModel(stationery) { Suppliers = _context.Supplier.ToList(), Categories = _context.Stationery.Select(m => m.Category).Distinct().ToList(), Units = _context.Stationery.Select(m => m.UnitOfMeasure).Distinct().ToList() }; return(View("StationeryForm", viewModel)); } //for Create New Stationery operation if (stationery.ItemId == null) { stationery.ItemId = GenerateItemId(stationery.Description); stationery.ActiveState = true; _context.Stationery.Add(stationery); } //for Update Stationery operation else { var stationeryInDb = _context.Stationery.Single(m => m.ItemId == stationery.ItemId); stationeryInDb.Category = stationery.Category; stationeryInDb.Description = stationery.Description; stationeryInDb.ReorderLevel = stationery.ReorderLevel; stationeryInDb.ReorderQuantity = stationery.ReorderQuantity; stationeryInDb.UnitOfMeasure = stationery.UnitOfMeasure; stationeryInDb.QuantityWarehouse = stationery.QuantityWarehouse; stationeryInDb.Location = stationery.Location; stationeryInDb.FirstSupplierId = stationery.FirstSupplierId; stationeryInDb.FirstSuppPrice = stationery.FirstSuppPrice; stationeryInDb.SecondSupplierId = stationery.SecondSupplierId; stationeryInDb.SecondSuppPrice = stationery.SecondSuppPrice; stationeryInDb.ThirdSupplierId = stationery.ThirdSupplierId; stationeryInDb.ThirdSuppPrice = stationery.ThirdSuppPrice; } try { _context.SaveChanges(); } catch (DbEntityValidationException e) { Console.WriteLine(e); } return(RedirectToAction("Index", "ManageStationery")); }
public ActionResult Edit(string id) { var stationery = _context.Stationery.SingleOrDefault(c => c.ItemId == id); if (stationery == null) { return(HttpNotFound()); } var viewModel = new StationeryFormViewModel(stationery); viewModel.Suppliers = _context.Supplier.ToList(); viewModel.Categories = _context.Stationery.Select(m => m.Category).Distinct().ToList(); viewModel.Units = _context.Stationery.Select(m => m.UnitOfMeasure).Distinct().ToList(); return(View("StationeryForm", viewModel)); }