// Email message to database public int Insert(EmailMessageAddRequest model) { int id = 0; DataProvider.ExecuteNonQuery("dbo.EmailMessage_Insert" , inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@ToEmail", model.ToEmail); paramCollection.AddWithValue("@ToName", model.ToName); paramCollection.AddWithValue("@FromEmail", model.FromEmail); paramCollection.AddWithValue("@FromName", model.FromName); paramCollection.AddWithValue("@Subject", model.Subject); paramCollection.AddWithValue("@EmailBody", model.EmailBody); SqlParameter idParameter = new SqlParameter("@Id", System.Data.SqlDbType.Int); idParameter.Direction = System.Data.ParameterDirection.Output; paramCollection.Add(idParameter); }, returnParameters : delegate(SqlParameterCollection param) { Int32.TryParse(param["@Id"].Value.ToString(), out id); }); return(id); }
public HttpResponseMessage Post(EmailMessageAddRequest model) { ItemResponse <int> response = new ItemResponse <int>(); response.Item = _emailService.Insert(model); return(Request.CreateResponse(HttpStatusCode.OK, response)); }
// Contact Page Post public HttpResponseMessage ContactEmail(EmailMessageAddRequest model) { try { _emailService.SendContactEmail(model); return(Request.CreateResponse(HttpStatusCode.OK, new SuccessResponse())); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public async Task SendContactEmail(EmailMessageAddRequest model) { var ToEmail = _configService.getConfigValusAsString("AdminEmail"); var ToName = _configService.getConfigValusAsString("AdminName"); var apiKey = _configService.getConfigValusAsString("SendGridKey"); var client = new SendGridClient(apiKey); var from = new EmailAddress(model.FromEmail, model.FromName); var subject = model.Subject; var plainTextContent = model.EmailBody; var to = new EmailAddress(ToEmail, ToName); var htmlContent = "<h3>(From Contact Us Page On Social Media Grader)</h3>" + plainTextContent; var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent); var response = await client.SendEmailAsync(msg); }
// Contact us email public async Task ContactEmail(EmailMessageAddRequest model) { await SendContactEmail(model); }