public virtual ActionResult Edit(JobSearch jobSearch) { try { // Determine if we are editing or adding a jobsearch if (jobSearch.Id == 0) { jobSearch = _createJobSearchCommand.ForUserId(CurrentUserId) .WithName(jobSearch.Name) .WithDescription(jobSearch.Description) .Execute(); } else { _editJobSearchCommand.WithJobSearchId(jobSearch.Id) .SetName(jobSearch.Name) .SetDescription(jobSearch.Description) .CalledByUserId(CurrentUserId) .Execute(); } // Set the current user's last visited job search to this one _editUserCommand.WithUserId(CurrentUserId).SetLastVisitedJobSearchId(jobSearch.Id).Execute(); return(RedirectToAction(MVC.Task.Index())); } // Show validation errors to the user and allow them to fix them catch (ValidationException ex) { foreach (var error in ex.Errors) { ModelState.AddModelError(error.PropertyName, error.ErrorMessage); } return(View(jobSearch)); } }
public virtual ActionResult Edit(EditUserDetailsParams model) { if (model.NewPassword != model.NewPasswordConfirmation) { ModelState.AddModelError("", "Your new password and the new password confirmation do not match"); } if (string.IsNullOrWhiteSpace(model.FullName)) { ModelState.AddModelError("FullName", "You must enter a valid full name"); } try { _editUserCmd.WithUserId(CurrentUserId) .WithExistingPassword(model.CurrentPassword) .SetPassword(model.NewPassword) .SetFullName(model.FullName) .Execute(); } catch (MJLDuplicateEmailException) { ModelState.AddModelError("NewEmail", "A user already exists with the specified email address"); } catch (MJLIncorrectPasswordException) { ModelState.AddModelError("CurrentPassword", "Your current password is incorrect"); } if (!ModelState.IsValid) { return(View(model)); } return(RedirectToAction(MVC.Home.Index())); }