public void InsertOrUpdate(USERSINFORMATION user) { if (user.UserName == default(string)) // New entity { _context.Entry(user).State = EntityState.Added; } else // Existing entity { _context.Entry(user).State = EntityState.Modified; } }
public void Update(User item) { try { _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.SaveChanges(); } catch (Exception) { throw; } }
public async Task <IActionResult> PutUser(int id, User user) { if (id != user.Id) { return(BadRequest()); } _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutUser(int id, User user) { using var transaction = _context.Database.BeginTransaction(); _context.Entry(user).State = EntityState.Modified; await _context.SaveChangesAsync(); var integrationEventData = System.Text.Json.JsonSerializer.Serialize <object>(new { id = user.ID, newname = user.Name, version = user.Version }); _context.IntregationEventOutBox.Add(new IntregationEvent { Event = "user.update", Data = integrationEventData }); _context.SaveChanges(); transaction.Commit(); _integrationEventSenderService.StartPublishingOutstandingIntegrationEvents(); return(NoContent()); }
public void Update(User item) { _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.SaveChanges(); }