示例#1
0
 internal static Newsletters GetNewsletter(int newsletterId, int clubId)
 {
     using (Vicdude_NewsletterEntities db = new Vicdude_NewsletterEntities())
     {
         return(db.Newsletters.Include("Account").FirstOrDefault(n => n.Id == newsletterId && n.ClubId == clubId && !n.IsDeleted));
     }
 }
示例#2
0
 internal static List <GetNewsletterStatsByNewsletterId_Result> GetNewsletterStatsByNewsletterId(int newsletterId, int clubId)
 {
     using (Vicdude_NewsletterEntities db = new Vicdude_NewsletterEntities())
     {
         return(db.GetNewsletterStatsByNewsletterId(newsletterId, clubId).ToList());
     }
 }
示例#3
0
 internal static List <Newsletter_Send> GetNewslettersToSend()
 {
     using (Vicdude_NewsletterEntities db = new Vicdude_NewsletterEntities())
     {
         return(db.Newsletter_Send.Include("Newsletter_Send_Item").Where(n => n.Newsletter_Send_Item.Any(s => !s.IsSent)).ToList());
     }
 }
示例#4
0
 internal static List <Newsletters> GetNewsletters(int clubId)
 {
     using (Vicdude_NewsletterEntities db = new Vicdude_NewsletterEntities())
     {
         return(db.Newsletters.Include("Account").Where(n => n.ClubId == clubId && !n.IsDeleted).ToList());
     }
 }
示例#5
0
 internal static void ReadNewsletter(string newsletterSendItemGuid)
 {
     using (Vicdude_NewsletterEntities db = new Vicdude_NewsletterEntities())
     {
         var item = db.Newsletter_Send_Item.FirstOrDefault(n => n.NewsletterSendItemGUID == newsletterSendItemGuid);
         item.IsRead   = true;
         item.ReadDate = DateTime.Now;
         db.SaveChanges();
     }
 }
示例#6
0
 internal static void UpdateNewsletterSendItemToSent(int id)
 {
     using (Vicdude_NewsletterEntities db = new Vicdude_NewsletterEntities())
     {
         var item = db.Newsletter_Send_Item.FirstOrDefault(n => n.Id == id);
         item.IsSent   = true;
         item.SendDate = DateTime.Now;
         db.SaveChanges();
     }
 }
示例#7
0
 internal static Newsletter_Send_Item GetNewsletterSendItemByGuid(string guid)
 {
     try
     {
         using (Vicdude_NewsletterEntities db = new Vicdude_NewsletterEntities())
         {
             return(db.Newsletter_Send_Item.FirstOrDefault(n => n.NewsletterSendItemGUID == guid));
         }
     }
     catch (Exception ex)
     {
         LogHelper.LogError(string.Format("Error getting newsletter send item, GUID: {0}", guid), ex, 0);
         return(null);
     }
 }
示例#8
0
 internal static void DeleteNewsletter(Newsletters newsletter)
 {
     try
     {
         using (Vicdude_NewsletterEntities db = new Vicdude_NewsletterEntities())
         {
             newsletter.IsDeleted       = true;
             db.Entry(newsletter).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         LogHelper.LogError(string.Format("Error delete newsletter: {0}", newsletter.Id), ex, 0);
     }
 }
示例#9
0
        internal static void SaveNewsletter(Newsletters newsletter)
        {
            using (Vicdude_NewsletterEntities db = new Vicdude_NewsletterEntities())
            {
                if (newsletter.Id > 0)
                {
                    db.Entry(newsletter).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    newsletter.CreatedDate = DateTime.Now;
                    db.Newsletters.Add(newsletter);
                }

                db.SaveChanges();
            }
        }
示例#10
0
        internal static int CreateNewsletterSend(Newsletters newsletter, AccountSessionEntity accountSession)
        {
            using (Vicdude_NewsletterEntities db = new Vicdude_NewsletterEntities())
            {
                Newsletter_Send newsletterSend = new Newsletter_Send()
                {
                    ClubId             = accountSession.ClubId,
                    UserSendId         = accountSession.AccountId,
                    NewsletterContent  = newsletter.Content,
                    NewsletterId       = newsletter.Id,
                    NewsletterName     = newsletter.Name,
                    NewsletterSendGUID = Guid.NewGuid().ToString(),
                    SendDate           = DateTime.Now
                };

                db.Newsletter_Send.Add(newsletterSend);
                db.SaveChanges();
                return(newsletterSend.Id);
            }
        }
示例#11
0
        internal static void UnsubscribeNewsletterItem(Newsletter_Send_Item newsletterSendItem)
        {
            try
            {
                using (Vicdude_NewsletterEntities db = new Vicdude_NewsletterEntities())
                {
                    var item = db.Newsletter_Send_Item.FirstOrDefault(n => n.NewsletterSendItemGUID == newsletterSendItem.NewsletterSendItemGUID);
                    if (item != null)
                    {
                        item.HasUnsubscribed = true;

                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.LogError(string.Format("Error updating newsletter send item to unsubscribed..."), ex, 0);
            }
        }
示例#12
0
        internal static void CreateNewsletterSendItems(int newsletterSendId, List <int> userIds, List <int> contactIds = null, int formFieldId = -1)
        {
            using (Vicdude_NewsletterEntities db = new Vicdude_NewsletterEntities())
            {
                foreach (int userId in userIds)
                {
                    Newsletter_Send_Item item = new Newsletter_Send_Item()
                    {
                        IsRead                 = false,
                        IsSent                 = false,
                        Email                  = SW.Core.BLL.AccountBLL.GetUserEmail(userId),
                        NewsletterSendId       = newsletterSendId,
                        NewsletterSendItemGUID = Guid.NewGuid().ToString(),
                        SendDate               = DateTime.Now,
                        SendToUserId           = userId,
                        ReadDate               = DateTime.Now.AddYears(-10),
                        HasUnsubscribed        = false,
                        SendType               = "USER"
                    };

                    db.Newsletter_Send_Item.Add(item);
                }

                if (contactIds != null && contactIds.Count > 0)
                {
                    foreach (int contactId in contactIds)
                    {
                        Newsletter_Send_Item item = new Newsletter_Send_Item()
                        {
                            IsRead                 = false,
                            IsSent                 = false,
                            Email                  = SW.Core.BLL.ContactBLL.GetContact(contactId).Email,
                            NewsletterSendId       = newsletterSendId,
                            NewsletterSendItemGUID = Guid.NewGuid().ToString(),
                            SendDate               = DateTime.Now,
                            SendToContactId        = contactId,
                            ReadDate               = DateTime.Now.AddYears(-10),
                            HasUnsubscribed        = false,
                            SendType               = "CONTACT"
                        };

                        db.Newsletter_Send_Item.Add(item);
                    }
                }

                if (formFieldId > 0)
                {
                    List <string> emails = FormsAdminBLL.GetExternalSubmitValues(formFieldId);

                    foreach (var email in emails)
                    {
                        Newsletter_Send_Item item = new Newsletter_Send_Item()
                        {
                            IsRead                 = false,
                            IsSent                 = false,
                            Email                  = email,
                            NewsletterSendId       = newsletterSendId,
                            NewsletterSendItemGUID = Guid.NewGuid().ToString(),
                            SendDate               = DateTime.Now,
                            ReadDate               = DateTime.Now.AddYears(-10),
                            HasUnsubscribed        = false,
                            SendType               = "FORM"
                        };

                        db.Newsletter_Send_Item.Add(item);
                    }
                }

                db.SaveChanges();
            }
        }