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()); }
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(); }
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); }