public async Task <ActionResult> GetBody_Anteprima(Guid id, TemplateTypeEnum type) { var apiGateway = new ApiGateway(_Token); var result = await apiGateway.Emendamento.GetBody(id, type); return(Json(result, JsonRequestBehavior.AllowGet)); }
public async Task <string> GetBody(Guid id, TemplateTypeEnum template, bool IsDeposito = false) { var result = string.Empty; try { var requestUrl = $"{apiUrl}/emendamenti/template-body"; var model = new GetBodyEmendamentoModel { Id = id, Template = template, IsDeposito = IsDeposito }; var body = JsonConvert.SerializeObject(model); result = await Post(requestUrl, body, _token); var lst = JsonConvert.DeserializeObject <string>(result); return(lst); } catch (UnauthorizedAccessException ex) { Log.Error("GetBodyEM", ex); throw ex; } catch (Exception ex) { Log.Error($"GetBodyEM PARAMS: GUID EM [{id}], TEMPLATE [{template}]"); Log.Error($"GetBodyEM RESULT: [{result}]"); Log.Error("GetBodyEM", ex); throw ex; } }
/// <summary> /// 转换成枚举 /// </summary> public static int TemplateTypeToValue(TemplateTypeEnum enumOption) { try{ return((int)enumOption); }catch (Exception ex) { throw new ArgumentException("enumOption", ex); } }
public IEnumerable <DynamicMethod> GetDynamicMethods(TemplateTypeEnum templateTypeEnum, IEnumerable <DynamicMethod> dynamicMethods) { var result = new List <DynamicMethod>(); foreach (var dynamicMethod in dynamicMethods) { if (dynamicMethod.TemplateTypeEnum.HasFlag(templateTypeEnum)) { result.Add(dynamicMethod); } } return(result); }
public DynamicOperation GetDynamicOperation(TemplateTypeEnum templateTypeEnum, string submitValue, IEnumerable <DynamicMethod> dynamicMethods) { var result = new DynamicOperation(); var matchingSubmitValues = dynamicMethods.Where(x => x.SubmitValue == submitValue).ToList(); matchingSubmitValues = matchingSubmitValues.Where(x => x.TemplateTypeEnum.HasFlag(templateTypeEnum)).ToList(); if (matchingSubmitValues.Count > 1) { throw new Exception("Duplicate dynamic methods found for submit value " + submitValue + " and templatetype " + templateTypeEnum.ToString()); } result.DynamicMethod = matchingSubmitValues.SingleOrDefault(); return(result); }
internal static string GetTemplate(TemplateTypeEnum templateType) { try { string path; switch (templateType) { case TemplateTypeEnum.PDF: path = HttpContext.Current.Server.MapPath("~/templates/template_pdf.html"); break; case TemplateTypeEnum.PDF_COPERTINA: path = HttpContext.Current.Server.MapPath("~/templates/template_pdf_copertina.html"); break; case TemplateTypeEnum.MAIL: path = HttpContext.Current.Server.MapPath("~/templates/template_mail.html"); break; case TemplateTypeEnum.HTML: path = HttpContext.Current.Server.MapPath("~/templates/template_html.html"); break; case TemplateTypeEnum.FIRMA: path = HttpContext.Current.Server.MapPath("~/templates/template_firma.html"); break; case TemplateTypeEnum.HTML_MODIFICABILE: path = HttpContext.Current.Server.MapPath( "~/templates/template_html_testomodificabile.html"); break; default: throw new ArgumentOutOfRangeException(nameof(templateType), templateType, null); } var result = File.ReadAllText(path); return(result); } catch (Exception e) { Log.Error("GetTemplate", e); throw e; } }
public IEnumerable <DynamicMethod> GetDynamicMethods(TemplateTypeEnum templateTypeEnum) { return(_dynamicMethodManager.GetDynamicMethods(templateTypeEnum, DynamicMethods())); }
public DynamicOperation GetDynamicOperation(TemplateTypeEnum templateTypeEnum, string submitValue) { return(_dynamicOperationManager.GetDynamicOperation(templateTypeEnum, submitValue, DynamicMethods())); }
public async Task <ActionResult> GetBody_Anteprima(Guid id, TemplateTypeEnum type) { var result = await ApiGateway.GetBodyEM(id, type); return(Json(result, JsonRequestBehavior.AllowGet)); }
public bool Contains(TemplateTypeEnum templateType, TemplateTypeEnum type) { return(Contains((int)templateType, (int)type)); }
public bool Contains(int templateType, TemplateTypeEnum type) { return(((int)templateType & (int)type) != 0); }
/// <summary> /// Method to trigger mail or message using templates - SS /// </summary> /// <param name="instituteId">instituteId</param> /// <param name="templateType">templateType</param> /// <param name="templateFormat">templateFormat</param> /// <param name="data">data as object</param> /// <param name="password">password, default null</param> public async Task TriggerMailOrMessageAsync(int instituteId, TemplateTypeEnum templateType, TemplateFormatEnum templateFormat, object data, string password = null) { var template = await _iMSDbContext.Templates.FirstOrDefaultAsync(x => x.InstituteId == instituteId && x.TemplateType == templateType && x.TemplateFormat == templateFormat); if (template != null) { var message = GetMailOrMessageBody(template, data, password); var recipients = GetRecipients(template, data, instituteId); if (template.TemplateFormat == TemplateFormatEnum.Email) { var emailConfiguration = await _iMSDbContext.AdministrationEmailConfigurations.Include(s => s.Institute).FirstOrDefaultAsync(x => x.InstituteId == instituteId); if (emailConfiguration != null) { var path = Path.Combine(Directory.GetCurrentDirectory(), "MailTemplates"); var engine = new RazorLightEngineBuilder().UseFilesystemProject(path).UseMemoryCachingProvider().Build(); string resultFromFile = await engine.CompileRenderAsync("Template.cshtml", new TemplateHtmlData() { Data = message }); var bcc = new List <EmailAddress>(); var emailBccs = template.EmailBcc.Split(','); foreach (var emailBcc in emailBccs) { bcc.Add(new EmailAddress() { Address = emailBcc, Name = emailBcc }); } var to = new List <EmailAddress>(); var tos = template.EmailBcc.Split(','); foreach (var emaolTo in tos) { to.Add(new EmailAddress() { Address = emaolTo, Name = emaolTo }); } var email = new EmailMessage() { BccAddresses = bcc, Content = resultFromFile, ToAddresses = to, FromAddresses = new List <EmailAddress>() { new EmailAddress() { Name = emailConfiguration.Institute.Name, Address = emailConfiguration.MailUserName } }, Subject = template.EmailSubject }; _emailService.SendMail(email); } } else { await _smsService.SendSms(recipients, message); } await AddEventReportDetail(template, data, instituteId); } }