public async Task <string> TestTemplate(MailTemplateDTO template) { if (template.MailIntent == MailIntent.GlobalTemplate) { return(await TestTemplateCore(template, GetGlobalTemplateData())); } else if (template.MailIntent == MailIntent.RegistrationConfirmed) { return(await TestTemplateCore(template, GetRegistrationConfirmedData())); } else if (template.MailIntent == MailIntent.ExternalInvoiceRequest) { return(await TestTemplateCore(template, GetExternalInvoiceRequestData())); } else if (template.MailIntent == MailIntent.ProformaInvoice) { return(await TestTemplateCore(template, (object)null)); } else if (template.MailIntent == MailIntent.Invoice) { return(await TestTemplateCore(template, (object)null)); } return("Cannot validate template!"); }
private async Task <string> TestTemplateCore <T>(MailTemplateDTO template, T data) { try { return(await TransformBody(template, data)); } catch (Exception ex) { return(ex.ToString()); } }
private async Task LoadItem() { if (ItemId == null) { Item = new MailTemplateDTO(); } else { Item = await client.ApiMailtemplatesByIdGetAsync(ItemId); } }
public async Task SendMail <T>(string to, MailTemplateDTO template, MailTemplateDTO globalTemplate, T data, string[] cc = null, string[] bcc = null, Attachment[] attachments = null) { var body = await templateProcessor.TransformBody(template, data); var globalBody = await templateProcessor.TransformBody(globalTemplate, new GlobalTemplateDataDTO() { Html = body, Subject = template.Subject }); await SendMail(template.FromAddress, to, template.Subject, globalBody, cc, bcc, attachments); }
public async Task <string> TransformBody <T>(MailTemplateDTO template, T data) { var templateKey = GetMd5(template.Body); return(await engine.CompileRenderAsync(templateKey, template.Body, data)); }
public async Task Update(string id, [FromBody] MailTemplateDTO mailTemplateData) { await mailTemplatesFacade.Update(id, mailTemplateData); }
public async Task <string> Test([FromBody] MailTemplateDTO mailTemplateData) { return(await templateProcessor.TestTemplate(mailTemplateData)); }
public async Task <IActionResult> Create([FromBody] MailTemplateDTO mailTemplateData) { await mailTemplatesFacade.Insert(mailTemplateData); return(CreatedAtAction(nameof(Get), new { id = mailTemplateData.Id }, mailTemplateData)); }
/// <returns>Success</returns> /// <exception cref="SwaggerException">A server side error occurred.</exception> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> public async System.Threading.Tasks.Task <string> ApiMailtemplatesTestPostAsync(MailTemplateDTO mailTemplateData, System.Threading.CancellationToken cancellationToken) { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/mailtemplates/test"); var client_ = new System.Net.Http.HttpClient(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(mailTemplateData, _settings.Value)); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); request_.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); PrepareRequest(client_, request_, urlBuilder_); var url_ = urlBuilder_.ToString(); request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); PrepareRequest(client_, request_, url_); var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); try { var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value); foreach (var item_ in response_.Content.Headers) { headers_[item_.Key] = item_.Value; } ProcessResponse(client_, response_); var status_ = ((int)response_.StatusCode).ToString(); if (status_ == "200") { var responseData_ = await response_.Content.ReadAsStringAsync().ConfigureAwait(false); var result_ = default(string); try { result_ = Newtonsoft.Json.JsonConvert.DeserializeObject <string>(responseData_, _settings.Value); return(result_); } catch (System.Exception exception_) { throw new SwaggerException("Could not deserialize the response body.", status_, responseData_, headers_, exception_); } } else if (status_ != "200" && status_ != "204") { var responseData_ = await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new SwaggerException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", status_, responseData_, headers_, null); } return(default(string)); } finally { if (response_ != null) { response_.Dispose(); } } } } finally { if (client_ != null) { client_.Dispose(); } } }
/// <returns>Success</returns> /// <exception cref="SwaggerException">A server side error occurred.</exception> public System.Threading.Tasks.Task <string> ApiMailtemplatesTestPostAsync(MailTemplateDTO mailTemplateData) { return(ApiMailtemplatesTestPostAsync(mailTemplateData, System.Threading.CancellationToken.None)); }
/// <returns>Success</returns> /// <exception cref="SwaggerException">A server side error occurred.</exception> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> public async System.Threading.Tasks.Task ApiMailtemplatesByIdPutAsync(string id, MailTemplateDTO mailTemplateData, System.Threading.CancellationToken cancellationToken) { if (id == null) { throw new System.ArgumentNullException("id"); } var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/mailtemplates/{id}"); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(System.Convert.ToString(id, System.Globalization.CultureInfo.InvariantCulture))); var client_ = new System.Net.Http.HttpClient(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(mailTemplateData, _settings.Value)); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("PUT"); PrepareRequest(client_, request_, urlBuilder_); var url_ = urlBuilder_.ToString(); request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); PrepareRequest(client_, request_, url_); var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); try { var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value); foreach (var item_ in response_.Content.Headers) { headers_[item_.Key] = item_.Value; } ProcessResponse(client_, response_); var status_ = ((int)response_.StatusCode).ToString(); if (status_ == "200") { return; } else if (status_ != "200" && status_ != "204") { var responseData_ = await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new SwaggerException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", status_, responseData_, headers_, null); } } finally { if (response_ != null) { response_.Dispose(); } } } } finally { if (client_ != null) { client_.Dispose(); } } }
/// <returns>Success</returns> /// <exception cref="SwaggerException">A server side error occurred.</exception> public System.Threading.Tasks.Task ApiMailtemplatesByIdPutAsync(string id, MailTemplateDTO mailTemplateData) { return(ApiMailtemplatesByIdPutAsync(id, mailTemplateData, System.Threading.CancellationToken.None)); }