public override async Task <ProductInfoResponse> GetProductInfo(GetProductInfoRequest request, ServerCallContext context) { try { var product = await _productsService.GetProductAsync(request.ProductId); if (product == null) { return(null); } var response = new ProductInfoResponse(); response.Prices.AddRange(product.PriceHistory.Select(x => new PorductPriceHistoryResponse { ProductId = product.Id, Id = x.Id, Date = Timestamp.FromDateTime(x.LastUpdated.ToUniversalTime()), Price = (float)x.Price })); response.ProductInfo = new TrackProductResponse { Description = product.Description, Discount = product.Discount, Id = (int)product.Id, ImageUrl = product.ImageUrl, Price = (float)product.Price, Title = product.Title, Url = product.Href, SellStatus = product.SellStatus, Status = product.Status }; response.ProductInfo.AdditionalPrices.AddRange(product.AdditionalPrices.Select(x => new ProductAdditionalPricesResponse { Description = x.Description, DiscountPrice = (float)x.DiscountPrice, Id = x.Id, LastUpdatedOn = Timestamp.FromDateTime(x.LastUpdated.ToUniversalTime()), ProductId = x.ProductId, Title = x.Title })); return(response); } catch (Exception ex) { _logger.LogError($"An error has occurred when trying to get product info. {ex}"); } return(null); }
public async Task Consume(ConsumeContext <ProductInfoRequest> context) { if (!context.Message.Slugs.HasAny()) { await context.RespondAsync(null); return; } var pis = await _svc.GetProducts(context.Message.Slugs); var productInfoResponse = new ProductInfoResponse { ProductInfos = ((List <Product>)pis).ConvertAll(pi => pi.ToProductInfo()) }; await context.RespondAsync(productInfoResponse); }
private ProductInfoResponse IsR(ProductInfoResponse response, UserModel currentAuthUser, int productId) { if (response == null || currentAuthUser == null) { return(response); } //是否收藏 var favoriteEntity = _favoriteService.Get(currentAuthUser.Id, productId, SourceType.Product); if (favoriteEntity != null) { response.CurrentUserIsFavorited = true; } //是否获取过优惠码 var list = _couponService.Get(currentAuthUser.Id, productId, SourceType.Product); if (list != null && list.Count > 0) { response.CurrentUserIsReceived = true; } return(response); }