Пример #1
0
 public void CreateComment(Comment comment)
 {
     if(comment == null)
     {
         throw  new ArgumentNullException("comment","comment is null");
     }
     _dbContext.Comments.Add(comment);
 }
Пример #2
0
        /// <summary>
        /// Create a new comment and store it.
        /// </summary>
        /// <param name="value">Value of the comment</param>
        /// <param name="date">Date when the comment was written</param>
        /// <param name="author">Author who wrote the comment</param>
        /// <param name="publication">Publication where the comment belongs</param>
        public void CreateComment(string value, DateTime date, User author, Publication publication)
        {
            if (!ValidContent(value))
                throw new Exception("El contenido no puede estar vacio ni ser mayor a 500 caracteres.");

            if (publication == null)
                throw new Exception("La publicación no es válida.");

            Comment comment = new Comment(date, value, publication, author);

            // Store the new comment
            dataPublications.AddComment(publication, comment);
        }
Пример #3
0
        /// <summary>
        /// Add a comment into the form
        /// </summary>
        /// <param name="c">Comment to add</param>
        private void AddCommentIntoPanel(Comment c)
        {
            // Create the panel object with the publication info inside
            Panel newComment = CreatePanelComment(c.Value, c.Author.CompleteName, c.Date);

            // Insert the publication panel into the flow layout panel in the form
            this.flowLayoutPanel.Controls.Add(newComment);
        }
Пример #4
0
        // *************************** //
        //  COMMENTS related COMMENTS  //
        // *************************** //
        /// <summary>
        /// Create a new comment for a specific publication.
        /// </summary>
        /// <param name="value">Value of the comment</param>
        /// <param name="date">Date when the publication has been written</param>
        /// <param name="publication">Publication that belongs the comment</param>
        /// <param name="author">User who wrote the comment</param>
        public void CreateComment(string value, DateTime date, Publication publication, User author)
        {
            if (!ValidContent(value))
                throw new Exception("El contenido no puede estar vacio ni ser mayor a 500 caracteres.");

            if (author == null)
                throw new Exception("El usuario no pudo ser identificado.");

            if (publication == null)
                throw new Exception("La publicación no pudo ser identificada.");

            Comment c = new Comment(date, value, publication.IdPublication, author.IdUser);

            dataComments.Add(c);
        }
Пример #5
0
        public bool CreateComment(Comment comment)
        {
            var queryString =
                "INSERT INTO [dbo].comments ([dbo].comments.comid, [dbo].comments.createdtime, [dbo].comments.accountid, [dbo].comments.postid, [dbo].comments.name, [dbo].comments.text) " +
                "VALUES (@comid, @createdtime, @accountid, @postid, @name, @text);";

            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                var command = new SqlCommand(queryString, connection);

                command.Parameters.AddWithValue("comid", comment.ComId);
                command.Parameters.AddWithValue("createdtime", comment.CreatedTime);
                command.Parameters.AddWithValue("accountid", comment.AccountId);
                command.Parameters.AddWithValue("postid", comment.PostId);
                command.Parameters.AddWithValue("name", comment.AuthorName);
                command.Parameters.AddWithValue("text", comment.Text);

                try
                {
                    connection.Open();
                    command.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    var stack = e.StackTrace;
                    throw new Exception();
                }

                return true;
            }
        }
Пример #6
0
 private void CopyCommentsProperties(Comment fromComment, Comment toComment)
 {
     if(fromComment == null)
     {
         throw new ArgumentNullException("fromComment");
     }
     if(toComment == null)
     {
         throw new ArgumentNullException("toComment");
     }
     toComment.CreateDate = fromComment.CreateDate;
     toComment.PresentationId = fromComment.PresentationId;
     toComment.Text = fromComment.Text;
     toComment.User.UserId = fromComment.User.UserId;
 }
Пример #7
0
        public void UpdateComment(Comment comment)
        {
            if (comment == null)
            {
                throw new ArgumentNullException("comment","comment is null");
            }

            Comment existComment = _dbContext.Comments.FirstOrDefault(x => x.CommentId == comment.CommentId);
            if(existComment == null)
            {
                throw new InvalidDataException("This comment doesn't exist in current data base");
            }
            if (comment != existComment)
            {
                CopyCommentsProperties(comment, existComment);
            }
            _dbContext.Entry(existComment).State = EntityState.Modified;
        }
Пример #8
0
 public void DeleteComment(Comment comment)
 {
     if(comment == null)
     {
         throw new ArgumentNullException("comment");
     }
     var existComment = _dbContext.Comments.FirstOrDefault(x => x.CommentId == comment.CommentId);
     if(existComment != null)
     {
         _dbContext.Comments.Remove(existComment);
     }
     else
     {
         throw  new InvalidDataException("This comment doesn't exist in current data base");
     }
 }