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

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