Ejemplo n.º 1
0
        public async Task <Factory> Update(int id, Factory factory)
        {
            //var updateFactory = JsonConvert.DeserializeObject<Factory>(factory);
            var dbFactory = await _context.Factories.FirstOrDefaultAsync(f => f.Id == id);

            dbFactory.Name                  = factory.Name;
            dbFactory.Description           = factory.Description;
            _context.Entry(dbFactory).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(factory);
        }
Ejemplo n.º 2
0
        public void UpdateUsingEntry(Product product)
        {
            var productToUpdate    = db.Products.Find(product.Id);
            var anyProductToUpdate = productToUpdate != null;

            if (anyProductToUpdate)
            {
                product.Name ??= productToUpdate.Name;
                product.ManufacturerId = product.ManufacturerId == default
                    ? productToUpdate.ManufacturerId
                    : product.Id;
                db.Entry(productToUpdate).CurrentValues.SetValues(product);
                db.SaveChanges();
            }
        }