public ActionResult MedicCreate(Medic medic) { if (ModelState.IsValid) { MedicComparer med = new MedicComparer(); int ok = 1; if (db.Medics.Count() > 0) { foreach (var a in db.Medics) { if (med.Equals(a, medic)) { ok = 0; } } } if (ok == 1) { medic.idMedic = 1; db.Medics.Add(medic); db.SaveChanges(); TempData["Success"] = "Medic successfully submitted!"; return(RedirectToAction("MedicIndex")); } else { TempData["Warning"] = "Medic already exists!"; return(RedirectToAction("MedicEdit")); } } return(View()); }
public ActionResult MedicCreate(Medic medic) { if (ModelState.IsValid) { MedicComparer cmp = new MedicComparer(); int ok = 1; if (db.Medics.Count() > 0) { foreach (var d in db.Medics) { if (cmp.Equals(d, medic)) { ok = 0; } } } if (ok == 1) { TempData["Success"] = "Medic successfully added!"; db.Medics.Add(medic); db.SaveChanges(); return(RedirectToAction("MedicIndex")); } else { TempData["Warning"] = "Medic already exists! Try add another one!"; return(RedirectToAction("MedicCreate")); } } return(View()); }