Пример #1
0
        public async Task <IActionResult> PutClienteItem(string id, Cliente varCliente)
        {
            if (!String.Equals(id, varCliente.Id))
            {
                return(BadRequest());
            }
            _context.Entry(varCliente).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
        public async Task <IActionResult> UpdateProductos(string id, Producto newProducto)
        {
            if (!String.Equals(id, newProducto.Id))
            {
                return(NotFound());
            }
            _context.Entry(newProducto).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Пример #3
0
        public void Edit(TEntity entity)
        {
            var entry = _context.Entry <TEntity>(entity);
            var pkey  = _dbSet.Create().GetType().GetProperty("Id").GetValue(entity);

            if (entry.State == EntityState.Detached)
            {
                var     set            = _context.Set <TEntity>();
                TEntity attachedEntity = set.Find(pkey);  // access the key
                if (attachedEntity != null)
                {
                    var attachedEntry = _context.Entry(attachedEntity);
                    attachedEntry.CurrentValues.SetValues(entity);
                }
                else
                {
                    entry.State = EntityState.Modified; // attach the entity
                }
            }

            _context.SaveChanges();
        }
Пример #4
0
 private List <Dish> PrepareDish(List <Dish> lstDish)
 {
     lstDish.ForEach(d => _context.Entry(d).Reference(r => r.Restaurant).Load());
     lstDish.ForEach(d => d.Restaurant?.Dishes.Clear());
     return(lstDish);
 }