Exemplo n.º 1
0
        public async Task <Product> UpdateProductAsync(Product product)
        {
            if (!_context.Products.Local.Any(p => p.ProductId == product.ProductId))
            {
                _context.Products.Attach(product);
            }
            _context.Entry <Product>(product).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(product);
        }
        public async Task <Product> UpdateProductAsync(Product product)
        {
            //LOCAL: Gets an ObservableCollection<T> that represents a local view of all Added, Unchanged, and Modified entities in this set. This local view will stay in sync as entities are added or removed from the context. Likewise, entities added to or removed from the local view will automatically be added to or removed from the context.
            if (!_context.Products.Local.Any(p => p.ProductId == product.ProductId))
            {
                _context.Products.Attach(product);
            }
            _context.Entry <Product>(product).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(product);
        }