public Boolean RemoveTemplate(long templateID)
        {
            using (ISession session = NHSessionHelper.GetSession())
            {
                try
                {
                    session.BeginTransaction();
                    DatabaseContext dc = new lm.Notification.Core.DataLayer.DatabaseContext(session);
                    TemplateMessage t  = session.Get <TemplateMessage>(templateID);

                    if (t != null && t.ID > 0)
                    {
                        session.Delete(t);
                        session.CommitTransaction();
                        return(true);
                    }
                    return(false);
                }
                catch (Exception ex)
                {
                    session.RollbackTransaction();
                    return(false);
                }
            }
        }
        public List <dtoTemplateMessage> AvailableTemplates(int ModuleID, int ActionID, dtoTemplateType tType)
        {
            List <dtoTemplateMessage> templates = null;

            using (ISession session = NHSessionHelper.GetSession())
            {
                DatabaseContext dc = new lm.Notification.Core.DataLayer.DatabaseContext(session);
                try
                {
                    List <TemplateMessage> l = (from TemplateMessage t in dc.Templates
                                                where
                                                (ActionID == -9999 || t.ActionID == ActionID) && t.ModuleID == ModuleID && (int)t.Type == (int)tType
                                                orderby t.LanguageID
                                                select t).ToList <TemplateMessage>();
                    templates = (from TemplateMessage t in l
                                 orderby t.LanguageID
                                 select new dtoTemplateMessage(t)).ToList <dtoTemplateMessage>();
                }
                catch (Exception ex)
                {
                    templates = new List <dtoTemplateMessage>();
                }


                return(templates);
            }
        }
        public List <dtoModule> AvailableModules()
        {
            List <dtoModule> modules = null;

            using (ISession session = NHSessionHelper.GetSession())
            {
                try
                {
                    List <NotificatedModule> n = (from NotificatedModule m in session.Linq <NotificatedModule>()
                                                  orderby m.Name
                                                  select m).ToList <NotificatedModule>();

                    modules = (from NotificatedModule m in n
                               select new dtoModule(m)).ToList <dtoModule>();

                    //modules = (from NotificatedModule m in session.Linq<NotificatedModule>()
                    //           orderby m.Name
                    //           select new dtoModule(m) ).ToList<dtoModule>();
                }
                catch (Exception ex)
                {
                    modules = new List <dtoModule>();
                }
                return(modules);
            }
        }
Beispiel #4
0
        public List <CommunityNews> GetNotifications(List <Guid> notificationsID, int UserLanguageID, int DefaultLanguageID)
        {
            List <CommunityNews> iResponse = new List <CommunityNews>();

            using (ISession session = NHSessionHelper.GetSession())
            {
                try
                {
                    foreach (Guid ID in notificationsID)
                    {
                        NotificationBase notification = (from nb in session.Linq <NotificationBase>()
                                                         where nb.UniqueNotifyID == ID && nb.LanguageID == UserLanguageID
                                                         select nb).FirstOrDefault <NotificationBase>();
                        if (notification.UniqueNotifyID != System.Guid.Empty)
                        {
                            CommunityNews news = new CommunityNews(notification.UniqueNotifyID, notification.CommunityID, notification.SentDate, notification.Day, notification.Message, notification.ModuleID);
                            iResponse.Add(news);
                        }
                    }
                }
                catch (Exception ex)
                {
                    iResponse = new List <CommunityNews>();
                }
            }

            return(iResponse);
        }
Beispiel #5
0
        public List <CommunityNews> GetCommunityNews(bool OnlySummary, DateTime StartDay, int PersonID, int CommunityID, int UserLanguageID, int DefaultLanguageID, int PageSize, int PageIndex)
        {
            List <CommunityNews> iResponse = null;

            using (ISession session = NHSessionHelper.GetSession())
            {
                try
                {
                    IQueryable <PersonNotification> p;
                    p = (from n in session.Linq <PersonNotification>()
                         where n.PersonID == PersonID && n.isDeleted == false && n.Day == StartDay && n.CommunityID == CommunityID
                         orderby n.SentDate descending
                         select n).Skip(PageSize * PageIndex).Take(PageSize);
                    List <PersonNotification>     pp = p.ToList <PersonNotification>();
                    IQueryable <NotificationBase> t;
                    t = (from n in session.Linq <NotificationBase>()
                         where n.CommunityID == CommunityID && n.LanguageID == UserLanguageID && n.Day == StartDay
                         select n);

                    List <NotificationBase> tt = t.ToList <NotificationBase>();
                    iResponse = (from NotificationBase nb in tt
                                 join PersonNotification pn in pp on nb.UniqueNotifyID equals pn.NotificationUniqueID
                                 select new CommunityNews()
                    {
                        CommunityID = CommunityID, Day = StartDay, Message = nb.Message, ModuleID = nb.ModuleID, SentDate = nb.SentDate, UniqueID = nb.UniqueNotifyID
                    }).ToList <CommunityNews>();
                }
                catch (Exception ex)
                {
                    iResponse = new List <CommunityNews>();
                }
            }

            return(iResponse);
        }
Beispiel #6
0
        public List <dtoCommunityWithNews> GetPersonalCommunityWithNews(int PersonID)
        {
            List <dtoCommunityWithNews> reminders = null;

            using (ISession session = NHSessionHelper.GetSession())
            {
                try
                {
                    session.BeginTransaction();
                    List <CommunityNewsSummary> news = (from CommunityNewsSummary r in session.Linq <CommunityNewsSummary>()
                                                        where r.PersonID == PersonID && r.ActionCount > 0
                                                        orderby r.CommunityID
                                                        select r).ToList <CommunityNewsSummary>();

                    reminders = (from CommunityNewsSummary r in news select new dtoCommunityWithNews(r)).ToList <dtoCommunityWithNews>();
                    session.CommitTransaction();
                }
                catch (Exception ex)
                {
                    if (session.isInTransaction())
                    {
                        session.RollbackTransaction();
                    }
                    reminders = new List <dtoCommunityWithNews>();
                }
                return(reminders);
            }
        }
