コード例 #1
0
        public async Task <ProductDetailsItem> UpdateProductAsync(Guid id, UpdateProductItem updateProductItem)
        {
            if (id == Guid.Empty)
            {
                throw new ArgumentNullException(nameof(id));
            }

            if (updateProductItem == null)
            {
                throw new ArgumentNullException(nameof(updateProductItem));
            }

            return(await Task.Run(() =>
            {
                var found = _allProducts.FirstOrDefault(p => p.Id == id);
                if (found == null)
                {
                    return null;
                }

                found.Name = updateProductItem.Name;
                found.Price = updateProductItem.Price;
                found.Category = updateProductItem.Category;

                return Mapper.Map <ProductDetailsItem>(found);
            }));
        }
コード例 #2
0
        public async Task <IActionResult> UpdateProductAsync(Guid id, [FromBody] UpdateProductItem updateProduct)
        {
            var product = await ProductsService.UpdateProductAsync(id, updateProduct);

            if (product == null)
            {
                return(NotFound());
            }
            return(Ok(product));
        }