예제 #1
0
        // [END vision_product_search_list_products]

        // [START vision_product_search_get_product]
        private static int GetProduct(GetProductOptions opts)
        {
            var client  = ProductSearchClient.Create();
            var request = new GetProductRequest
            {
                // Get the full path of the product.
                ProductName = new ProductName(opts.ProjectID,
                                              opts.ComputeRegion,
                                              opts.ProductID)
            };

            var product = client.GetProduct(request);

            var productId = product.Name.Split("/").Last();

            Console.WriteLine($"\nProduct name: {product.Name}");
            Console.WriteLine($"Product id: {productId}");
            Console.WriteLine($"Product display name: {product.DisplayName}");
            Console.WriteLine($"Product category: {product.ProductCategory}");
            Console.WriteLine($"Product labels:");
            foreach (var label in product.ProductLabels)
            {
                Console.WriteLine($"\tLabel: {label.ToString()}");
            }
            return(0);
        }
예제 #2
0
 public async Task <IEnumerable <GetProductResponse> > GetProductList(GetProductRequest request)
 {
     return(await context.Product.Where(prod => (request.ProductId == 0)?true : prod.ProductId == request.ProductId)
            .Select(prod => new GetProductResponse()
     {
         ProductId = prod.ProductId,
         Class = prod.Class,
         Color = prod.Color,
         DaysToManufacture = prod.DaysToManufacture,
         DiscontinuedDate = prod.DiscontinuedDate,
         FinishedGoodFlag = prod.FinishedGoodsFlag,
         FlagBit = prod.MakeFlag,
         ListPrice = prod.ListPrice,
         ModifiedDate = prod.ModifiedDate,
         Name = prod.Name,
         ProductLine = prod.ProductLine,
         ProductNumber = prod.ProductNumber,
         ReorderPoint = prod.ReorderPoint,
         SafetyStockLevel = prod.SafetyStockLevel,
         SaleEndDate = prod.SellEndDate,
         SaleStartDate = prod.SellStartDate,
         Size = prod.Size,
         StandardCost = prod.StandardCost,
         Style = prod.Style,
         Weight = prod.Weight
     }).ToListAsync());
 }
        public JsonResult Update(ProductDetailView vm)
        {
            GetProductRequest request = new GetProductRequest();

            request.ProductID = vm.ProductID;

            ModifyProductRequest updateRequest = _productService.GetProduct(request).Product.ConvertToModifyProductRequest();

            updateRequest.ProductID   = vm.ProductID;
            updateRequest.ProductName = vm.ProductName;
            GetSupplierRequest supplierRequest = new GetSupplierRequest();

            supplierRequest.SupplierID = vm.SupplierSupplierID;
            updateRequest.Supplier     = _supplierService.GetSupplier(supplierRequest).Supplier;
            GetCategoryRequest categoryRequest = new GetCategoryRequest();

            categoryRequest.CategoryID    = vm.CategoryCategoryID;
            updateRequest.Category        = _categoryService.GetCategory(categoryRequest).Category;
            updateRequest.QuantityPerUnit = vm.QuantityPerUnit;
            updateRequest.UnitPrice       = vm.UnitPrice;
            updateRequest.UnitsInStock    = vm.UnitsInStock;
            updateRequest.UnitsOnOrder    = vm.UnitsOnOrder;
            updateRequest.ReorderLevel    = vm.ReorderLevel;
            updateRequest.Discontinued    = vm.Discontinued;

            ModifyProductResponse response = _productService.ModifyProduct(updateRequest);

            return(Json(response));
        }
