Beispiel #1
0
        /// <summary>
        /// The initialize.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        public static void Initialize(ConferenceContext context)
        {
            context.Database.EnsureCreated();

            // Look for any attendees.
            if (context.Attendees.Any())
            {
                return;   // DB has been seeded
            }

            var attendees = new[]
            {
                new Attendee {
                    FirstName = "Carson", LastName = "Alexander", Title = "Mr"
                },
                new Attendee {
                    FirstName = "Meredith", LastName = "Alonso", Title = "Mr"
                },
                new Attendee {
                    FirstName = "Arturo", LastName = "Anand", Title = "Mr"
                },
                new Attendee {
                    FirstName = "Gytis", LastName = "Barzdukas", Title = "Mr"
                },
                new Attendee {
                    FirstName = "Yan", LastName = "Li", Title = "Mr"
                },
                new Attendee {
                    FirstName = "Peggy", LastName = "Justice", Title = "Mr"
                },
                new Attendee {
                    FirstName = "Laura", LastName = "Norman", Title = "Mr"
                },
                new Attendee {
                    FirstName = "Nino", LastName = "Olivetto", Title = "Mr"
                }
            };

            foreach (var a in attendees)
            {
                context.Attendees.Add(a);
            }

            context.SaveChanges();
        }
        /// <summary>
        /// The dispatch domain events async.
        /// </summary>
        /// <param name="mediator">
        /// The mediator.
        /// </param>
        /// <param name="ctx">
        /// The ctx.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public static async Task DispatchDomainEventsAsync(this IMediator mediator, ConferenceContext ctx)
        {
            var domainEntities = ctx.ChangeTracker
                                 .Entries <BaseEntity>()
                                 .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);
        }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RegistrationRepository"/> class.
 /// Initializes a new instance of the <see cref="Repository{TEntity}"/> class.
 /// </summary>
 /// <param name="context">
 /// The context.
 /// </param>
 public RegistrationRepository(ConferenceContext context)
 {
     this._context = context;
     this._dbSet   = context.Set <Registration>();
 }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Repository{TEntity}"/> class.
 /// </summary>
 /// <param name="context">
 /// The context.
 /// </param>
 public Repository(ConferenceContext context)
 {
     this._context = context;
     this._dbSet   = context.Set <TEntity>();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConferenceRepository"/> class.
 /// </summary>
 /// <param name="context">
 /// The context.
 /// </param>
 public ConferenceRepository(ConferenceContext context)
 {
     this._context = context;
     this._dbSet   = context.Set <Conference>();
 }