public static ICollection <ProductComment> FromData(ICollection <Interaction> interaction) { List <ProductComment> productComment = new List <ProductComment> (); if (interaction == null) { return(null); } foreach (var item in interaction) { if (item.IsComment != null) { var comment = new ProductComment() { IsComment = item.IsComment, CommentBy = item.CommentUser.Name, CommentDate = item.CommentDate, Content = item.Comment, }; productComment.Add(comment); } } return(productComment); }
public static ProductInteraction FromData(ICollection <Interaction> interaction, int?userId) { var productInteraction = new ProductInteraction() { TotalLike = interaction.Count(x => x.IsLike == true), TotalChat = interaction.Count(x => x.IsChat == true), TotalComment = interaction.Count(x => x.IsComment == true), TotalView = interaction.Count(x => x.IsViewed == true), IsLike = false, Comment = ProductComment.FromData(interaction.Where(x => x.IsComment == true).ToList()), }; if (interaction.FirstOrDefault(x => x.LikedBy == userId) != null) { productInteraction.IsLike = interaction.FirstOrDefault(x => x.LikedBy == userId).IsLike; } return(productInteraction); }