public ActionResult Create(ClientModel clientmodel) { if (_avdb.Clients.Any(x => x.Email == clientmodel.Email)) { ModelState.AddModelError("Email", "Client with this E-mail already exists"); } if (_avdb.Clients.Any(x => x.MobilePhoneNumber == clientmodel.MobilePhoneNumber)) { ModelState.AddModelError("MobilePhoneNumber", "Client with this Mobile Phone already exists"); } if (_avdb.Clients.Any(x => (x.PassportNumber == clientmodel.PassportNumber && x.PassportSerie == clientmodel.PassportSerie))) { ModelState.AddModelError("PassportNumber", "Client with this Passport Number already exists"); } if (_avdb.Clients.Any(x => (x.IndentityNo == clientmodel.IndentityNo))) { ModelState.AddModelError("IndentityNo", "Client with this Indentity Number already exists"); } if (ModelState.IsValid) { _avdb.Clients.Add(clientmodel.ToEntity()); var errors = _avdb.GetValidationErrors(); _avdb.SaveChanges(); return RedirectToAction("Index"); } ViewBag.Cities = new SelectList(_avdb.Cities, "Id", "Title"); ViewBag.Disabilities = new SelectList(_avdb.Disabilities, "Id", "Title"); ViewBag.MaritalStatuses = new SelectList(_avdb.MaritalStatuses, "Id", "Title"); ViewBag.Nationalities = new SelectList(_avdb.Nationalities, "Id", "Title"); ViewBag.Genders = new SelectList(_avdb.Genders, "Id", "Title"); return View(clientmodel); }