public ViewResult New() { NewAttorneyViewModel viewModel = new NewAttorneyViewModel { Attorney = new Attorney { User = new User() }, Departments = _departmentsRepo.Departments.ToList() }; ViewBag.AddedAttorney = TempData["added"]; return(View(viewModel)); }
public IActionResult Edit(int id) { TempData.Keep(); ViewBag.UpdatedAttorney = TempData["updated"]; NewAttorneyViewModel viewModel = new NewAttorneyViewModel { Departments = _departmentsRepo.Departments.ToList() }; viewModel.Attorney = _attorneysRepo.Attorneys.Where(a => a.Id == id).Include(a => a.User).Include(a => a.Department).First(); if (viewModel.Attorney == null) { return(NotFound()); } return(View(viewModel)); }
public IActionResult New(Attorney attorney) { if (!_usersRepo.VerifyUsername(attorney.User.Username)) { ModelState.AddModelError("uqUsername", "El usuario ingresado ya existe"); } if (!_attorneysRepo.VerifyEmail(attorney.Email)) { ModelState.AddModelError("uqEmail", "El correo ingresado ya existe"); } if (!_attorneysRepo.VerifyNotaryCode(attorney.NotaryCode)) { ModelState.AddModelError("uqNotaryCode", "El código de notario ingresado ya existe"); } //if(attorney.User.Username.Contains(" ")) //{ // ModelState.AddModelError("whiteSpacesUsername", "El nombre de usuario contiene espacios en blanco, favor no incluir espacios en blanco"); //} if (!ModelState.IsValid) { NewAttorneyViewModel viewModel = new NewAttorneyViewModel { Departments = _departmentsRepo.Departments.ToList() }; viewModel.Attorney = attorney; return(View(viewModel)); } else { //string guidGenerated = _guidManager.GenerateGuid(); //string passwordDefault = guidGenerated.Substring(guidGenerated.Length - 12, 12); string passwordOriginal = attorney.User.Password; string passwordHashed = _cryptoManager.HashString(attorney.User.Password); attorney.User.Password = passwordHashed; _attorneysRepo.Save(attorney); //Envío de password sin hash al usuario string emailBody = $"Se le ha creado un acceso a la aplicación Lexincorp Nicaragua Web, su usuario es {attorney.User.Username} " + $"y su clave de acceso es {passwordOriginal}. \n**Este es un mensaje autogenerado por el sistema, favor no responder**"; _mailSender.SendMail(attorney.Email, "Usuario web creado para aplicación Lexincorp Nicaragua Web", emailBody); TempData["added"] = true; return(RedirectToAction("New")); } }
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"] })); } }