private void Prepare(UnsubscribeRequestModel requestModel, UnsubscribeModel unsubscribeModel) { requestModel.Prepare(); requestModel.Validate(); // Get the user. var user = _usersQuery.GetUser(requestModel.UserId.Value); if (user == null) { throw new ValidationErrorsException(new NotFoundValidationError("UserId", requestModel.UserId.Value)); } if (CurrentRegisteredUser == null) { unsubscribeModel.Login.LoginId = _loginCredentialsQuery.GetLoginId(requestModel.UserId.Value); } // Get the category. unsubscribeModel.Category = _settingsQuery.GetCategory(requestModel.Category); if (unsubscribeModel.Category == null) { throw new ValidationErrorsException(new NotFoundValidationError("Category", requestModel.Category)); } }
public ActionResult Unsubscribe(UnsubscribeRequestModel requestModel) { var model = new UnsubscribeModel { Login = new Login() }; try { Prepare(requestModel, model); } catch (UserException ex) { ModelState.AddModelError(ex, new StandardErrorHandler()); } return(View(model)); }
public ActionResult PostUnsubscribe(UnsubscribeRequestModel requestModel) { var model = new UnsubscribeModel { Login = new Login() }; try { Prepare(requestModel, model); // Unsubscribe. _settingsCommand.SetFrequency(requestModel.UserId.Value, model.Category.Id, Frequency.Never); model.HasUnsubscribed = true; ModelState.AddModelConfirmation("You have now been unsubscribed from this type of email."); } catch (UserException ex) { ModelState.AddModelError(ex, new StandardErrorHandler()); } return(View(model)); }