Example #1
0
 public static void Initialize(HealthFoodDbContext context)
 {
     if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
     {
         context.Database.Migrate();
     }
 }
        public static async Task PublicarEventos(this IMediatorHandler mediator, HealthFoodDbContext context)
        {
            var domainEntities = context.ChangeTracker
                                 .Entries <IRaizAgregacao>()
                                 .Where(x => x.Entity.Notificacoes != null && x.Entity.Notificacoes.Any());

            var domainEvents = domainEntities
                               .SelectMany(x => x.Entity.Notificacoes)
                               .ToList();

            domainEntities.ToList()
            .ForEach(entity => entity.Entity.LimparEventos());

            var tasks = domainEvents
                        .Select(async(domainEvent) =>
            {
                await mediator.PublicarEvento(domainEvent);
            });

            await Task.WhenAll(tasks);
        }