コード例 #1
0
        public async Task <IActionResult> Create(Guid?productId, [FromBody] ProductCatalogModel product)
        {
            try
            {
                if (!productId.HasValue)
                {
                    productId = Guid.NewGuid();
                }

                var createdVendor = product.Clone();
                createdVendor.CreationDate = DateTime.UtcNow;
                createdVendor.LastUpdate   = null;
                createdVendor.Id           = productId.Value;

                var savedVendor = await repository.Create(createdVendor);

                return(CreatedAtAction(nameof(Get), new { vendorId = savedVendor.Id }, savedVendor));
            }
            catch (Exception ex)
            {
                // TODO: handle error
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                throw;
            }
        }
コード例 #2
0
        public async Task <ProductCatalogModel> Create(ProductCatalogModel product)
        {
            try
            {
                ServicePartitionClient <HttpCommunicationClient> partitionClient = new ServicePartitionClient <HttpCommunicationClient>(communicationFactory, serviceUri);

                return(await partitionClient.InvokeWithRetryAsync(
                           async (client) =>
                {
                    var uri = client.Url.ToString() + "api/products/" + product.Id.ToString();

                    var reqContent = new StringContent(JsonConvert.SerializeObject(product), Encoding.UTF8, "application/json");

                    HttpResponseMessage response = await client.HttpClient.PostAsync(uri, reqContent);
                    string content = await response.Content.ReadAsStringAsync();
                    return JsonConvert.DeserializeObject <ProductCatalogModel>(content);
                }));
            }
            catch (Exception ex)
            {
                // Sample code: print exception
                //ServiceEventSource.Current.OperationFailed(ex.Message, "Count - run web request");
                throw;
            }
        }
コード例 #3
0
        private async Task Handler(BrokeredMessage message)
        {
            try
            {
                var productChanged = message.GetJsonBody <ProductChangedEvent>();

                // Start catalog update

                // 1. Get vendor name from VendorApplication
                var vendor = await vendorClient.Get(productChanged.Current.VendorId);

                // 2. Send message to update catalog
                var isNewProductCatalog = false;
                var catalogProduct      = await catalogProductClient.Get(productChanged.Current.Id);

                if (catalogProduct == null)
                {
                    isNewProductCatalog = true;
                    catalogProduct      = new ProductCatalogModel()
                    {
                        Id = productChanged.Current.Id,
                    };
                }

                catalogProduct.Name        = productChanged.Current.Name;
                catalogProduct.Enabled     = productChanged.Current.Enabled;
                catalogProduct.VendorId    = productChanged.Current.VendorId;
                catalogProduct.VendorName  = vendor.Name;
                catalogProduct.Price       = productChanged.Current.Price;
                catalogProduct.MembersOnly = productChanged.Current.MembersOnly;

                if (productChanged.Previous != null && productChanged.Previous.Price != productChanged.Current.Price)
                {
                    catalogProduct.PreviousPrice = productChanged.Previous.Price;
                }

                if (isNewProductCatalog)
                {
                    await catalogProductClient.Create(catalogProduct);
                }
                else
                {
                    await catalogProductClient.Update(catalogProduct);
                }
            }
            catch (Exception ex)
            {
            }
        }
コード例 #4
0
        public async Task <IActionResult> Update(Guid productId, [FromBody] ProductCatalogModel product)
        {
            try
            {
                var updatedProduct = product.Clone();
                updatedProduct.Id         = productId;
                updatedProduct.LastUpdate = DateTime.UtcNow;

                var savedVendor = await this.repository.Update(productId.ToString(), updatedProduct);

                return(new OkObjectResult(savedVendor));
            }
            catch (Exception ex)
            {
                // TODO: handle error
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                throw;
            }
        }
コード例 #5
0
        public async Task <ActionResult> Get([FromQuery] ProductCatalogModel productCatalogModel)
        {
            var listCatalogProducts = await _iSearchProductsByTagsService.GetCatalogProducts(productCatalogModel);

            return(Ok(listCatalogProducts));
        }
コード例 #6
0
 public async Task <IEnumerable <ProductCatalogResponse> > GetCatalogProducts(ProductCatalogModel productCatalogModel)
 {
     return(await Query <ProductCatalogResponse>("Crm.GetCatalogProducts", productCatalogModel));
 }
コード例 #7
0
 public async Task <IEnumerable <ProductCatalogResponse> > GetCatalogProducts(ProductCatalogModel productCatalogModel)
 {
     return(await _iSearchProductsByTagsRepository.GetCatalogProducts(productCatalogModel));
 }