Esempio n. 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, EShopContext eShopContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler();
            }

            app.UseStatusCodePages();

            app.UseMvc();

            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Product, ProductToGetDTO>();
                cfg.CreateMap <ProductToCreateDTO, Product>();
                cfg.CreateMap <ProductToUpdateDTO, Product>();
                cfg.CreateMap <Product, ProductToPatchDTO>();

                cfg.CreateMap <Customer, CustomerToGetDTO>();
                cfg.CreateMap <CustomerToCreateDTO, Customer>();
                cfg.CreateMap <CustomerToUpdateDTO, Customer>();
                cfg.CreateMap <Customer, CustomerToPatchDTO>();

                cfg.CreateMap <Order, OrderToGetDTO>();
                cfg.CreateMap <OrderDetail, OrderDetailToGetDTO>();
            });

            eShopContext.EnsureSeedDataForProducts();
            eShopContext.EnsureSeedDataForCustomers();
            eShopContext.EnsureSeedDataForOrders();
        }