public void Put(T model) { _context.Entry(model).Property("EnderecoId").CurrentValue = null; _context.Entry(model).Property("TelefoneId").CurrentValue = null; _context.Entry(model).State = EntityState.Modified; _context.SaveChanges(); }
public void Alterar(Contato contato) { _context.Attach(contato); _context.Entry(contato).Property("Nome").IsModified = true; _context.Entry(contato).Property("Celular").IsModified = true; _context.Entry(contato).Property("Email").IsModified = true; _context.Entry(contato).Property("DataAlteracao").IsModified = true; _context.SaveChanges(); }
public async Task <IActionResult> PutAgendaItem(long id, AgendaItem agendaItem) { if (id != agendaItem.Id) { return(BadRequest()); } _context.Entry(agendaItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AgendaItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutContacts([FromRoute] long id, [FromBody] Contacts contacts) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != contacts.IdUser) { return(BadRequest()); } _context.Entry(contacts).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Put(int id, [FromBody] InfoModel info) { if (info.IdPersona == 0) { info.IdPersona = id; } if (info.IdPersona != id) { return(BadRequest(ErrorsHelp.RespuestaHttp(400, "Error al enviar la petición"))); } if (!await agendactx.DboInfos.Where(x => x.IdPersona == info.IdPersona).AsNoTracking().AnyAsync()) { return(NotFound(ErrorsHelp.RespuestaHttp(404, $"El curso {info.IdPersona} no existe"))); } if (await agendactx.DboInfos.Where(x => x.Email == info.Email && x.IdPersona != info.IdPersona).AsNoTracking().AnyAsync()) { return(BadRequest(ErrorsHelp.RespuestaHttp(400, $"El código {info.Email} ya existe"))); } if (!ModelState.IsValid) { return(BadRequest(ErrorsHelp.ModelStateErrors(ModelState))); } agendactx.Entry(info).State = EntityState.Modified; await agendactx.SaveChangesAsync(); return(NoContent()); }
public async Task <IActionResult> PutContact(int id, Contact contact) { if (id != contact.ContactId) { return(BadRequest()); } contact.DateUpdate = DateTime.UtcNow; _context.Entry(contact).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> UpdateCustomer(long id, Customer customer) { if (id != customer.Id) { return(BadRequest()); } _context.Entry(customer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <T> Update(Guid id, T entity) { _context.Entry(entity).State = EntityState.Modified; entity.DateUpdated = Now; await _context.SaveChangesAsync(); return(entity); }
public ActionResult Alterar(Contato contato) { //Atualizar no banco de dados _context.Entry(contato).State = System.Data.Entity.EntityState.Modified; _context.SaveChanges(); //Mensagem de sucesso TempData["msg"] = "Alterado!"; return(RedirectToAction("Listar")); }
public ActionResult Edit([Bind(Include = "ID,Name,LastName,Email,Number,NType")] Register register) { if (ModelState.IsValid) { db.Entry(register).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(register)); }
public ActionResult Edit([Bind(Include = "Id,Nombre")] Contacto contacto) { if (ModelState.IsValid) { db.Entry(contacto).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(contacto)); }
public ActionResult Edit([Bind(Include = "Id,Nombre,Telefono,Correo")] Agenda agenda) { if (ModelState.IsValid) { db.Entry(agenda).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(agenda)); }
public async Task <ActionResult> Edit([Bind(Include = "ContactId,Name,Observation,FavoriteTag")] Contact contact) { if (ModelState.IsValid) { db.Entry(contact).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(contact)); }
public ActionResult Edit([Bind(Include = "ID,PessoaID,Numero,Tipo")] Telefone telefone) { if (ModelState.IsValid) { db.Entry(telefone).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PessoaID = new SelectList(db.Pessoas, "ID", "Nome", telefone.PessoaID); return(View(telefone)); }
public ActionResult Edit([Bind(Include = "Id,Nome,Email,IdConsultor")] Cliente cliente) { if (ModelState.IsValid) { db.Entry(cliente).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IdConsultor = new SelectList(db.Consultores, "Id", "Nome", cliente.IdConsultor); return(View(cliente)); }
public ActionResult EditCustomer([Bind(Include = "LastName, FirstName, Mail, PhoneNumber, Budget, Subject")] Customer customer) { var CustomerToUpdate = db.Customers.Find(customer.CustomerID); if (ModelState.IsValid) { db.Entry(customer).State = EntityState.Modified; try { db.SaveChanges(); return(RedirectToAction("ListCustomers")); } catch (DataException) { //Si echec: ModelState.AddModelError("", "Une erreur s'est produite, si le problème persiste appelez un technicien"); } } return(View(CustomerToUpdate)); }
public async Task <ActionResult <Contato> > PutContato(long id, Contato contato) { if (id != contato.Id) { return(BadRequest()); } _context.Entry(contato).State = EntityState.Modified; await _context.SaveChangesAsync(); return(contato); }
public IActionResult Put([FromBody] Turma turma) { if (ModelState.IsValid) { _contexto.Entry(turma).State = EntityState.Modified; _contexto.SaveChanges(); return(Ok(turma)); } else { return(BadRequest(ModelState.Values.SelectMany(e => e.Errors.Select(er => er.ErrorMessage)))); } }
public bool Edit(Persona persona) { try { db.Entry(persona).State = EntityState.Modified; db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public ActionResult Edit([Bind(Include = "Id,Nome,Email,IdConsultor, Telefones")] Cliente cliente) { if (ModelState.IsValid) { foreach (var telefone in cliente.Telefones) { if (telefone.Id > 0) { db.Entry(telefone).State = EntityState.Modified; } else { db.Entry(telefone).State = EntityState.Added; } } db.Entry(cliente).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IdConsultor = new SelectList(db.Consultores, "Id", "Nome", cliente.IdConsultor); return(View(cliente)); }
public async Task <ActionResult> Edit([Bind(Include = "TelephoneId,ContactId,TelephoneContent,ContactType")] Telephone telephone) { if (ModelState.IsValid) { var contact = db.Contatos.Find(telephone.ContactId); telephone.Contact = contact; db.Entry(telephone).State = EntityState.Modified; await db.SaveChangesAsync(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); } ViewBag.ContactId = new SelectList(db.Contatos, "ContactId", "Name", telephone.ContactId); return(View(telephone)); }
public IActionResult Put([FromBody] Professor professor) { if (ModelState.IsValid) { _contexto.Entry(professor).State = EntityState.Modified; _contexto.SaveChanges(); return(Ok(professor)); } else { return(BadRequest(new { message = "Requisição inválida.", error = ModelState.Values.SelectMany(e => e.Errors.Select(er => er.ErrorMessage)) })); } }
public async Task <ActionResult> Edit([Bind(Include = "AddressId,ContactId,AddressContent,ContactType")] Address address) { if (ModelState.IsValid) { var contact = db.Contatos.Find(address.ContactId); address.Contact = contact; db.Entry(address).State = EntityState.Modified; await db.SaveChangesAsync(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); } ViewBag.ContactId = address.ContactId; return(View(address)); }
public async Task <ActionResult> Edit([Bind(Include = "EmailId,ContactId,EmailContent,ContactType")] Email email) { if (ModelState.IsValid) { db.Entry(email).State = EntityState.Modified; var contact = db.Contatos.Find(email.ContactId); email.Contact = contact; await db.SaveChangesAsync(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); } ViewBag.ContactId = new SelectList(db.Contatos, "ContactId", "Name", email.ContactId); return(View(email)); }
public void Alterar(Usuario usuario) { _context.Attach(usuario); _context.Entry(usuario).Property("Nome").IsModified = true; _context.Entry(usuario).Property("CPF").IsModified = true; _context.Entry(usuario).Property("Email").IsModified = true; _context.Entry(usuario).Property("Senha").IsModified = true; _context.Entry(usuario).Property("SenhaConfirmacao").IsModified = true; _context.Entry(usuario).Property("DataAlteracao").IsModified = true; _context.SaveChanges(); }
public async Task <IActionResult> UpdateUsuario(int id, [FromBody] Usuario usuario) { try { /** * Especifica uma entitdade que tera seu estado alterado */ context.Entry(usuario).State = EntityState.Modified; await context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (id != usuario.Id) { return(this.StatusCode(StatusCodes.Status400BadRequest, "Usuario não encontrado")); } } return(Ok(usuario)); }
public async Task <bool> Edit(Persona item) { try { var entity = await context.Persona.Include(x => x.TipoContacto).FirstOrDefaultAsync(c => c.Id == item.Id); if (entity == null) { return(false); } context.Entry(entity).CurrentValues.SetValues(item); await context.SaveChangesAsync(); return(true); } catch (Exception) { return(false); } }
public void PutAgenda(int id, Agenda agenda) { if (id != agenda.AgendaId) { this.AdicionarNotificacao("Informações invalidas"); } _context.Entry(agenda).State = EntityState.Modified; try { _context.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AgendaExists(id)) { this.AdicionarNotificacao("Registro inesistente"); } else { throw; } } }
public bool Delete(int id) { int resultSaveChanges = 0; try { using (var context = new AgendaContext()) { var elementToDelete = context.Contactos.FirstOrDefault(c => c.IdContacto == id); if (elementToDelete != null) { context.Entry(elementToDelete).State = System.Data.Entity.EntityState.Deleted; resultSaveChanges = context.SaveChanges(); Log.Debug("Se elimino el contacto."); } else { Log.Debug("No existe el id del contacto a eliminar."); Log.Error("No existe el id del contacto a eliminar."); throw new Exception("Error en el id ingresado, no existe en la base de datos."); } } } catch (SqlException ex) { Log.Debug(string.Format("Error: {0}", ex.InnerException)); Log.Error(string.Format("Error: {0}", ex.InnerException)); throw ex; } catch (Exception ex) { Log.Debug(string.Format("Error: {0}", ex.InnerException)); Log.Error(string.Format("Error: {0}", ex.InnerException)); throw ex; } return(resultSaveChanges > 0); }
public virtual TEntity Update(TEntity obj) { db.Attach(obj); ctx.Entry(obj).State = EntityState.Modified; return(obj); }