public async Task <IActionResult> OnPostBoardEmailAsync(CancellationToken cancellationToken) { if (!ModelState.IsValid) { return(Partial("_SendBoardEmailPartial", this)); } if (EmailProperties.Attachment != null) { //ValidateFile returns a tuple that is deconstructed into separate variables var(FileType, FileExtension) = _fileValidate.GetFileTypeExtension(EmailProperties.Attachment); var result = await _sendEmail.SendBoardEmailMessageAsync(EmailProperties, true, FileType, cancellationToken); if (result != HttpStatusCode.Accepted) { //failed to send an email due to the SendGrid service being down or rejecting the request TempData["Error"] = "An error occured while processing your request. Please try again later."; return(Partial("_SendBoardEmailPartial", this)); } } else { //file was not provided so no need to attach a file var result = await _sendEmail.SendBoardEmailMessageAsync(EmailProperties, false, null, cancellationToken); if (result != HttpStatusCode.Accepted) { //failed to send an email due to the SendGrid service being down or rejecting the request TempData["Error"] = "An error occured while processing your request. Please try again later."; return(Partial("_SendBoardEmailPartial", this)); } } TempData["EmailSent"] = "Your email was sent successfully. We will contact you as soon as possible"; return(Partial("_SendBoardEmailPartial", this)); }