예제 #4
0
        public Task <GetProductResponse> GetProduct(GetProductRequest request)
        {
            return(Task.Factory.StartNew(() =>
            {
                Debug.WriteLine("Quering DB. Current thread is " + System.Threading.Thread.CurrentThread.ManagedThreadId);
                using (var context = new MercuryDbConnection())
                {
                    var query = context.Product
                                .Where(p => p.ID == request.ProductId)
                                .Select(p => new ProductInfo
                    {
                        ModifyDate = p.ModifyDate,
                        Model = p.Model,
                        Id = p.ID,
                        Color = p.Color,
                        Name = p.Name,
                        BestSellers = p.BestSeller,
                        Material = p.Material,
                        Collection = p.Collection,
                        Comment = p.Comment,
                        CreateDate = p.CreateDate,
                        Private = p.Private,
                        RowVersion = p.RowVersion,
                        SellDate = p.SellDate,
                        VIP = p.VIP,
                    });

                    return new GetProductResponse {
                        Product = query.FirstOrDefault()
                    };
                }
            }, token, TaskCreationOptions.LongRunning, TaskScheduler.Default));
        }
예제 #5
0
        /// <inheritdoc/>
        public override async Task <GetProductResponse> GetProduct(GetProductRequest request, ServerCallContext context)
        {
            Inventory.Product product;

            if (request.SquareId != null)
            {
                product = await this.productService.GetProductBySquareIdAsync(request.SquareId);
            }
            else if (request.ProductCode != null)
            {
                product = await this.productService.GetProductByProductCodeAsync(request.ProductCode);
            }
            else if (request.ProductName != null)
            {
                product = await this.productService.GetProductByNameAsync(request.ProductName);
            }
            else
            {
                throw new ArgumentException("Cannot search for the given request.");
            }

            return(new GetProductResponse
            {
                Product = this.mapper.Map <Product>(product),
            });
        }
예제 #6
0
        public override Task <ActivityResponse> GetActivity(GetProductRequest request, Grpc.Core.ServerCallContext context)
        {
            this.logger.LogInformation($"Received query for product activity for SKU {request.SKU}");
            var response = new ActivityResponse();

            try
            {
                var activities = this.repository.GetActivity(request.SKU);
                foreach (var activity in activities)
                {
                    response.Activities.Add(new Activity
                    {
                        SKU          = activity.SKU,
                        ActivityID   = activity.ActivityId,
                        Timestamp    = (ulong)activity.CreatedOn,
                        OrderID      = activity.OrderId,
                        Quantity     = (uint)activity.Quantity,
                        ActivityType = ToProtoActivityType(activity.ActivityType)
                    });
                }
                return(Task.FromResult(response));
            }
            catch (Exception ex)
            {
                this.logger.LogError(ex, "Failed to retrieve activity for SKU : {}", request.SKU);
                return((Task <ActivityResponse>)Task.FromException(ex));
            }
        }
예제 #7
0
        public async Task TestGetProduct_ElastiCache_SingleSkuFromOffer()
        {
            // ARRANGE
            string sku = "HBRQZSXXSY2DXJ77";

            PriceListClient client = new PriceListClient();

            GetProductRequest request = new GetProductRequest("AmazonElastiCache")
            {
                Format = Format.JSON
            };

            GetProductResponse response = await client.GetProductAsync(request);

            ProductOffer ecOffer = response.ProductOffer;

            // ACT

            IEnumerable <IGrouping <string, PricingTerm> > groupedTerms = ecOffer.Terms
                                                                          .SelectMany(x => x.Value) // Get all of the product item dictionaries from on demand and reserved
                                                                                                    //.Where(x => ApplicableProductSkus.Contains(x.Key)) // Only get the pricing terms for products we care about
                                                                          .SelectMany(x => x.Value) // Get all of the pricing term key value pairs
                                                                          .Select(x => x.Value)     // Get just the pricing terms
                                                                          .GroupBy(x => x.Sku);     // Put all of the same skus together

            IGrouping <string, PricingTerm> skuTerms = groupedTerms.First(x => x.Key.Equals(sku));

            // ASSERT
            Assert.True(skuTerms.Where(x => x.TermAttributes.PurchaseOption == PurchaseOption.ON_DEMAND).Count() == 1);
        }
 public void GettingProducts(GetProductRequest getProductRequest)
 {
     productOutput.GotProducts(new GetProductResponse
     {
         Products = productGateway.GetProducts()
     });
 }
        public async Task <List <Products> > GetProducts(GetProductRequest filter)
        {
            var query  = GetProductQuery(filter);
            var result = await query.ToListAsync();

            return(result);
        }
