public static NewsletterAction GetByID(int NewsletterActionID, IEnumerable <string> includeList = null) { NewsletterAction obj = null; string key = cacheKeyPrefix + NewsletterActionID + GetCacheIncludeText(includeList); NewsletterAction tmpClass = null; if (Cache.IsEnabled) { if (Cache.IsEmptyCacheItem(key)) { return(null); } tmpClass = Cache[key] as NewsletterAction; } if (tmpClass != null) { obj = tmpClass; } else { using (Entities entity = new Entities()) { IQueryable <NewsletterAction> itemQuery = AddIncludes(entity.NewsletterAction, includeList); obj = itemQuery.FirstOrDefault(n => n.NewsletterActionID == NewsletterActionID); } Cache.Store(key, obj); } return(obj); }
public static NewsletterAction CreateOpenAction(Subscriber subscriber, int mailoutID) { var action = new NewsletterAction(); action.SetCommonProperties(subscriber, mailoutID); action.NewsletterActionTypeID = (int)Action.Open; action.Save(); return(action); }
public static NewsletterAction CreateForwardAction(Subscriber subscriber, int mailoutID, string toEmail) { var action = new NewsletterAction(); action.SetCommonProperties(subscriber, mailoutID); action.NewsletterActionTypeID = (int)Action.Forward; action.Details = toEmail; action.Save(); return(action); }
public static NewsletterAction CreateClickAction(Subscriber subscriber, int mailoutID, String url) { var action = new NewsletterAction(); action.SetCommonProperties(subscriber, mailoutID); action.NewsletterActionTypeID = (int)Action.Click; action.Details = url; action.Save(); return(action); }
public NewsletterAction(NewsletterAction objectToCopy) { Details = objectToCopy.Details; Email = objectToCopy.Email; IPAddress = objectToCopy.IPAddress; MailoutID = objectToCopy.MailoutID; NewsletterActionID = objectToCopy.NewsletterActionID; NewsletterActionTypeID = objectToCopy.NewsletterActionTypeID; SubscriberID = objectToCopy.SubscriberID; Timestamp = objectToCopy.Timestamp; }
public static bool ForwardNewsletter(int mailoutID, Guid entityID, string toEmail, string fromEmail, string toName, string fromName) { Mailout mailout = Mailout.GetByID(mailoutID); if (mailout == null) { throw new Exception("The requested mailout does not exist"); } NewsletterSendingTypeFormat sendingFormat = Settings.NewsletterSendingType; SubscriptionType type; switch (sendingFormat) { case NewsletterSendingTypeFormat.HtmlAndText: // when forwarding, we don't ask for a preferred format, so default to HTML case NewsletterSendingTypeFormat.HtmlOnly: type = SubscriptionType.Html; break; case NewsletterSendingTypeFormat.TextOnly: type = SubscriptionType.PlainText; break; case NewsletterSendingTypeFormat.Multipart: type = SubscriptionType.MultiPart; break; default: throw new Exception("Newsletter Format " + sendingFormat + " not defined."); } SubscriberInfo recipient = new SubscriberInfo(toEmail, type); String forwardPreambleText = "This newsletter was forwarded to you by " + fromName + " (" + fromEmail + ")\n"; String forwardPreambleHtml = "<p>" + forwardPreambleText + "</p>"; string body = forwardPreambleHtml + GetNewsletterHtml(mailout, true).Replace("[[EntityID]]", ""); string bodyText = forwardPreambleText + GetNewsletterText(mailout); string subject = "FW: " + mailout.Title; if (SendSingleEmail(recipient, Settings.SenderEmail, subject, body, bodyText)) { Subscriber subscriberEntity = Subscriber.GetSubscriberByEntityID(entityID); if (subscriberEntity != null) { NewsletterAction.CreateForwardAction(subscriberEntity, mailoutID, toEmail); } return(true); } return(false); }
public static List <NewsletterAction> NewsletterActionGetForMetricsPage(int mailoutID, int actionTypeId, int pageNumber, int pageSize, out int totalCount) { List <NewsletterAction> objects; totalCount = 0; string baseKey = cacheKeyPrefix + "GetForMetricsPage_" + mailoutID + "_" + actionTypeId; string key = baseKey + "_" + pageNumber + "_" + pageSize; string countkey = baseKey + "_count"; List <NewsletterAction> tmpList = null; int?tmpInt = null; if (Cache.IsEnabled) { tmpList = Cache[key] as List <NewsletterAction>; tmpInt = Cache[countkey] as int?; } if (tmpList != null && tmpInt.HasValue) { objects = tmpList; totalCount = tmpInt.Value; } else { using (Entities entity = new Entities()) { var baseQuery = from newsletterAction in entity.NewsletterAction where newsletterAction.NewsletterActionTypeID == actionTypeId && newsletterAction.MailoutID == mailoutID group newsletterAction by new { newsletterAction.SubscriberID, newsletterAction.Email, newsletterAction.IPAddress, newsletterAction.Details } into g orderby g.Key.Email select new { NewsletterActionID = g.Min(p => p.NewsletterActionID), NewsletterActionTypeID = g.Min(p => p.NewsletterActionTypeID), MailoutID = g.Min(p => p.MailoutID), SubscriberID = g.Key.SubscriberID, Email = g.Key.Email, Timestamp = g.Min(p => p.Timestamp), IPAddress = g.Key.IPAddress, Details = g.Key.Details }; var tempObjects = pageSize == 0 ? baseQuery.ToList() : baseQuery.Skip(pageSize * (pageNumber - 1)).Take(pageSize).ToList(); totalCount = tmpInt.HasValue ? tmpInt.Value : baseQuery.Count(); objects = new List <NewsletterAction>(); foreach (var temp in tempObjects) { NewsletterAction obj = new NewsletterAction { Details = temp.Details, Email = temp.Email, IPAddress = temp.IPAddress, MailoutID = temp.MailoutID, NewsletterActionID = temp.NewsletterActionID, NewsletterActionTypeID = temp.NewsletterActionTypeID, SubscriberID = temp.SubscriberID, Timestamp = temp.Timestamp }; objects.Add(obj); } } Cache.Store(key, objects); Cache.Store(countkey, totalCount); } return(objects); }