public IHttpActionResult PutOrder(int id) { Order order = db.Orders.Find(id); if (order == null) { return(BadRequest("O pedido não existe!")); } if (IsAuthorized(order.Email)) { if (order.PrecoFrete != 0) { order.Status = "fechado"; db.Entry(order).State = EntityState.Modified; db.SaveChanges(); return(Ok(order)); } else { return(BadRequest("Frete não calculado!")); } } else { return(BadRequest("Usuário não autorizado!")); } }
public virtual void Atualizar(TEntity obj) { var entry = Context.Entry(obj); DbSet.Attach(obj); entry.State = EntityState.Modified; }
public async Task <IActionResult> PutEndereco(int id, Endereco endereco) { if (id != endereco.Id) { return(BadRequest()); } _context.Entry(endereco).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EnderecoExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCliente(int id, Cliente cliente) { if (id != cliente.Id) { return(BadRequest()); } _context.Entry(cliente).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClienteExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IHttpActionResult PutProduct(int id, Product product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != product.Id) { return(BadRequest()); } bool prodSameCode = db.Products.Where(prod => prod.codigo != product.codigo) .Any(prod => prod.codigo == product.codigo); bool prodSameModel = db.Products.Where(prod => prod.modelo != product.modelo) .Any(prod => prod.modelo == product.modelo); if (prodSameCode && prodSameModel) { return(BadRequest("Código e modelo já existente.")); } else if (prodSameCode) { return(BadRequest("Código já existente.")); } else if (prodSameModel) { return(BadRequest("Modelo já existente.")); } db.Entry(product).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void Update(TEntity obj) { Db.Entry(obj).State = EntityState.Modified; Db.SaveChanges(); }
public void Update(T obj) { _context.Entry(obj).State = EntityState.Modified; _context.SaveChanges(); }