示例#1
0
        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());
        }
示例#2
0
        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());
        }
示例#4
0
 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());
     });
 }
示例#5
0
        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();
        }