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);

        }
        public ActionResult Edit(ClientModel clientmodel)
        {
            if (_avdb.Clients.Any(x => x.Email == clientmodel.Email && x.Id != clientmodel.Id))
            {
                ModelState.AddModelError("Email", "Client with this E-mail already exists");
            }

            if (_avdb.Clients.Any(x => x.MobilePhoneNumber == clientmodel.MobilePhoneNumber && x.Id != clientmodel.Id))
            {
                ModelState.AddModelError("MobilePhoneNumber", "Client with this Mobile Phone already exists");
            }

            if (_avdb.Clients.Any(x => (x.PassportNumber == clientmodel.PassportNumber && x.PassportSerie == clientmodel.PassportSerie && x.Id != clientmodel.Id)))
            {
                ModelState.AddModelError("PassportNumber", "Client with this Passport Number already exists");
            }

            if (_avdb.Clients.Any(x => (x.IndentityNo == clientmodel.IndentityNo && x.Id != clientmodel.Id)))
            {
                ModelState.AddModelError("IndentityNo", "Client with this Indentity Number already exists");
            }

            if (ModelState.IsValid)
            {
                var clientEntity = _avdb.Clients.Find(clientmodel.Id);

                clientEntity.Birthdate = clientmodel.Birthdate;
                clientEntity.DisabilityId = clientmodel.DisabilityId;
                clientEntity.Email = clientmodel.Email;
                clientEntity.FirstName = clientmodel.FirstName;
                clientEntity.GenderId = clientmodel.GenderId;
                clientEntity.IndentityNo = clientmodel.IndentityNo;
                clientEntity.IssueDate = clientmodel.IssueDate;
                clientEntity.JobPosition = clientmodel.JobPosition;
                clientEntity.LastName = clientmodel.LastName;
                clientEntity.Liable = clientmodel.Liable;
                clientEntity.LocationAddress = clientmodel.LocationAddress;
                clientEntity.LocationCityId = clientmodel.LocationCityId;
                clientEntity.MaritalStatusId = clientmodel.MaritalStatusId;
                clientEntity.MobilePhoneNumber = clientmodel.MobilePhoneNumber;
                clientEntity.MonthlyIncome = clientmodel.MonthlyIncome;
                clientEntity.NationalityId = clientmodel.NationalityId;
                clientEntity.PassportIssuingAuthority = clientmodel.PassportIssuingAuthority;
                clientEntity.PassportNumber = clientmodel.PassportNumber;
                clientEntity.PassportSerie = clientmodel.PassportSerie;
                clientEntity.Pensioner = clientmodel.Pensioner;
                clientEntity.RegistrationAddress = clientmodel.RegistrationAddress;
                clientEntity.RegistrationCityId = clientmodel.RegistrationCityId;
                clientEntity.Work = clientmodel.Job;
                _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);
        }