private JsonProductCompare GetJsonProductCompare(int productID, int groupID) { var product = Products.GetDetails(productID); var group = Groups.GetByID(groupID); product.Title = group.Perfix + " " + product.Title; product.Title_En = product.Title_En + " " + group.Perfix_En; var url = UrlProvider.GetProductUrl(productID, group.UrlPerfix, product.UrlPerfix); #region Image File string fileName = ""; var imageInfo = ProductImages.GetDefaultImage(productID); if (imageInfo != null) { fileName = imageInfo.Filename; } var image = UrlProvider.GetProductImage(fileName, StaticValues.ThumbnailProductImageSize); #endregion Image File #region Scores float totalScore = Utilities.CalcRaty(product.SumScore.Value, product.ScoreCount, product.ProductScore); List <ScoresAverage> scoresAverages = ScoreParameterValues.CalculateAverage(productID); #endregion Scores #region Attributes var groups = ProductGroups.GetByProductID(productID).Select(item => item.GroupID).ToList(); var attrbutes = Attributes.GetByGroupIDs(groups); foreach (var item in attrbutes) { item.Value = AttributeValues.GetValue(productID, item.ID); if (item.Value != null) { item.Value = AttributeValues.RenderValue(item); } } #endregion Attributes #region Prices product.Prices = Products.GetProductPrices(product.ID, product.HasVarients, PriceType.Sell); string userID = null; if (User.Identity.IsAuthenticated) { userID = UserID; } Products.SetDiscounts(userID, product.ID, product.HasVarients, product.Prices); #endregion Prices var productItem = new JsonProductCompare { ProductID = productID, DisplayTitleType = product.DisplayTitleType, Title_Fa = product.Title, Title_En = product.Title_En, Url = url, Prices = product.Prices, Image = image, Score = totalScore, PreferentialsCount = product.ScoreCount + 1, Attributes = attrbutes, ScoresAverages = scoresAverages, GroupID = groupID, IsUnavailable = product.IsUnavailable }; return(productItem); }