예제 #10
0
        public async Task <BaseResponseDto <ProductDto> > Handle(GetProductRequest request, CancellationToken cancellationToken)
        {
            BaseResponseDto <ProductDto> response = new BaseResponseDto <ProductDto>();

            try
            {
                ProductDto product = (await _repository.GetWhereAsync(p => p.ProductCode == request.productCode)).Select(p => new ProductDto
                {
                    ProductCode = p.ProductCode,
                    Price       = p.Price,
                    Stock       = p.Stock
                }).FirstOrDefault();

                BaseResponseDto <CampaignDto> getCampaignReponse = await _mediator.Send(new GetCampaignByProductCodeRequest(productCode : product.ProductCode));

                if (getCampaignReponse != null)
                {
                    if (getCampaignReponse.Data != null)
                    {
                        product.Price = product.Price - (product.Price * (getCampaignReponse.Data.Limit / 100M));
                    }
                }
                response.Data = product;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                response.Errors.Add("An error occurred while getting product.");
            }

            return(response);
        }
예제 #11
0
        public override async Task <GetProductResponse> GetProduct(GetProductRequest request, ServerCallContext context)
        {
            var productId = request.ProductId;

            if (productId == null)
            {
                throw new RpcException(new Status(StatusCode.InvalidArgument, "Invalid product id to GetProduct"));
            }

            var result = _ProductsDataStore.FirstOrDefault(predicate => predicate.Id == productId);

            if (result == null)
            {
                throw new RpcException(new Status(StatusCode.NotFound, $"The Product id {productId} wasn't found"));
            }

            Product.Product Product = new Product.Product()
            {
                Id          = result.Id,
                Name        = result.Name,
                Description = result.Description
            };
            return(await Task.FromResult(new GetProductResponse()
            {
                Product = Product
            }));
        }
예제 #12
0
            public static GetProductResponse GetProductToCellarArea(GetProductRequest request)
            {
                GetProductResponse response = new GetProductResponse();

                response.Error       = new Handler.ErrorObject();
                response.ProductList = new List <Products>();

                try
                {
                    var bussines = ProductData.Select.GetProductToCellarArea(request.CellarAreaID);
                    if (!bussines.Item1.Error)
                    {
                        foreach (var item in bussines.Item2)
                        {
                            response.ProductList.Add(new Products()
                            {
                                id   = item.id,
                                name = item.name
                            });
                        }
                    }
                    else
                    {
                        response.Error.InfoError(bussines.Item1);
                    }
                }
                catch (Exception ex)
                {
                    response.Error.InfoError(ex);
                }

                return(response);
            }
예제 #13
0
        public ProductModelResponse GetRandomProducts(GetProductRequest request)
        {
            ProductModelResponse response = new ProductModelResponse();

            try
            {
                int        count   = _repositoryProduct.Get(t => t.CategoryID == request.CategoryID).Count();
                List <int> randoms = new List <int>();
                for (int i = 0; i < request.Range; i++)
                {
                    randoms.Add(RandomGenerator(count, randoms));
                }
                for (int i = 0; i < request.Range; i++)
                {
                    Product product = _repositoryProduct.Get(t => t.CategoryID == request.CategoryID).OrderBy(t => t.ID).Skip(randoms[i]).Take(1).SingleOrDefault();
                    response.Products.Add(new ProductModel
                    {
                        ID            = product.ID,
                        Description   = product.Description,
                        Price         = product.Price,
                        ProductImages = product.ProductImages.Select(t => t.URLFromAway).ToList(),
                        ProductName   = product.ProductName,
                        Brand         = product.BrandID
                    });
                }

                response.SetStatus(Constants.ResponseCode.SUCCESS);
                return(response);
            }
            catch (Exception)
            {
                response.SetStatus(Constants.ResponseCode.FAILED_ON_DB_PROCESS);
                return(response);
            }
        }
