//public Comment Comment {get; set;} public static CommentIntrinsicInfoDto Build(Entities.Comment comment) { return(new CommentIntrinsicInfoDto { Content = comment.Content, User = UserBasicEmbeddedInfoDto.Build(comment.User), CreatedAt = comment.CreatedAt, UpdatedAt = comment.UpdatedAt }); }
public void MapCommonConditionSuccessTest() { var comment = new Comment(3, "My test comment", "My test name", "*****@*****.**"); var commentMapper = new CommentMapper(); Entities.Comment result = commentMapper.Map(comment); Assert.AreEqual(3, result.PostId); Assert.AreEqual("My test comment", result.Text); Assert.AreEqual("*****@*****.**", result.CommenterEmail); Assert.AreEqual("My test name", result.CommenterName); }
/// <summary> /// Determines whether <see cref="Entities.Comment"/> is suitable for current criteria /// <para/> /// Was written by current user /// </summary> /// <param name="comment"> /// An instance of <see cref="Entities.Comment"/> to check /// </param> /// <param name="user"> /// A user that has wrote <see cref="Entities.Comment"/> /// </param> /// <returns> /// True if <see cref="Entities.Comment"/> is suitable for current criteria, otherwise — false /// </returns> /// <exception cref="System.ArgumentNullException"> /// Throws when <paramref name="comment"/> or <paramref name="user"/> is null; /// </exception> public static bool Where(Entities.Comment comment, Entities.User user) { if (comment == null) { throw new System.ArgumentNullException(nameof(comment)); } if (user == null) { throw new System.ArgumentNullException(nameof(user)); } return(comment.User == user); }
/// <summary> /// Determines whether <see cref="Entities.Comment"/> is suitable for current criteria /// <para/> /// Has substring in text message /// </summary> /// <param name="comment"> /// An instance of <see cref="Entities.Comment"/> to check /// </param> /// <param name="textSubstring"> /// A subsring in <see cref="Entities.Comment.Text"/> to find /// </param> /// <returns> /// True if <see cref="Entities.Comment"/> is suitable for current criteria, otherwise — false /// </returns> /// <exception cref="System.ArgumentNullException"> /// Throws when <paramref name="comment"/> or <paramref name="textSubstring"/> is null; /// </exception> public static bool Has(Entities.Comment comment, string textSubstring) { if (comment == null) { throw new System.ArgumentNullException(nameof(comment)); } if (textSubstring == null) { throw new System.ArgumentNullException(nameof(textSubstring)); } return(comment.Text.Contains(textSubstring)); }
/// <summary> /// Determines whether <see cref="Entities.Comment"/> is suitable for current criteria /// <para/> /// Was written by current user /// </summary> /// <param name="comment"> /// An instance of <see cref="Entities.Comment"/> to check /// </param> /// <param name="userSubstringName"> /// A user substring nickname /// </param> /// <returns> /// True if <see cref="Entities.Comment"/> is suitable for current criteria, otherwise — false /// </returns> /// <exception cref="System.ArgumentNullException"> /// Throws when <paramref name="comment"/> or <paramref name="userSubstringName"/> is null; /// </exception> public static bool Where(Entities.Comment comment, string userSubstringName) { if (comment == null) { throw new System.ArgumentNullException(nameof(comment)); } if (userSubstringName == null) { throw new System.ArgumentNullException(nameof(userSubstringName)); } return(comment.User.NickName.Contains(userSubstringName)); }
public void PublishComment(int postId, Contracts.BlogComment comment) { // Create Linq2Sql DataContext using (var dbx = CreateContext()) { // Build entity for blog post Entities.Comment postComment = new Entities.Comment() { DateCreated = DateTime.Now, Username = comment.UserName, Comment1 = comment.Comment, PostId = postId }; dbx.Comments.InsertOnSubmit(postComment); // Save changes. dbx.SubmitChanges(); } }
// public Comment Comment {get; set;} public static CommentDetailsDto Build(Entities.Comment comment) { return(new CommentDetailsDto { // ArticleSlug = comment.Article.Slug, // ArticleId = comment.ArticleId, Article = new ArticleIdSlugAndTitle { Id = comment.ArticleId, Title = comment.Article.Title, Slug = comment.Article.Slug, }, Content = comment.Content, User = UserBasicEmbeddedInfoDto.Build(comment.User), IsReply = comment.RepliedComment != null, RepliedCommentId = comment.RepliedCommentId, CreatedAt = comment.CreatedAt, UpdatedAt = comment.UpdatedAt }); }
/// <summary> /// Determines whether <see cref="Entities.Comment"/> is suitable for current criteria /// <para/> /// Is date in range /// </summary> /// <param name="comment"> /// An instance of <see cref="Entities.Comment"/> to check /// </param> /// <param name="from"> /// A minimum value for <see cref="Entities.Comment.Date"/> /// </param> /// <param name="to"> /// A maximum value for <see cref="Entities.Comment.Date"/> /// </param> /// <returns> /// True if <see cref="Entities.Comment"/> is suitable for current criteria, otherwise — false /// </returns> /// <exception cref="System.ArgumentNullException"> /// Throws when <paramref name="comment"/> is null; /// </exception> public static bool Where(Entities.Comment comment, System.DateTime?from, System.DateTime?to) { if (comment == null) { throw new System.ArgumentNullException(nameof(comment)); } bool pass = true; if (from != null) { pass &= comment.Date > from.Value; } if (to != null) { pass &= comment.Date < to.Value; } return(pass); }
public bool AddComment(Entities.Comment comment) { using (SqlConnection con = new SqlConnection(ConnectionString)) { SqlCommand command = new SqlCommand("INSERT INTO dbo.Comments (User_Name, Post_ID, Comment_ID, Text, Time) VALUES (@Author,CAST(@Post_ID AS NVARCHAR(36)), CAST(@Comment_ID AS NVARCHAR(36)), @Text, @Time)", con); command.Parameters.Add(new SqlParameter("@Author", comment.Author)); command.Parameters.Add(new SqlParameter("@Post_ID", comment.Post_ID)); command.Parameters.Add(new SqlParameter("@Comment_ID", comment.ID)); command.Parameters.Add(new SqlParameter("@Text", comment.Text)); command.Parameters.Add(new SqlParameter("@Time", comment.Time)); con.Open(); int num = command.ExecuteNonQuery(); if (num == 1) { logger.Info("DB: Добавлен комментарий: " + comment.ID + " к посту: " + comment.Post_ID); return(true); } else { logger.Error("DB: Ошибка добавления комментария: " + comment.ID + " к посту: " + comment.Post_ID); return(false); } } }
// METHODS /// <summary> /// Gets user like if it exists /// </summary> /// <param name="comment"> /// Rated comment /// </param> /// <param name="user"> /// User that probably sets the like /// </param> /// <returns> /// An instance of <see cref="Entities.CommentLike"/> if user rated comment, otherwise — null /// </returns> public Entities.CommentLike TryGetUserLike(Entities.Comment comment, Entities.User user) { return(context.CommentLike.FirstOrDefault(l => l.Comment.Id == comment.Id && l.User.Id == user.Id)); }
public void InsertComment(Entities.Comment comment) { _repository.InsertComment(comment); }
// CONSTRUCTORS /// <summary> /// Initializes a new instance of <see cref="CommentWrapper"/> /// </summary> /// <param name="comment"> /// An instance of <see cref="Entities.Comment"/> /// </param> public CommentWrapper(Entities.Comment comment) { this.comment = comment; this.likesAmount = comment.Likes.Count(l => l.IsLiked); this.dislikeAmount = comment.Likes.Count - likesAmount; }