public async Task <IActionResult> Submit([FromBody] Contact contact) { try { if (contact != null) { var userName = HttpContext.User.Identity.Name; contact.CreatedBy = _userProvider.GetUser(userName); contact.CreatedOn = DateTime.Now; var result = _contactProvider.submitData(contact); System.Collections.Generic.ICollection <Property> pageModuleProperties = GetModuleProperties(contact.PageModuleId); string adminEmail = pageModuleProperties.Get("cf_admin_email")?.ToString(); string fromEmail = pageModuleProperties.Get("from")?.ToString(); string subject = pageModuleProperties.Get("subject")?.ToString(); string adminEmailTemplate = pageModuleProperties.Get("cf_admin_email_template")?.ToString(); string contactEmailTemplate = pageModuleProperties.Get("cf_contact_email_template")?.ToString(); dynamic data = JObject.Parse(contact.Data); //Send Email to Admin string message = ViewExtensions.RenderPartial($"{_modulePath}/EmailTemplates/{adminEmailTemplate}.cshtml", data, HttpContext); await _emailsender.SendEmailAsync(adminEmail, subject, message, fromEmail); //Send Email to Contact message = ViewExtensions.RenderPartial($"{_modulePath}/EmailTemplates/{contactEmailTemplate}.cshtml", data, HttpContext); await _emailsender.SendEmailAsync(data.Email, subject, message, fromEmail); if (result) { return(Ok()); } } return(NotFound()); } catch (Exception ex) { _logger.LogError(string.Format("Error occured while posting the message."), ex); return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } }