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

                var createdProduct = productModel.Clone();
                createdProduct.VendorId     = vendorId;
                createdProduct.CreationDate = DateTime.UtcNow;
                createdProduct.LastUpdate   = null;
                createdProduct.Id           = productId.Value;

                var savedProduct = await ServiceProxyUtils.GetProductService(productId.Value).Create(createdProduct);

                return(CreatedAtAction(nameof(Product), new { vendorId = vendorId, productId = savedProduct.Id }, savedProduct));
            }
            catch (Exception ex)
            {
                // TODO: handle error
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                throw;
            }
        }
コード例 #2
0
        public async Task <IActionResult> Product(Guid vendorId, Guid productId)
        {
            try
            {
                var product = await ServiceProxyUtils.GetProductService(productId).Get(productId);

                return(product == null ?
                       (IActionResult)NotFound() :
                       new OkObjectResult(product));
            }
            catch (Exception ex)
            {
                // TODO: handle error
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                throw;
            }
        }
コード例 #3
0
        public async Task <IActionResult> UpdateProduct(Guid vendorId, Guid productId, [FromBody] ProductModel product)
        {
            try
            {
                var updatedProduct = product.Clone();
                updatedProduct.Id         = productId;
                updatedProduct.VendorId   = vendorId;
                updatedProduct.LastUpdate = DateTime.UtcNow;

                var savedProduct = await ServiceProxyUtils.GetProductService(productId).Update(updatedProduct);

                return(new OkObjectResult(savedProduct));
            }
            catch (Exception ex)
            {
                // TODO: handle error
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                throw;
            }
        }