public void Save(Relationship 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(Relationship obj)
        {
            if(Request.IsAjaxRequest())
            {
                dataManager.Relationships.Save(obj);

                return Json(new { Name = obj.Type, Id = obj.Id, Key = "RelationshipId" }, JsonRequestBehavior.AllowGet);
            }
            return Json("", JsonRequestBehavior.AllowGet);
        }
 public ActionResult Create(Relationship obj, FormCollection collection)
 {
     if (ModelState.IsValid)
     {
         if (!dataManager.Relationships.GetAll().Any(o => o.Type == obj.Type))
         {
             dataManager.Relationships.Save(obj);
             return RedirectToAction("Show", new { Id = obj.Id });
         }
         else
         {
             ModelState.AddModelError("Name",
                 "Тип взаимоотношений с названием \"" + obj.Type + "\" уже существует!");
             return View(obj);
         }
     }
     return View(obj);
 }
 public ActionResult Edit(Relationship obj)
 {
     if (ModelState.IsValid)
     {
         if (!dataManager.Relationships.GetAll()
             .Any(o =>
                 o.Type == obj.Type &&
                 o.Id != obj.Id))
         {
             var objFromDb = dataManager.Relationships.Get(obj.Id);
             objFromDb.Type = obj.Type;
             dataManager.Relationships.Save(objFromDb);
             return RedirectToAction("Show", new { Id = obj.Id });
         }
         else
         {
             ModelState.AddModelError("Name",
                 "Национальность с названием \"" + obj.Type + "\" уже существует!");
             return View(obj);
         }
     }
     return View(obj);
 }