示例#1
0
        public async Task <Product> Update(int id, DtoProductPut dtoProductPut)
        {
            var product = await unitOfWork.Query <Product>().FirstOrDefaultAsync(p => p.ProductID == id);

            if (product == null)
            {
                throw new KeyNotFoundException();
            }

            product.SupplierID      = dtoProductPut.SupplierID;
            product.QuantityPerUnit = dtoProductPut.QuantityPerUnit;
            product.UnitPrice       = dtoProductPut.UnitPrice;
            product.UnitsInStock    = dtoProductPut.UnitsInStock;
            product.UnitsOnOrder    = dtoProductPut.UnitsOnOrder;
            product.ReorderLevel    = dtoProductPut.ReorderLevel;
            product.Discontinued    = dtoProductPut.Discontinued;

            unitOfWork.Update(product);

            unitOfWork.Commit();

            BackgroundJob.Enqueue(() => RefreshCache());

            return(product);
        }
示例#2
0
        public async Task <DtoProductGet> PutProduct(int id, [FromBody] DtoProductPut dtoProduct)
        {
            var item = await queryProcessor.Update(id, dtoProduct);

            var model = autoMapper.Map <DtoProductGet>(item);

            return(model);
        }