Пример #1
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new TrainingContext(serviceProvider.GetRequiredService <DbContextOptions <TrainingContext> >()))
            {
                using (var command = context.Database.GetDbConnection().CreateCommand())
                {
                    command.CommandText = "ResetComputerTrainingCertificationDatabase";
                    command.CommandType = CommandType.StoredProcedure;

                    if (command.Connection.State != ConnectionState.Open)
                    {
                        command.Connection.Open();
                    }

                    command.ExecuteNonQuery();
                }
            }
        }
Пример #2
0
        public static async Task DispatchDomainEventsAsync(this IMediator mediator, TrainingContext ctx)
        {
            var domainEntities = ctx.ChangeTracker
                                 .Entries <Entity>()
                                 .Where(x => x.Entity.DomainEvents != null && x.Entity.DomainEvents.Any());

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

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

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

            await Task.WhenAll(tasks);
        }
 public StudentRepository(TrainingContext context)
 {
     _context = context;
 }
 public CertificationRepository(TrainingContext context)
 {
     _context = context;
 }