public async Task <IActionResult> PutBalance([FromRoute] int id, [FromBody] Balance balance) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != balance.Id) { return(BadRequest()); } _context.Entry(balance).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BalanceExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PostCandleChart([FromBody] CandleChart candleChart) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.CandleCharts.Add(candleChart); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCandleChart", new { id = candleChart.Id }, candleChart)); }
public async Task <IActionResult> KeepUpdateMarket([FromRoute] int id, [FromBody] Market market) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != market.Id) { return(BadRequest()); } _context.Entry(market).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MarketExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private async Task SaveEventAndOrderingContextChangesAsync(IntegrationEvent evt) { //Use of an EF Core resiliency strategy when using multiple DbContexts within an explicit BeginTransaction(): //See: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency await ResilientTransaction.New(_exchangeAccessContext) .ExecuteAsync(async() => { // Achieving atomicity between original ordering database operation and the IntegrationEventLog thanks to a local transaction await _exchangeAccessContext.SaveChangesAsync(); //await _eventLogService.SaveEventAsync(evt, _executionContext.Database.CurrentTransaction.GetDbTransaction()); }); }
public async Task CreateRequestForCommandAsync <T>(Guid id) { var exists = await ExistAsync(id); var request = exists ? throw new Exception($"Request with {id} already exists") : new ClientRequest() { Id = id, Name = typeof(T).Name, Time = DateTime.UtcNow }; _context.Add(request); await _context.SaveChangesAsync(); }