public ActionResult Create() { ItemsTipViewModel model = new ItemsTipViewModel(); model.categories = _context.categories.ToList(); return(View(model)); }
public ActionResult Edit(int id) { ItemsTipViewModel model = new ItemsTipViewModel(); model.categories = _context.categories.ToList(); var item = _context.items.SingleOrDefault(m => m.Id == id); model.item = item; return(View(model)); }
public ActionResult Edit(ItemsTipViewModel model) { if (!ModelState.IsValid) { model.categories = _context.categories.ToList(); return(View("Edit", model)); } int id = model.item.Id; var item = _context.items.SingleOrDefault(m => m.Id == id); Tip tipNaProdukt = _context.categories.SingleOrDefault(m => m.Id == model.item.TipId); item.Name = model.item.Name; item.Price = model.item.Price; item.Desc = model.item.Desc; item.ImgURL = model.item.ImgURL; item.Stock = model.item.Stock; item.TipId = model.item.TipId; item.Tip = tipNaProdukt; _context.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(ItemsTipViewModel viewModel) { if (!ModelState.IsValid) { viewModel.categories = _context.categories.ToList(); return(View("Create", viewModel)); } Tip tipNaProdukt = _context.categories.SingleOrDefault(m => m.Id == viewModel.item.TipId); Item item = new Item(); item.Name = viewModel.item.Name; item.Price = viewModel.item.Price; item.Stock = viewModel.item.Stock; item.Desc = viewModel.item.Desc; item.Tip = tipNaProdukt; item.TipId = viewModel.item.TipId; item.ImgURL = viewModel.item.ImgURL; _context.items.Add(item); _context.SaveChanges(); return(RedirectToAction("Index")); }