public async Task SeedAsync(ApplyingContext context, IWebHostEnvironment env, IOptions<ApplyingSettings> settings, ILogger<ApplyingContextSeed> logger)
        {
            var policy = CreatePolicy(logger, nameof(ApplyingContextSeed));

            await policy.ExecuteAsync(async () =>
            {

                var useCustomizationData = settings.Value
                .UseCustomizationData;

                var contentRootPath = env.ContentRootPath;


                using (context)
                {
                    context.Database.Migrate();

                    if (!context.PaymentTypes.Any())
                    {
                        context.PaymentTypes.AddRange(useCustomizationData
                                                ? GetPaymentTypesFromFile(contentRootPath, logger)
                                                : GetPredefinedPaymentTypes());

                        await context.SaveChangesAsync();
                    }

                    if (!context.ApplicationStatus.Any())
                    {
                        context.ApplicationStatus.AddRange(useCustomizationData
                                                ? GetApplicationStatusFromFile(contentRootPath, logger)
                                                : GetPredefinedApplicationStatus());
                    }

                    await context.SaveChangesAsync();
                }
            });
        }
Beispiel #2
0
        public async Task CreateRequestForCommandAsync <T>(Guid id)
        {
            var exists = await ExistAsync(id);

            var request = exists ?
                          throw new ApplyingDomainException($"Request with {id} already exists") :
                                new ClientRequest()
                                {
                                    Id   = id,
                                    Name = typeof(T).Name,
                                    Time = DateTime.UtcNow
                                };

            _context.Add(request);

            await _context.SaveChangesAsync();
        }