public PositiveFormModel(AppDbContext context, IConfiguration config, ICaseService caseService, ITesterService testerService, IUserService userService, ITestingCentreService testingCentreService)
 {
     _CaseService          = caseService;
     _TesterService        = testerService;
     _UserService          = userService;
     _TestingCentreService = testingCentreService;
     _config  = config;
     CaseForm = new CaseForm();
 }
        public async Task <IActionResult> OnPostAsync()
        {
            bool extraValid = true;

            if (ModelState.IsValid)
            {
                if (!PostcodeValidator.IsValid(CaseForm.Postcode, _config["googleApiKey"]))
                {
                    ModelState.AddModelError("CaseForm.Postcode", PostcodeValidator.FormatErrorMessage());
                    extraValid = false;
                }

                if (CaseForm.Email == null && CaseForm.Phone == null)
                {
                    ModelState.AddModelError("CaseForm.Email", "You must supply either an email address or primary phone number");
                    ModelState.AddModelError("CaseForm.Phone", "You must supply either an email address or primary phone number");
                    extraValid = false;
                }
                else if (CaseForm.Phone2 != null && CaseForm.Phone == null)
                {
                    ModelState.AddModelError("CaseForm.Phone", "You should supply a primary phone number before entering a secondary phone number");
                    extraValid = false;
                }

                if (CaseForm.TestDate > DateTime.Now.AddDays(1))
                {
                    ModelState.AddModelError("CaseForm.TestDate", "Test date is too far in the future");
                    extraValid = false;
                }

                if (CaseForm.SymptomDate > DateTime.Now.AddDays(1))
                {
                    ModelState.AddModelError("CaseForm.Phone", "Symptom date is too far in the future");
                    extraValid = false;
                }

                if (extraValid)
                {
                    var lastCase = _CaseService.AssignAndAdd(CaseForm.getCase());
                    return(RedirectToPage("Dashboard", new { lastCaseId = lastCase.CaseID }));
                }
            }
            return(Page());
        }