public WaterCoolerThread[] GetMoreThreads(int pageType, int pageID, int msgcount)
        {
            List <WaterCoolerThread> result = new List <WaterCoolerThread>();

            //This reads the WaterCoolerView because it has UserNames and Groups.  This is readonly

            WaterCoolerView wc = new WaterCoolerView(TSAuthentication.GetLoginUser());

            wc.LoadMoreThreads(pageType, pageID, msgcount);

            foreach (WaterCoolerViewItem item in wc)
            {
                WaterCoolerThread thread = new WaterCoolerThread();

                WaterCoolerView replies = new WaterCoolerView(wc.LoginUser);
                replies.LoadReplies(item.MessageID);

                WatercoolerAttachments wcgroups = new WatercoolerAttachments(TSAuthentication.GetLoginUser());
                wcgroups.LoadByType(item.MessageID, WaterCoolerAttachmentType.Group);

                WatercoolerAttachments wctickets = new WatercoolerAttachments(TSAuthentication.GetLoginUser());
                wctickets.LoadByType(item.MessageID, WaterCoolerAttachmentType.Ticket);

                WatercoolerAttachments wcprods = new WatercoolerAttachments(TSAuthentication.GetLoginUser());
                wcprods.LoadByType(item.MessageID, WaterCoolerAttachmentType.Product);

                WatercoolerAttachments wccompany = new WatercoolerAttachments(TSAuthentication.GetLoginUser());
                wccompany.LoadByType(item.MessageID, WaterCoolerAttachmentType.Company);

                WatercoolerAttachments wcuseratt = new WatercoolerAttachments(TSAuthentication.GetLoginUser());
                wcuseratt.LoadByType(item.MessageID, WaterCoolerAttachmentType.User);

                WatercoolerAttachments wcactivitiesatt = new WatercoolerAttachments(TSAuthentication.GetLoginUser());
                wcactivitiesatt.LoadByType(item.MessageID, WaterCoolerAttachmentType.Activities);

                thread.Message    = item.GetProxy();
                thread.Replies    = replies.GetWaterCoolerViewItemProxies();
                thread.Groups     = wcgroups.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Group);
                thread.Tickets    = wctickets.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Ticket);
                thread.Products   = wcprods.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Product);
                thread.Company    = wccompany.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Company);
                thread.User       = wcuseratt.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.User);
                thread.Activities = wcactivitiesatt.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Activities);

                result.Add(thread);
            }

            return(result.ToArray());
        }
        public WaterCoolerThread GetMessage(int messageID)
        {
            WaterCoolerThread thread = new WaterCoolerThread();

            WaterCoolerView wcv = new WaterCoolerView(TSAuthentication.GetLoginUser());

            wcv.LoadByMessageID(messageID);

            WaterCoolerView replies = new WaterCoolerView(TSAuthentication.GetLoginUser());

            replies.LoadReplies(messageID);

            WatercoolerAttachments wcgroups = new WatercoolerAttachments(TSAuthentication.GetLoginUser());

            wcgroups.LoadByType(messageID, WaterCoolerAttachmentType.Group);

            WatercoolerAttachments wctickets = new WatercoolerAttachments(TSAuthentication.GetLoginUser());

            wctickets.LoadByType(messageID, WaterCoolerAttachmentType.Ticket);

            WatercoolerAttachments wcprods = new WatercoolerAttachments(TSAuthentication.GetLoginUser());

            wcprods.LoadByType(messageID, WaterCoolerAttachmentType.Product);

            WatercoolerAttachments wccompany = new WatercoolerAttachments(TSAuthentication.GetLoginUser());

            wccompany.LoadByType(messageID, WaterCoolerAttachmentType.Company);

            WatercoolerAttachments wcuseratt = new WatercoolerAttachments(TSAuthentication.GetLoginUser());

            wcuseratt.LoadByType(messageID, WaterCoolerAttachmentType.User);

            WatercoolerAttachments wcactivitiesatt = new WatercoolerAttachments(TSAuthentication.GetLoginUser());

            wcactivitiesatt.LoadByType(messageID, WaterCoolerAttachmentType.Activities);

            thread.Message    = wcv.GetWaterCoolerViewItemProxies()[0];
            thread.Replies    = replies.GetWaterCoolerViewItemProxies();
            thread.Groups     = wcgroups.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Group);
            thread.Tickets    = wctickets.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Ticket);
            thread.Products   = wcprods.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Product);
            thread.Company    = wccompany.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Company);
            thread.User       = wcuseratt.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.User);
            thread.Activities = wcactivitiesatt.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Activities);

            return(thread);
        }
        public WaterCoolerThread[] GetThreads(int pageType, int pageID, int messageID)
        {
            List <WaterCoolerThread> result = new List <WaterCoolerThread>();

            // Main page [group, user]
            // Ticket page
            // Product page
            // Company page

            WaterCoolerView wc = new WaterCoolerView(TSAuthentication.GetLoginUser());

            if (messageID == -1)
            {
                wc.LoadTop10Threads(pageType, pageID);
            }
            else
            {
                wc.SearchLoadByMessageID(pageType, pageID, messageID);
            }


            foreach (WaterCoolerViewItem item in wc)
            {
                WaterCoolerThread thread = new WaterCoolerThread();

                WaterCoolerView replies = new WaterCoolerView(wc.LoginUser);
                replies.LoadReplies(item.MessageID);

                WatercoolerAttachments threadAttachments = new WatercoolerAttachments(TSAuthentication.GetLoginUser());
                threadAttachments.LoadByMessageID(item.MessageID);

                thread.Message    = item.GetProxy();
                thread.Replies    = replies.GetWaterCoolerViewItemProxies();
                thread.Groups     = threadAttachments.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Group);
                thread.Tickets    = threadAttachments.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Ticket);
                thread.Products   = threadAttachments.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Product);
                thread.Company    = threadAttachments.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Company);
                thread.User       = threadAttachments.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.User);
                thread.Activities = threadAttachments.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Activities);
                result.Add(thread);
            }

            return(result.ToArray());
        }
        public WaterCoolerThread[] GetUpdatedThreads(int msgcount, int pausetime)
        {
            List <WaterCoolerThread> result = new List <WaterCoolerThread>();

            //This reads the WaterCoolerView because it has UserNames and Groups.  This is readonly

            WaterCoolerView wc = new WaterCoolerView(TSAuthentication.GetLoginUser());

            //wc.LoadUpdatedThreads(msgcount, pausetime);


            foreach (WaterCoolerViewItem item in wc)
            {
                WaterCoolerThread thread = new WaterCoolerThread();

                WaterCoolerView replies = new WaterCoolerView(wc.LoginUser);
                replies.LoadReplies(item.MessageID);

                //WatercoolerGroupAtt wcgroups = new WatercoolerGroupAtt(TSAuthentication.GetLoginUser());
                //wcgroups.LoadByMessageID(item.MessageID);
                //WatercoolerTicketAtt wctickets = new WatercoolerTicketAtt(TSAuthentication.GetLoginUser());
                //wctickets.LoadByMessageID(item.MessageID);
                //WatercoolerProductAtt wcprods = new WatercoolerProductAtt(TSAuthentication.GetLoginUser());
                //wcprods.LoadByMessageID(item.MessageID);

                //WatercoolerCompanyAtt wccompany = new WatercoolerCompanyAtt(TSAuthentication.GetLoginUser());
                //wccompany.LoadByMessageID(item.MessageID);

                //WatercoolerUserAtt wcuseratt = new WatercoolerUserAtt(TSAuthentication.GetLoginUser());
                //wcuseratt.LoadByMessageID(item.MessageID);

                thread.Message = item.GetProxy();
                thread.Replies = replies.GetWaterCoolerViewItemProxies();
                //thread.Groups = wcgroups.GetWatercoolerGroupAttItemProxies();
                //thread.Tickets = wctickets.GetWatercoolerTicketAttItemProxies();
                //thread.Products = wcprods.GetWatercoolerProductAttItemProxies();
                //thread.Company = wccompany.GetWatercoolerCompanyAttItemProxies();
                //thread.User = wcuseratt.GetWatercoolerUserAttItemProxies();
                result.Add(thread);
            }

            return(result.ToArray());
        }
        public void NewThread(int messageID, string organizationID)
        {
            LoginUser loginUser = new LoginUser(connString, -1, -1, null);

            try
            {
                loginUser = new LoginUser(connString, TSAuthentication.GetLoginUser().UserID, TSAuthentication.GetLoginUser().OrganizationID, null);
                WaterCoolerThread thread = new WaterCoolerThread();

                WaterCoolerView wcv = new WaterCoolerView(loginUser);
                wcv.LoadByMessageID(messageID);

                WaterCoolerView replies = new WaterCoolerView(loginUser);
                replies.LoadReplies(messageID);

                WatercoolerAttachments wcgroups = new WatercoolerAttachments(loginUser);
                wcgroups.LoadByType(messageID, WaterCoolerAttachmentType.Group);

                WatercoolerAttachments wctickets = new WatercoolerAttachments(loginUser);
                wctickets.LoadByType(messageID, WaterCoolerAttachmentType.Ticket);

                WatercoolerAttachments wcprods = new WatercoolerAttachments(loginUser);
                wcprods.LoadByType(messageID, WaterCoolerAttachmentType.Product);

                WatercoolerAttachments wccompany = new WatercoolerAttachments(loginUser);
                wccompany.LoadByType(messageID, WaterCoolerAttachmentType.Company);

                WatercoolerAttachments wcuseratt = new WatercoolerAttachments(loginUser);
                wcuseratt.LoadByType(messageID, WaterCoolerAttachmentType.User);

                WatercoolerAttachments wcactivitiesatt = new WatercoolerAttachments(loginUser);
                wcactivitiesatt.LoadByType(messageID, WaterCoolerAttachmentType.Activities);

                thread.Message    = wcv.GetWaterCoolerViewItemProxies()[0];
                thread.Replies    = replies.GetWaterCoolerViewItemProxies();
                thread.Groups     = wcgroups.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Group);
                thread.Tickets    = wctickets.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Ticket);
                thread.Products   = wcprods.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Product);
                thread.Company    = wccompany.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Company);
                thread.User       = wcuseratt.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.User);
                thread.Activities = wcactivitiesatt.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Activities);

                //If this is a new thread
                if (thread.Message.MessageParent == -1)
                {
                    var result = pusher.Trigger("ticket-dispatch-" + organizationID, "addThread", thread);
                    //return JsonConvert.SerializeObject(true);
                    //Clients.Group().addThread(thread);
                }
                else
                {
                    var result = pusher.Trigger("ticket-dispatch-" + organizationID, "addComment", thread);
                    //Clients.Group(organizationID).addComment(thread);
                    int parentThreadID = (int)thread.Message.MessageParent;

                    WaterCoolerThread parentThread    = new WaterCoolerThread();
                    WaterCoolerView   parentThreadwcv = new WaterCoolerView(loginUser);
                    parentThreadwcv.LoadByMessageID(parentThreadID);

                    WatercoolerAttachments parentThreadwcgroups = new WatercoolerAttachments(loginUser);
                    parentThreadwcgroups.LoadByType(parentThreadID, WaterCoolerAttachmentType.Group);

                    WatercoolerAttachments parentThreadwctickets = new WatercoolerAttachments(loginUser);
                    parentThreadwctickets.LoadByType(parentThreadID, WaterCoolerAttachmentType.Ticket);

                    WatercoolerAttachments parentThreadwcprods = new WatercoolerAttachments(loginUser);
                    parentThreadwcprods.LoadByType(parentThreadID, WaterCoolerAttachmentType.Product);

                    WatercoolerAttachments parentThreadwccompany = new WatercoolerAttachments(loginUser);
                    parentThreadwccompany.LoadByType(parentThreadID, WaterCoolerAttachmentType.Company);

                    WatercoolerAttachments parentThreadwcuseratt = new WatercoolerAttachments(loginUser);
                    parentThreadwcuseratt.LoadByType(parentThreadID, WaterCoolerAttachmentType.User);

                    WatercoolerAttachments parentThreadactivitiesatt = new WatercoolerAttachments(TSAuthentication.GetLoginUser());
                    parentThreadactivitiesatt.LoadByType(parentThreadID, WaterCoolerAttachmentType.Activities);

                    parentThread.Message    = parentThreadwcv.GetWaterCoolerViewItemProxies()[0];
                    parentThread.Groups     = parentThreadwcgroups.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Group);
                    parentThread.Tickets    = parentThreadwctickets.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Ticket);
                    parentThread.Products   = parentThreadwcprods.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Product);
                    parentThread.Company    = parentThreadwccompany.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Company);
                    parentThread.User       = parentThreadwcuseratt.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.User);
                    parentThread.Activities = parentThreadactivitiesatt.GetWatercoolerAttachmentProxies(WaterCoolerAttachmentType.Activities);

                    result = pusher.Trigger("ticket-dispatch-" + organizationID, "updateattachments", parentThread);
                    //Clients.Group(organizationID).updateattachments(parentThread);
                }
            }
            catch (Exception ex)
            {
                ExceptionLogs.LogException(loginUser, ex, "Socket.NewThread");
            }
        }