예제 #14
0
        public ActionResult <GetProductResponse> GetProduct(long id)
        {
            var getProductRequest = new GetProductRequest();

            getProductRequest.Id = id;
            return(productService.GetProduct(getProductRequest));
        }
        public async Task <IActionResult> GetProduct([FromRoute] GetProductRequest request)
        {
            this.logger.LogDebug($"Incoming request to get product with id '{request.Id}'");

            return(await this.productActorRef.Ask <ProductActor.IResponse>(
                       new ProductActor.GetProductById {
                Id = request.Id !.Value
            }) switch
예제 #16
0
        private async Task <IEnumerable <ProductResponse> > GetProducts(GetProductRequest filter)
        {
            var products = await _productRepository.GetProducts(filter);

            var result = products.Map <Products, ProductResponse>();

            return(result);
        }
예제 #17
0
        public async Task <GetProductResponse> Handle(GetProductRequest message)
        {
            var product = await _productRepository.Get(message.Id);

            return(new GetProductResponse {
                Product = product
            });
        }
예제 #18
0
 public Task <IActionResult> Get([FromBody] GetProductRequest request, string Customer = "")
 {
     if (Customer.ToLower() != request.Customer.ToLower())
     {
         BadRequest(request);
     }
     return(ExceptionRespons(() => mediator.Send(request)));
 }
예제 #19
0
        public GetProductResponse GetProduct(GetProductRequest request)
        {
            GetProductResponse response = new GetProductResponse();

            response.Product = _mapper.Map <ProductTitle, ProductView>(FindAllProductTitles().FirstOrDefault(p => p.Id == request.ProductId));

            return(response);
        }
예제 #20
0
        public async Task <IActionResult> GetProduct(GetProductRequest request)
        {
            var response = await _getProductHandler.HandleAsync(request);

            var result = MakeActionResult(response);

            return(result);
        }
예제 #21
0
        public GetProductResponse GetProduct(GetProductRequest request)
        {
            var response = new GetProductResponse();

            response.Product = _productTitleRepository.FindBy(request.ProductId).ToProductView();

            return(response);
        }
예제 #22
0
        public GetProductResponse GetProduct(GetProductRequest request)
        {
            GetProductResponse response = new GetProductResponse();

            response.Product = FindAllProductTitles().Where(p => p.Id == request.ProductId).FirstOrDefault();

            return(response);
        }
예제 #23
0
        public ActionResult <GetProductResponse> GetProduct(long id)
        {
            var request = new GetProductRequest {
                Id = id
            };
            var response = _service.GetProduct(request);

            return(response);
        }
        //public async Task<Target> CreateTarget(string displayName, string description, IReadOnlyDictionary<string, string> labels, byte[] referenceImageBinaries)
        //{
        //    GoogleCredential cred = this.CreateCredentials();
        //    var channel = new Channel(ProductSearchClient.DefaultEndpoint.Host, ProductSearchClient.DefaultEndpoint.Port, cred.ToChannelCredentials());

        //    try
        //    {
        //        var client = ProductSearchClient.Create(channel);
        //        var storage = await StorageClient.CreateAsync(cred);

        //        string productId = Guid.NewGuid().ToString();
        //        var createProductOptions = new CreateProductOptions
        //        {
        //            ProjectID = this.options.Value.ProjectId,
        //            ComputeRegion = this.options.Value.LocationId,
        //            ProductID = productId,
        //            ProductCategory = "apparel",
        //            DisplayName = displayName,
        //            Description = description,
        //            ProductLabels = labels,
        //        };
        //        Product product = await this.CreateProduct(client, createProductOptions);

        //        var addProductOptions = new AddProductToProductSetOptions
        //        {
        //            ProjectID = this.options.Value.ProjectId,
        //            ComputeRegion = this.options.Value.LocationId,
        //            ProductID = product.ProductName.ProductId,
        //            ProductSetId = this.options.Value.ProductSetId,
        //        };
        //        await this.AddProductToProductSet(client, addProductOptions);

        //        string referenceImageId = Guid.NewGuid().ToString();
        //        await this.UploadFile(storage, this.options.Value.StorageBucketName, referenceImageId, referenceImageBinaries);

        //        var createReferenceImageOptions = new CreateReferenceImageOptions
        //        {
        //            ProjectID = this.options.Value.ProjectId,
        //            ComputeRegion = this.options.Value.LocationId,
        //            ProductID = product.ProductName.ProductId,
        //            ReferenceImageID = referenceImageId,
        //            ReferenceImageURI = $"gs://{this.options.Value.StorageBucketName}/{referenceImageId}",
        //        };
        //        Google.Cloud.Vision.V1.ReferenceImage referenceImage = await this.CreateReferenceImage(client, createReferenceImageOptions);

        //        Target target = this.mapper.Map<Target>(product);
        //        target.ReferenceImages = new ReferenceImage[] { this.mapper.Map<ReferenceImage>(referenceImage) };

        //        return target;
        //    }
        //    finally
        //    {
        //        await channel.ShutdownAsync();
        //    }
        //}

        //public async Task DeleteTarget(string targetSetId, string targetId)
        //{
        //    GoogleCredential cred = this.CreateCredentials();
        //    var channel = new Channel(ProductSearchClient.DefaultEndpoint.Host, ProductSearchClient.DefaultEndpoint.Port, cred.ToChannelCredentials());

        //    try
        //    {
        //        var client = ProductSearchClient.Create(channel);
        //        var storage = await StorageClient.CreateAsync(cred);

        //        IEnumerable<Google.Cloud.Vision.V1.ReferenceImage> referenceImages = await this.GetReferenceImages(client, targetId, 100);
        //        await Task.WhenAll(referenceImages.Select(async r =>
        //        {
        //            await this.DeleteReferenceImage(client, targetId, r.ReferenceImageName.ReferenceImageId);
        //            await this.DeleteFile(storage, this.options.Value.StorageBucketName, r.ReferenceImageName.ReferenceImageId);
        //        }));

        //        await this.RemoveProductFromProductSet(client, targetSetId, targetId);
        //        await this.DeleteProduct(client, targetId);

        //    }
        //    finally
        //    {
        //        await channel.ShutdownAsync();
        //    }
        //}

        //public async Task<TargetSearchResults> QuerySimilarTargets(byte[] image)
        //{
        //    GoogleCredential cred = this.CreateCredentials();
        //    var channel = new Channel(ProductSearchClient.DefaultEndpoint.Host, ProductSearchClient.DefaultEndpoint.Port, cred.ToChannelCredentials());

        //    try
        //    {
        //        var imageAnnotatorClient = ImageAnnotatorClient.Create(channel);

        //        var options = new GetSimilarProductsOptions
        //        {
        //            ProjectID = this.options.Value.ProjectId,
        //            ComputeRegion = this.options.Value.LocationId,
        //            ProductSetId = this.options.Value.ProductSetId,
        //            ProductCategory = "apparel",
        //            Filter = string.Empty,
        //            ImageBinaries = image,
        //        };

        //        return await this.GetSimilarProductsFile(imageAnnotatorClient, options);
        //    }
        //    catch (AnnotateImageException e)
        //    {
        //        this.logger.LogError(e, "The google cloud image recognition service threw an error.");
        //        return new TargetSearchResults
        //        {
        //            Results = new TargetSearchResultEntry[0],
        //        };
        //    }
        //    finally
        //    {
        //        await channel.ShutdownAsync();
        //    }
        //}

        //private async Task<ProductSet> CreateProductSet(ProductSearchClient client, CreateProductSetsOptions opts)
        //{
        //    // Create a product set with the product set specification in the region.
        //    var request = new CreateProductSetRequest
        //    {
        //        // A resource that represents Google Cloud Platform location
        //        ParentAsLocationName = new LocationName(opts.ProjectID, opts.ComputeRegion),
        //        ProductSetId = opts.ProductSetId,
        //        ProductSet = new ProductSet
        //        {
        //            DisplayName = opts.ProductSetDisplayName
        //        }
        //    };

        //    // The response is the product set with the `name` populated
        //    var response = await client.CreateProductSetAsync(request);

        //    return response;
        //}


        ////private async Task<ProductSet> GetProductSets(ProductSearchClient client, int pageSize)
        ////{
        ////    var request = new ListProductSetsRequest
        ////    {
        ////        ParentAsLocationName = new LocationName(this.options.Value.ProjectId, this.options.Value.LocationId),
        ////        PageSize = pageSize,
        ////    };

        ////    return await client.ListProductSets(request);
        ////}

        //private async Task<Product> CreateProduct(ProductSearchClient client, CreateProductOptions opts)
        //{
        //    var request = new CreateProductRequest
        //    {
        //        // A resource that represents Google Cloud Platform location.
        //        ParentAsLocationName = new LocationName(opts.ProjectID, opts.ComputeRegion),
        //        // Set product category and product display name
        //        Product = new Product
        //        {
        //            DisplayName = opts.DisplayName,
        //            ProductCategory = opts.ProductCategory,
        //            Description = opts.Description ?? string.Empty,
        //        },
        //        ProductId = opts.ProductID
        //    };

        //    foreach (var label in opts.ProductLabels)
        //    {
        //        request.Product.ProductLabels.Add(new KeyValue { Key = label.Key, Value = label.Value });
        //    }

        //    // The response is the product with the `name` field populated.
        //    var product = await client.CreateProductAsync(request);

        //    return product;
        //}

        private async Task <Product> GetProduct(ProductSearchClient client, string productId)
        {
            var request = new GetProductRequest
            {
                ProductName = new ProductName(this.options.Value.ProjectId, this.options.Value.LocationId, productId),
            };

            return(await client.GetProductAsync(request));
        }
예제 #25
0
        public GetProductResponse GetProduct(GetProductRequest request)
        {
            GetProductResponse response     = new GetProductResponse();
            ProductTitle       productTitle = _productTitleRepository.FindBy(request.ProductId);

            response.Product = _mapper.Map <ProductTitle, ProductView>(productTitle);

            return(response);
        }
예제 #26
0
        public async Task <ProductResponse> GetById(string id)
        {
            var filter = new GetProductRequest {
                Id = id
            };
            var result = (await GetProducts(filter)).SingleOrDefault();

            return(result);
        }
예제 #27
0
        public GetProductResponse Get(GetProductRequest request)
        {
            var readByProductIdRequest  = _mapper.Map <ProductDetailsModel>(request);
            var readByProductIdResponse = _productDetailsManager.ReadByProductId(readByProductIdRequest);

            var getProductResponse = _mapper.Map <GetProductResponse>(readByProductIdResponse);

            return(getProductResponse);
        }
예제 #28
0
        public override Task <GetQuantityResponse> GetEffectiveQuantity(GetProductRequest request, Grpc.Core.ServerCallContext context)
        {
            this.logger.LogInformation($"Received query for effective quantity of SKU {request.SKU}");
            var quantity = this.repository.GetCurrentQuantity(request.SKU);

            return(Task.FromResult(new GetQuantityResponse {
                Quantity = (uint)quantity
            }));
        }
예제 #29
0
        public GetProductResponse GetProduct(GetProductRequest getproductRequest)
        {
            var product    = productRepository.FindProductById(getproductRequest.Id);
            var productDTO = messageMapper.MapToProductDto(product);

            return(new GetProductResponse {
                Product = productDTO
            });
        }
예제 #30
0
        public GetProductResponse GetProduct(GetProductRequest request)
        {
            GetProductResponse response = new GetProductResponse();

            Product product = _productRepository.FindBy(request.ProductId);

            response.Product = product.ConvertToProductDetailView();
            return(response);
        }