public static void RemoveCache(DNHMessageTemplate objItem) { HttpCache.RemoveByPattern(string.Format(SETTINGS_ALL_KEY, objItem.CompanyID)); HttpCache.RemoveByPattern(string.Format(SETTINGS_ID_KEY, objItem.ID, objItem.CompanyID)); HttpCache.RemoveByPattern(string.Format(SETTINGS_User_KEY, objItem.CreatedUser, objItem.CompanyID)); HttpCache.RemoveSearchCache(SystemConfig.AllowSearchCache, SETTINGS_Search_KEY); }
/// <summary> /// /// </summary> /// <param name="messageTemplate"></param> /// <param name="emailAccount"></param> /// <param name="languageId"></param> /// <param name="tokens"></param> /// <param name="toEmailAddress"></param> /// <param name="toName"></param> /// <param name="attachmentFilePath"></param> /// <param name="attachmentFileName"></param> /// <param name="replyToEmailAddress"></param> /// <param name="replyToName"></param> /// <param name="fromEmail"></param> /// <param name="fromName"></param> /// <param name="subject"></param> /// <returns>Retuern QueuedEmail ID</returns> public static int SendNotification(int CompanyID, DNHMessageTemplate messageTemplate, EmailAccount emailAccount, IEnumerable <Token> tokens, string toEmailAddress, string toName, string attachmentFilePath = null, string attachmentFileName = null, string replyToEmailAddress = null, string replyToName = null, string fromEmail = null, string fromName = null, string subject = null) { if (messageTemplate == null) { throw new ArgumentNullException("messageTemplate"); } if (emailAccount == null) { throw new ArgumentNullException("emailAccount"); } Tokenizer _tokenizer = new Tokenizer(new MessageTemplatesSettings()); //retrieve localized message template data var bcc = messageTemplate.BccEmailAddresses; if (String.IsNullOrEmpty(subject)) { subject = messageTemplate.Subject; } var body = messageTemplate.Body; //Replace subject and body tokens var subjectReplaced = _tokenizer.Replace(subject, tokens, false); var bodyReplaced = _tokenizer.Replace(body, tokens, false); //limit name length toName = CommonHelper.EnsureMaximumLength(toName, 300); var email = new QueuedEmail { CompanyID = CompanyID, Priority = QueuedEmailPriority.High, From = !string.IsNullOrEmpty(fromEmail) ? fromEmail : emailAccount.Email, FromName = !string.IsNullOrEmpty(fromName) ? fromName : emailAccount.DisplayName, To = toEmailAddress, ToName = toName, ReplyTo = replyToEmailAddress, ReplyToName = replyToName, CC = string.Empty, Bcc = bcc, Subject = subjectReplaced, Body = bodyReplaced, AttachmentFilePath = attachmentFilePath, AttachmentFileName = attachmentFileName, AttachedDownloadId = messageTemplate.AttachedDownloadId, CreatedOnUtc = DateTime.UtcNow, CreatedDate = SystemConfig.CurrentDate, ///EmailAccountId = emailAccount.Id, DontSendBeforeDateUtc = !messageTemplate.DelayBeforeSend.HasValue ? null : (DateTime?)(DateTime.UtcNow + TimeSpan.FromHours(messageTemplate.DelayPeriod.ToHours(messageTemplate.DelayBeforeSend.Value))) }; QueuedEmailManager.Add(email); return(email.Id); }
public static int SendFiveDayReminderMessage(string ToEmail, EmpReminderModel objEmp) { MessageTokenProvider _messageTokenProvider = new MessageTokenProvider(); var messageTemplate = GetActiveMessageTemplate(MessageTemplateSystemNames.EmailAFriendMessage, 1); if (messageTemplate == null) { messageTemplate = new DNHMessageTemplate() { Body = "%PM.Employee(s)%", Subject = "TMS-5 Days Reminders" } } ; //email account // var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId); //tokens var tokens = new List <Token>(); _messageTokenProvider.Add5DaysNotWorking(tokens, objEmp); //tokens.Add(new Token("EmailAFriend.Email", customerEmail)); //event notification //_eventPublisher.MessageTokensAdded(messageTemplate, tokens); return(EmailSender.SendNotification(1, messageTemplate, new EmailAccount(), tokens, ToEmail, string.Empty, null, null, null, null, "*****@*****.**", "Contract Manager System")); } #endregion }
public static void Delete(DNHMessageTemplate objItem) { if (objItem != null) { using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue)) { HttpResponseMessage response = client.DeleteAsync(string.Format(Resource + "?id={0}&CompanyID={1}", objItem.ID, objItem.CompanyID)).GetAwaiter().GetResult(); } RemoveCache(objItem); } }
/// <summary> /// Get token groups of message template /// </summary> /// <param name="messageTemplate">Message template</param> /// <returns>Collection of token group names</returns> public static IEnumerable <string> GetTokenGroups(this DNHMessageTemplate messageTemplate) { //groups depend on which tokens are added at the appropriate methods in IWorkflowMessageService switch (messageTemplate.Name) { case MessageTemplateSystemNames.FiveDaysReminderNotification: return(new[] { TokenGroupNames.FiveDaysReminder, TokenGroupNames.CustomerTokens }); default: return(new string[] { }); } }
public static DNHMessageTemplate Update(DNHMessageTemplate objItem) { DNHMessageTemplate item = new DNHMessageTemplate(); using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue)) { HttpResponseMessage response = client.PutAsJsonAsync(string.Format(Resource + "?id={0}", objItem.ID), objItem).GetAwaiter().GetResult(); if (response.IsSuccessStatusCode) { item = response.Content.ReadAsAsync <DNHMessageTemplate>().GetAwaiter().GetResult(); RemoveCache(item); } } return(item); }
public static DNHMessageTemplate Add(DNHMessageTemplate objItem) { DNHMessageTemplate b = new DNHMessageTemplate(); using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue)) { HttpResponseMessage response = client.PostAsJsonAsync(Resource, objItem).GetAwaiter().GetResult(); if (response.IsSuccessStatusCode) { b = response.Content.ReadAsAsync <DNHMessageTemplate>().GetAwaiter().GetResult(); } } RemoveCache(b); return(b); }
/// <summary> /// Get DNH template by Company /// </summary> /// <param name="messageTemplateName"></param> /// <param name="CompanyID"></param> /// <returns></returns> public static DNHMessageTemplate GetMessageTemplateByName(string messageTemplateName, int CompanyID) { string key = String.Format(SETTINGS_ID_KEY, messageTemplateName, CompanyID); object obj2 = HttpCache.Get(key); if (obj2 != null) { return((DNHMessageTemplate)obj2); } DNHMessageTemplate b = new DNHMessageTemplate(); using (var client = WebApiHelper.myclient(HouseEndpoint, SystemConst.APIJosonReturnValue)) { HttpResponseMessage response = client.GetAsync(string.Format(Resource + "?Temp={0}&CompanyID={1}&temp=", messageTemplateName, CompanyID)).GetAwaiter().GetResult(); if (response.IsSuccessStatusCode) { b = response.Content.ReadAsAsync <DNHMessageTemplate>().GetAwaiter().GetResult(); } } HttpCache.Max(key, b); return(b); }