예제 #1
0
        public async Task <IActionResult> Put([FromRoute] Guid productID, [FromBody] Product value)
        {
            if (null == value || Guid.Empty == value.ProductID ||
                null == value.ProductID)
            {
                return(ResponseHelper.BadRequest());
            }

            // 先查看当前保存的数据中是否有这么一个产品信息
            var product = await _productRepository.GetAsync(value.ProductID);

            if (null == product)
            {
                await _productRepository.AddAsync(value);
            }
            else
            {
                product.BrandID        = value.BrandID;
                product.CategoryID     = value.CategoryID;
                product.CreatedTime    = value.CreatedTime;
                product.Currency       = value.Currency;
                product.Description    = value.Description;
                product.Height         = value.Height;
                product.Images         = value.Images;
                product.LastUpdateTime = value.LastUpdateTime;
                product.Length         = value.Length;
                product.ProductName    = value.ProductName;
                product.ThumbnailImage = value.ThumbnailImage;
                product.UnitOfLength   = value.UnitOfLength;
                product.UnitOfWeight   = value.UnitOfWeight;
                product.Weight         = value.Width;
                product.Width          = value.Width;
                await _productRepository.UpdateAsync(product);
            }
            return(Ok());
        }