예제 #1
0
        public int addComment(int firstMessageID, int publisherID, string publisherName, string title, string body)
        {
            if ((title == null) || (title.Equals("")))
            {
                throw new ArgumentException(error_emptyTitle);
            }
            if (!IsValidMessage(title, body))
            {
                throw new ArgumentException(error_wrongWords);
            }
            FirstMessage first = (FirstMessage)findMessage(firstMessageID);

            //checking if firstMessageID exists and really FirstMessage
            if ((first != null) && (first.isFirst()))
            {
                lastMessageID++;
                int             messageId = lastMessageID;
                ResponseMessage rm        = new ResponseMessage(messageId, publisherID, publisherName, title, body);
                first.addResponse(rm);
                messages.Add(rm);
                saveMessageDB();
                return(rm.MessageID);
            }
            throw new InvalidOperationException(error_messageIdNotFound);
        }
예제 #2
0
        public List <CommentInfo> GetAllThreadComments(int firstMessageId)
        {
            List <CommentInfo> ans          = new List <CommentInfo>();
            CommentInfo        cur          = new CommentInfo();
            Message            firstMessage = findMessage(firstMessageId);

            if (firstMessage == null)
            {
                return(null);
            }
            FirstMessage fm = (FirstMessage)firstMessage;

            if (fm.isFirst())
            {
                foreach (ResponseMessage rm in fm.ResponseMessages)
                {
                    cur.Id        = rm.MessageID;
                    cur.topic     = rm.Title;
                    cur.content   = rm.Content;
                    cur.date      = rm.PublishDate;
                    cur.publisher = rm.PublisherName;
                    ans.Add(cur);
                }
            }
            return(ans);
        }