コード例 #1
0
 public IActionResult Edit(Attorney attorney)
 {
     TempData.Keep();
     if (!_usersRepo.VerifyUsername(attorney.User.Username) && !_usersRepo.VerifyAttorneyIDAndUsername(attorney.Id, attorney.UserId))
     {
         ModelState.AddModelError("uqUsername", "El usuario ingresado ya existe");
     }
     if (!_attorneysRepo.VerifyEmail(attorney.Email) && !_attorneysRepo.VerifyAttorneyIDAndEmailOwnership(attorney.Id, attorney.Email))
     {
         ModelState.AddModelError("uqEmail", "El correo ingresado ya existe");
     }
     if (!_attorneysRepo.VerifyNotaryCode(attorney.NotaryCode) && !_attorneysRepo.verifyAttorneyIDAndNotaryCodeOwnership(attorney.Id, attorney.NotaryCode))
     {
         ModelState.AddModelError("uqNotaryCode", "El código de notario ingresado ya existe");
     }
     if (!ModelState.IsValid)
     {
         NewAttorneyViewModel viewModel = new NewAttorneyViewModel
         {
             Departments = _departmentsRepo.Departments.ToList()
         };
         viewModel.Attorney = attorney;
         return(View(viewModel));
     }
     else
     {
         bool passwordModified = false;
         if (attorney.User.Password != null && (attorney.User.Password != " " || attorney.User.Password != ""))
         {
             passwordModified = true;
             string passwordOriginal = attorney.User.Password;
             string passwordHashed   = _cryptoManager.HashString(attorney.User.Password);
             attorney.User.Password = passwordHashed;
         }
         _attorneysRepo.Save(attorney, passwordModified);
         _usersRepo.Save(attorney.User);
         TempData["updated"] = true;
         return(RedirectToAction("Admin", new { filter = TempData["filter"] }));
     }
 }