Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        public Thread GetFirstMessageThread(FirstMessage fm)
        {
            Thread        trd;
            List <Thread> threads = DBthreadMan.getAll();

            for (int i = 0; i < threads.Count; i++)
            {
                if (threads.ElementAt(i).GetMessage() == fm)
                {
                    trd = threads.ElementAt(i);
                    return(trd);
                }
            }
            return(null);
        }
Ejemplo n.º 4
0
        public bool deleteMessage(int userRequesterId, int messageID)
        {
            Message ms = findMessage(messageID);

            if (ms != null)
            {
                if ((!(ms.publisherID != userRequesterId)) && (!(userRequesterId != 1)))
                {
                    throw new UnauthorizedAccessException("User " + userRequesterId + " has no permissions to delete the message " + messageID);
                }
                // if firstMessage, it should be deleted with all its comments
                if (ms.isFirst())
                {
                    FirstMessage fm = (FirstMessage)ms;
                    HashSet <ResponseMessage> messagesForDeletion = fm.ResponseMessages;
                    while (messagesForDeletion.Count > 0)
                    {
                        ResponseMessage rm = messagesForDeletion.ElementAt(0);
                        fm.removeRespone(rm);
                        messages.Remove(rm);
                    }
                    messages.Remove(fm);
                    //removing firstMessage pointer from its thread
                    Thread trd = GetFirstMessageThread(fm);
                    DBthreadMan.remove(trd);
                }
                // if responseMessage, should delete itself and the pointer from its firstMessage
                else
                {
                    ResponseMessage rm = (ResponseMessage)ms;
                    FirstMessage    fm = GetFirstMessage(rm);
                    fm.removeRespone(rm);
                    messages.Remove(rm);
                }
                saveMessageDB();
                return(true);
            }
            throw new InvalidOperationException(error_messageIdNotFound);
        }
Ejemplo n.º 5
0
 public Thread(int forumId, int subForumId, int messageId, int publisherID, string publisherName, string title, string body)
 {
     this.forumId    = forumId;
     this.subForumId = subForumId;
     firstMessage    = new FirstMessage(messageId, publisherID, publisherName, title, body);
 }
Ejemplo n.º 6
0
 public ResponseMessage(FirstMessage firstMessage, int messageId, int publisherID, string title, string body) :
     base(messageId, publisherID, title, body)
 {
     this.firstMessage = firstMessage;
 }