public void Save(Education obj) { if (obj.Id == 0) context.Entry(obj).State = System.Data.Entity.EntityState.Added; else context.Entry(obj).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); }
public ActionResult CreatePartial(Education obj) { if(Request.IsAjaxRequest()) { dataManager.Educations.Save(obj); return Json(new { Name = obj.Name, Id = obj.Id, Key = "EducationId" }, JsonRequestBehavior.AllowGet); } return Json("", JsonRequestBehavior.AllowGet); }
public ActionResult Create(Education obj) { if (ModelState.IsValid) { if (!dataManager.Educations.GetAll().Any(o => o.Name == obj.Name)) { dataManager.Educations.Save(obj); return RedirectToAction("Show", new { Id = obj.Id }); } else { ModelState.AddModelError("Name", "Образование с названием \"" + obj.Name + "\" уже существует!"); return View(obj); } } return View(obj); }