public async Task <ActionResult <string> > PutCadastro([FromBody] Cadastro cadastro) { try { if (!ValidarHeaders()) { return(BadRequest("Autorização inválida.")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (CadastroService.ConsisteDadosEntrada(cadastro)) { try { Cadastro cadastroUpdate = BuscaCadastroUnico(cadastro.CPF); if (cadastroUpdate != null) { cadastro.ID = cadastroUpdate.ID; _context.Entry(cadastroUpdate).CurrentValues.SetValues(cadastro); _context.Entry(cadastroUpdate).State = EntityState.Modified; _context.Entry(cadastroUpdate).Property("ID").IsModified = false; await _context.SaveChangesAsync(); } else { return(NotFound("Documento não localizado.")); } } catch (Exception ex) { return(UnprocessableEntity($"Erro ao salvar dados. {ex.Message}")); } } else { return(UnprocessableEntity("Dados inválidos.")); } } catch (Exception ex) { return(UnprocessableEntity("Dados inválidos.")); } return(Ok("PutCadastro - Cadastro atualizado")); }
public async Task <IActionResult> PutDepartments(int id, DepartmentView departments) { if (id != departments.Id) { return(BadRequest()); } _context.Entry(departments).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DepartmentsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutDataEventRecord([FromRoute] int id, [FromBody] DataEventRecord dataEventRecord) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != dataEventRecord.DataEventRecordId) { return(BadRequest()); } _context.Entry(dataEventRecord).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DataEventRecordExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void UpdateLastLoggedInDate(AppUser appUser) { appUser.UpdateDateTime = DateTime.UtcNow; using (var db = new MySqlDbContext(_options.MySqlConnectionString)) { db.AppUsers.Attach(appUser); db.Entry(appUser).Property(u => u.LastLoggedInDate).IsModified = true; //var updatededRecipe = db.Update(appUser); db.SaveChanges(); } }
public bool Edit(T entity) { mySqlDbContext.Entry(entity).State = EntityState.Modified; return(true); }
public async Task UpdateAsync(T entity) { _context.Entry(entity).State = EntityState.Modified; await _context.SaveChangesAsync().ConfigureAwait(false); }