Exemple #1
0
        public async Task <Product> Create(DtoProductPost dtoProductPost)
        {
            var product = new Product()
            {
                CategoryID      = dtoProductPost.CategoryID,
                SupplierID      = dtoProductPost.SupplierID,
                ProductName     = dtoProductPost.ProductName,
                UnitPrice       = dtoProductPost.UnitPrice,
                QuantityPerUnit = dtoProductPost.QuantityPerUnit,
                Discontinued    = dtoProductPost.Discontinued,
                UnitsInStock    = dtoProductPost.UnitsInStock,
                UnitsOnOrder    = dtoProductPost.UnitsOnOrder,
                ReorderLevel    = dtoProductPost.ReorderLevel
            };

            unitOfWork.Add(product);

            unitOfWork.Commit();

            var newProduct = await unitOfWork.Query <Product>().OrderBy(x => x.ProductID).LastOrDefaultAsync();

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

            return(newProduct);
        }
Exemple #2
0
        public async Task <DtoProductGet> PostProduct([FromBody] DtoProductPost dtoProduct)
        {
            var item = await queryProcessor.Create(dtoProduct);

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

            return(product);
        }