public async Task <IActionResult> EmployerNextSteps(EmployerContactViewModel viewModel) { Validate(viewModel); if (!ModelState.IsValid || viewModel.ContactFormSent || HasContactFormSentCookie()) { return(View(viewModel)); } if (!await _emailService.SendEmployerContactEmail( viewModel.FullName, viewModel.OrganisationName, viewModel.Phone, viewModel.Email)) { return(View("Error", new ErrorViewModel())); } viewModel.ContactFormSent = true; Response.Cookies.Append(AppConstants.EmployerContactFormSentCookieName, "true", new CookieOptions { Expires = DateTime.Now.AddDays(365), IsEssential = true, HttpOnly = false, Secure = true }); return(View(viewModel)); }
private void Validate(EmployerContactViewModel viewModel) { if (string.IsNullOrEmpty(viewModel.Phone)) { return; } if (!viewModel.Phone.Any(char.IsDigit)) { ModelState.AddModelError(nameof(viewModel.Phone), "You must enter a number"); } else if (!Regex.IsMatch(viewModel.Phone, @"^(?:.*\d.*){7,}$")) { ModelState.AddModelError(nameof(viewModel.Phone), "You must enter a telephone number that has 7 or more numbers"); } }
public EmployerContactViewModelBuilder() { _viewModel = new EmployerContactViewModel(); }