Beispiel #7
0
        public int GetCommunityNewsCount(bool OnlySummary, DateTime StartDay, int PersonID, int CommunityID, int UserLanguageID, int DefaultLanguageID)
        {
            int iResponse = 0;

            using (ISession session = NHSessionHelper.GetSession())
            {
                try
                {
                    iResponse = (from n in session.Linq <PersonNotification>()
                                 where n.PersonID == PersonID && n.isDeleted == false && n.Day == StartDay && n.CommunityID == CommunityID
                                 select n.ID).Count();
                }
                catch (Exception ex)
                {
                }
            }
            return(iResponse);
        }
        public long SaveTemplate(dtoTemplateMessage template)
        {
            using (ISession session = NHSessionHelper.GetSession())
            {
                try
                {
                    session.BeginTransaction();
                    DatabaseContext dc = new lm.Notification.Core.DataLayer.DatabaseContext(session);
                    TemplateMessage t  = session.Get <TemplateMessage>(template.ID);

                    if (t == null || t.ID == 0)
                    {
                        t            = new TemplateMessage();
                        t.ActionID   = template.ActionID;
                        t.LanguageID = template.LanguageID;
                        t.ModuleCode = template.ModuleCode;
                        t.ModuleID   = template.ModuleID;
                        t.Type       = (TemplateType)template.Type;
                    }
                    t.Name    = template.Name;
                    t.Message = template.Message;
                    if (template.Message == "" && t.ID == 0)
                    {
                        return(0);
                    }
                    else if (template.Message == "" && t.ID > 0)
                    {
                        session.Delete(t);
                    }
                    else
                    {
                        session.SaveOrUpdate(t);
                    }
                    session.CommitTransaction();
                    return(t.ID);
                }
                catch (Exception ex)
                {
                    session.RollbackTransaction();
                    return(0);
                }
            }
        }
Beispiel #9
0
        public void UpdateCommunityNewsCount(dtoCommunityWithNews previous)
        {
            CommunityNewsSummary reminder = null;

            using (ISession session = NHSessionHelper.GetSession())
            {
                try
                {
                    session.BeginTransaction();
                    reminder = (from CommunityNewsSummary r in session.Linq <CommunityNewsSummary>()
                                where r.PersonID == previous.PersonID && r.CommunityID == previous.CommunityID
                                orderby r.CommunityID
                                select r).FirstOrDefault <CommunityNewsSummary>();
                    if (reminder != null)
                    {
                        if (previous.LastUpdate == null || previous.LastUpdate == new DateTime())
                        {
                            reminder.ActionCount = 0;
                        }
                        else if (previous.LastUpdate == reminder.LastUpdate)
                        {
                            reminder.ActionCount = 0;
                        }
                        else if (previous.ActionCount < reminder.ActionCount)
                        {
                            reminder.ActionCount = reminder.ActionCount - previous.ActionCount;
                        }
                        reminder.LastUpdate = DateTime.Now;


                        session.SaveOrUpdate(reminder);
                        session.CommitTransaction();
                    }
                }
                catch (Exception ex)
                {
                    if (session.isInTransaction())
                    {
                        session.RollbackTransaction();
                    }
                }
            }
        }
Beispiel #10
0
        public List <dtoCommunityWithNews> GetPersonalCommunityWithNews(int PersonID)
        {
            List <dtoCommunityWithNews> reminders = null;

            using (ISession session = NHSessionHelper.GetSession())
            {
                try
                {
                    reminders = (from CommunityNewsSummary r in session.Linq <CommunityNewsSummary>()
                                 where r.PersonID == PersonID && r.ActionCount > 0
                                 orderby r.CommunityID
                                 select new dtoCommunityWithNews(r)).ToList <dtoCommunityWithNews>();
                }
                catch (Exception ex)
                {
                    reminders = new List <dtoCommunityWithNews>();
                }
                return(reminders);
            }
        }
Beispiel #11
0
        public List <DateTime> GetMonthDaysWithNews(DateTime StartDay, int PersonID, int CommunityID)
        {
            List <DateTime> MonthDays = null;

            using (ISession session = NHSessionHelper.GetSession())
            {
                try
                {
                    DateTime PreviousMonth = StartDay.AddMonths(-1);
                    MonthDays = (from NotificationSummary ns in session.Linq <NotificationSummary>()
                                 where ns.PersonID == PersonID && (CommunityID < 0 || ns.CommunityID == CommunityID) &&
                                 (ns.Day >= PreviousMonth || ns.Day <= StartDay)
                                 orderby ns.Day ascending
                                 select ns.Day).Distinct().ToList <DateTime>();
                }
                catch (Exception ex)
                {
                    MonthDays = new List <DateTime>();
                }
            }

            return(MonthDays);
        }
Beispiel #12
0
        public Boolean RemoveNewsSummary(Guid NotificationID)
        {
            using (ISession session = NHSessionHelper.GetSession())
            {
                try
                {
                    session.BeginTransaction();
                    NotificationSummary nm = session.Get <NotificationSummary>(NotificationID);

                    if (nm != null && nm.ID != System.Guid.Empty)
                    {
                        session.Delete(nm);
                        session.CommitTransaction();
                        return(true);
                    }
                    return(false);
                }
                catch (Exception ex)
                {
                    session.RollbackTransaction();
                    return(false);
                }
            }
        }