Exemplo n.º 1
0
        public ActionResult Detail(GetProductInfoRequest request, [FetchRestfulAuthUserAttribute(IsCanMissing = true, KeyName = Define.Token)] UserModel currentAuthUser)
        {
            request.CurrentAuthUser = currentAuthUser;

            return(new RestfulResult {
                Data = this._productDataService.GetProductInfo(request)
            });
        }
        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);
        }
Exemplo n.º 3
0
        public ExecuteResult <ProductInfoResponse> GetProductInfo(GetProductInfoRequest request)
        {
            if (request == null)
            {
                return(new ExecuteResult <ProductInfoResponse>(null)
                {
                    StatusCode = StatusCode.ClientError, Message = "参数错误"
                });
            }


            var entity = _productRepository.GetItem(request.ProductId);

            var r = MappingManager.ProductInfoResponseMapping(entity);


            if (r != null && request.CurrentAuthUser != null)
            {
                r = IsR(r, request.CurrentAuthUser, r.Id);
            }

            return(new ExecuteResult <ProductInfoResponse>(r));
        }