public static ProductDetailResponse FromData(Product entity, ICollection <Interaction> interaction) { if (entity == null) { return(null); } var response = new ProductDetailResponse() { Id = entity.Id, CompanyName = entity.Company.CompanyName, HoldingName = entity.Holding.HoldingName, ProductName = entity.ProductName, CategoryName = entity.Category.Category, Description = entity.Description, IsIncludePrice = entity.IsIncludePrice, Price = entity.Price, Credentials = entity.Credentials, VideoPath = entity.VideoPath, FotoPath = null, Contact = ProductContact.FromData(entity.User), Interaction = ProductInteraction.FromData(interaction, entity.UserId), }; if (entity.FotoUpload.LastOrDefault() != null) { response.FotoPath = entity.FotoUpload.LastOrDefault().FotoPath; } return(response); }
public static ProductInteraction InteractionMapping(ICollection <Interaction> interaction, int?userId) { var productInteraction = new ProductInteraction(interaction); if (interaction.FirstOrDefault(x => x.LikedBy == userId) != null) { productInteraction.IsLike = interaction.FirstOrDefault(x => x.LikedBy == userId).IsLike; } return(productInteraction); }
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); }