public ActionResult Create( EducationSystem educationSystem) { if (ModelState.IsValid) { var count = db.EducationSystems.Select(a => a.SystemName.ToLower().Equals(educationSystem.SystemName.ToLower()) & a.SystemId != educationSystem.SystemId).Count(); if(count == 0) { db.EducationSystems.Add(educationSystem); db.SaveChanges(); return RedirectToAction("Index"); } else { ModelState.AddModelError("SystemName", "System Name already exists in DB."); return View(educationSystem); } } return View(educationSystem); }
public ActionResult Edit(EducationSystem educationSystem) { if (ModelState.IsValid) { var count = db.EducationSystems.Where<EducationSystem>(a => (a.SystemName.ToLower().Equals(educationSystem.SystemName.ToLower()) & a.SystemId != educationSystem.SystemId)).Count(); if(count == 0) { db.Entry(educationSystem).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } else { ModelState.AddModelError("SystemName", "System Name already exists in DB."); return View(educationSystem); } } return View(educationSystem); }