Example #1
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseStatusCodePages();
            }

            app.UseStaticFiles();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: null,
                    template: "{controller=Product}/{action=List}/Page{productPage}/{pageSize:int}"
                    );
                routes.MapRoute(
                    name: null,
                    template: "{controller=Product}/{action=List}/Page{productPage:int}"
                    );
                routes.MapRoute(
                    name: null,
                    template: "{controller=Product}/{action=List}/{pageSize:int}"
                    );
                routes.MapRoute(
                    name: null,
                    template: "{controller=Product}/{action=List}"
                    );
            });
            SeedDataCategory.EnsurePopulated(app);
            SeedDataProduct.EnsurePopulated(app);
        }
Example #2
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var service       = scope.ServiceProvider;
                var product       = service.GetRequiredService <ProductContext>();
                var staff         = service.GetRequiredService <StaffContext>();
                var customer      = service.GetRequiredService <CustomerContext>();
                var supplier      = service.GetRequiredService <SupplierContext>();
                var promotion     = service.GetRequiredService <PromotionContext>();
                var invoice       = service.GetRequiredService <InvoiceContext>();
                var detailInvoice = service.GetRequiredService <DetailInvoiceContext>();
                var receipt       = service.GetRequiredService <ReceiptContext>();
                var detailreceipt = service.GetRequiredService <DetailReceiptContext>();
                var account       = service.GetRequiredService <AccountContext>();
                try
                {
                    SeedDataProduct.Initialize(product);
                    SeedDataStaff.Initialize(staff);
                    SeedDataCustomer.Initialize(customer);
                    SeedDataSupplier.Initialize(supplier);
                    SeedDataPromotion.Initialize(promotion);
                    SeedDataInvoice.Initialize(invoice);
                    SeedDataDetailInvoice.Initialize(detailInvoice);
                    SeedDataReceipt.Initialize(receipt);
                    SeedDataDetailReceipt.Initialize(detailreceipt);
                    SeedDataAccount.Initialize(account);
                }
                catch (Exception ex)
                {
                    var logger = service.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured seeding database.");
                }
            }
            host.Run();
        }