Esempio n. 1
0
        public async Task <ProductModel> SaveProduct(ProductModel product)
        {
            var data = await Get(product.Id);

            if (data != null)
            {
                data.Name        = product.Name;
                data.Price       = product.Price;
                data.Description = product.Description;
            }
            else
            {
                var newProduct = new Products();
                newProduct.Name        = product.Name;
                newProduct.Price       = product.Price;
                newProduct.Description = product.Description;
                newProduct.CategoryId  = product.CategoryId;

                await dbContext.AddAsync(newProduct);
            }

            int id = await dbContext.SaveChangesAsync();

            product.Id = id;

            return(product);
        }
        public async Task Create(Product product)
        {
            await _context.AddAsync(product);

            await _context.SaveChangesAsync();
        }