Ejemplo n.º 1
0
        public async Task <bool> CommitSaveChangesAsync()
        {
            try
            {
                await _dbContext.SaveChangesAsync();

                return(true);
            }
            catch (DbUpdateException ex)
            {
                Console.WriteLine("Something went wrong." + ex);
                return(false);
            }
        }
Ejemplo n.º 2
0
        public async Task SendCommandAsync <T>(T command) where T : Command
        {
            logger.Info("[ServiceBus->SendCommandAsync] Sending command of type: {0}", typeof(T).Name);

            var entity = new CommandEntity
            {
                Id            = command.CommandId,
                CorrelationId = command.CorrelationId,
                ExecutedBy    = command.ExecutedBy,
                Type          = command.GetType().FullName,
                ScheduledAt   = DateTimeOffset.UtcNow,
                Payload       = messageSerializer.Serialize(command)
            };

            db.Commands.Add(entity);

            await db.SaveChangesAsync();

            try
            {
                await SendMessage(command, commandsQueueClient);

                entity.Success = true;
            }
            catch (Exception e)
            {
                entity.ErrorDescription = e.ToString();

                throw e;
            }
            finally
            {
                entity.Executed   = true;
                entity.ExecutedAt = DateTimeOffset.UtcNow;
                db.SaveChanges();
            }
        }
Ejemplo n.º 3
0
 public Task SaveChangesAsync()
 {
     return(db.SaveChangesAsync());
 }