public ActionResult TeaAdd(Tea form) { if (ModelState.IsValid == false) { ModelState.AddModelError("Error", "Invalid model"); return View(form); } Tea newTea = new Tea { TeaName = form.TeaName, TeaDescription = form.TeaDescription, TeaImageFileName = form.TeaImageFileName, TeaTypeID=form.TeaTypeID, Price = form.Price, Size = form.Size }; try { _dataContext.Teas.InsertOnSubmit(newTea); _dataContext.SubmitChanges(); } catch (Exception e) { Console.WriteLine(e); } return View(newTea); //return RedirectToAction("TeaAddIndex"); }
public ActionResult TeaUpdate(FormCollection form) { Tea teaInput = new Tea(); try { UpdateModel(teaInput); Tea teaOld = _dataContext.Teas.FirstOrDefault(t => t.TeaID == teaInput.TeaID); if (teaOld != null) { teaOld.TeaName = teaInput.TeaName; teaOld.TeaDescription = teaInput.TeaDescription; teaOld.TeaImageFileName = teaInput.TeaImageFileName; teaOld.Price = teaInput.Price; teaOld.Size = teaInput.Size; _dataContext.SubmitChanges(); } } catch (Exception e) { Console.WriteLine(e); } return View(teaInput); //return RedirectToRoute("Tea",new {teaInput.TeaID }); }
partial void DeleteTea(Tea instance);
partial void UpdateTea(Tea instance);
partial void InsertTea(Tea instance);
private void detach_Teas(Tea entity) { this.SendPropertyChanging(); entity.TeaType = null; }
private void attach_Teas(Tea entity) { this.SendPropertyChanging(); entity.TeaType = this; }