Пример #1
0
        public async Task <IActionResult> PutRoundtrip([FromRoute] int id, [FromBody] Roundtrip roundtrip)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != roundtrip.Id)
            {
                return(BadRequest());
            }

            _context.Entry(roundtrip).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RoundtripExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
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(_investingContext)
     .ExecuteAsync(async() => {
         // Achieving atomicity between original ordering database operation and the IntegrationEventLog thanks to a local transaction
         await _investingContext.SaveChangesAsync();
         //await _eventLogService.SaveEventAsync(evt, _executionContext.Database.CurrentTransaction.GetDbTransaction());
     });
 }
Пример #3
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();
        }
Пример #4
0
        public async Task <IActionResult> DeleteInvestment([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var investment = await _context.Investments.FindAsync(id);

            if (investment == null)
            {
                return(NotFound());
            }

            _context.Investments.Remove(investment);
            await _context.SaveChangesAsync();

            return(Ok(investment));
        }