public IActionResult Index() { if (!_context.Receivers.Any()) { _seeder.Seed(); } if (this.User.Identity.IsAuthenticated) { var uncompletedOrders = _ordersService.GetAllUncomleted(); var model = uncompletedOrders.Select(x => new UncomletedOrdersViewModel { OrderId = x.Id, //Sequence = int.Parse(x.SequenceNumber), ReceiverName = x.Receiver.Name, OrderedPackagesCount = x.Products.Sum(p => p.OrderedPackagesCount), OrderedPackagesWeight = x.Products.Sum(p => p.OrderedPackagesWeight), DeliveryAddress = x.DeliveryAddress.Street, }) .OrderBy(x => x.Sequence) .ToList(); return(this.View("IndexLoggedIn", model)); } else { return(this.View()); } }
public async Task StartAsync(CancellationToken cancellationToken) { using IServiceScope serviceScope = _serviceProvider.CreateScope(); foreach (string dataSeederTypeName in _dataSeedingOptions.Value.DataSeeders) { if (String.IsNullOrWhiteSpace(dataSeederTypeName)) { continue; } Type?dataSeederType = Type.GetType(dataSeederTypeName); if (dataSeederType == null) { throw new OptionsValidationException( nameof(DataSeedingOptions.DataSeeders), typeof(DataSeedingOptions), new[] { $"Data seeder '{dataSeederTypeName}' not found" } ); } if (!typeof(IDataSeeder).IsAssignableFrom(dataSeederType)) { throw new OptionsValidationException( nameof(DataSeedingOptions.DataSeeders), typeof(DataSeedingOptions), new[] { $"Data seeder '{dataSeederTypeName}' must implement {nameof(IDataSeeder)}" } ); } IDataSeeder dataSeeder = (IDataSeeder)ActivatorUtilities.CreateInstance(serviceScope.ServiceProvider, dataSeederType); await dataSeeder.Seed(cancellationToken); } }
public MongoDbContext(DatabaseSettings settings, IDataSeeder seeder) { var client = BuildClient(settings.ConnectionString, settings.LogCommands); if (!isInitialized) { ConfigureMapping(); var dbExsists = client.ListDatabaseNames().ToList().Any(n => n == settings.DatabaseName); if (!dbExsists) { _database = client.GetDatabase(settings.DatabaseName); seeder.Seed(this); } isInitialized = true; } if (_database == null) { _database = client.GetDatabase(settings.DatabaseName); } }