public bool DeleteMessage(int messageID)
        {
            //WatercoolerMsg wcm = new WatercoolerMsg(TSAuthentication.GetLoginUser());
            //wcm.LoadByMessageID(messageID);

            WatercoolerMsgItem wcm = WatercoolerMsg.GetWatercoolerMsgItem(TSAuthentication.GetLoginUser(), messageID);

            if (wcm.OrganizationID != TSAuthentication.OrganizationID)
            {
                return(false);
            }
            if (wcm.UserID != TSAuthentication.UserID && !TSAuthentication.IsSystemAdmin)
            {
                return(false);
            }

            wcm.IsDeleted = true;
            wcm.Collection.Save();

            //wcm[0].Delete();
            //wcm[0].Collection.Save();

            return(true);
        }
        public WatercoolerMsgItemProxy NewComment(string data)
        {
            WatercoolerJsonInfo info = Newtonsoft.Json.JsonConvert.DeserializeObject <WatercoolerJsonInfo>(data);
            WatercoolerMsgItem  wc   = (new WatercoolerMsg(TSAuthentication.GetLoginUser())).AddNewWatercoolerMsgItem();
            int parentmsgid          = info.ParentTicketID;
            int pageType             = info.PageType;
            int pageID = info.PageID;

            wc.UserID         = TSAuthentication.UserID;
            wc.OrganizationID = TSAuthentication.OrganizationID;
            wc.TimeStamp      = DateTime.UtcNow;
            wc.LastModified   = DateTime.UtcNow;
            wc.Message        = info.Description;
            wc.MessageParent  = parentmsgid;

            wc.Collection.Save();

            if (info.ParentTicketID != -1)
            {
                WatercoolerMsg wcm = new WatercoolerMsg(TSAuthentication.GetLoginUser());
                wcm.LoadByMessageID(parentmsgid);

                wcm[0].LastModified = DateTime.UtcNow;
                wcm[0].Collection.Save();
            }

            if (wc.MessageParent == -1 && info.PageType == 0)
            {
                AddAttachment((int)wc.MessageID, info.PageID, WaterCoolerAttachmentType.Ticket);
            }
            foreach (int ticketID in info.Tickets)
            {
                AddAttachment(wc.MessageID, ticketID, WaterCoolerAttachmentType.Ticket);
                if (wc.MessageParent != -1)
                {
                    AddAttachment((int)wc.MessageParent, ticketID, WaterCoolerAttachmentType.Ticket);
                }
            }

            if (wc.MessageParent == -1 && info.PageType == 1)
            {
                AddAttachment((int)wc.MessageID, info.PageID, WaterCoolerAttachmentType.Product);
            }
            foreach (int productID in info.Products)
            {
                AddAttachment(wc.MessageID, productID, WaterCoolerAttachmentType.Product);
                if (wc.MessageParent != -1)
                {
                    AddAttachment((int)wc.MessageParent, productID, WaterCoolerAttachmentType.Product);
                }
            }

            if (wc.MessageParent == -1 && info.PageType == 2)
            {
                AddAttachment((int)wc.MessageID, info.PageID, WaterCoolerAttachmentType.Company);
            }
            foreach (int CompanyID in info.Company)
            {
                AddAttachment(wc.MessageID, CompanyID, WaterCoolerAttachmentType.Company);
                if (wc.MessageParent != -1)
                {
                    AddAttachment((int)wc.MessageParent, CompanyID, WaterCoolerAttachmentType.Company);
                }
            }

            if (wc.MessageParent == -1 && info.PageType == 4)
            {
                AddAttachment((int)wc.MessageID, info.PageID, WaterCoolerAttachmentType.Group);
            }
            foreach (int groupID in info.Groups)
            {
                AddAttachment(wc.MessageID, groupID, WaterCoolerAttachmentType.Group);
                if (wc.MessageParent != -1)
                {
                    AddAttachment((int)wc.MessageParent, groupID, WaterCoolerAttachmentType.Group);
                }
            }

            foreach (int UserID in info.User)
            {
                AddAttachment(wc.MessageID, UserID, WaterCoolerAttachmentType.User);
                if (wc.MessageParent != -1)
                {
                    AddAttachment((int)wc.MessageParent, UserID, WaterCoolerAttachmentType.User);
                }
            }

            foreach (int activityID in info.Activities)
            {
                AddAttachment(wc.MessageID, activityID, WaterCoolerAttachmentType.Activities);
                if (wc.MessageParent != -1)
                {
                    AddAttachment((int)wc.MessageParent, activityID, WaterCoolerAttachmentType.Activities);
                }
            }

            return(wc.GetProxy());
        }