예제 #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, BugattiContext BContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            //Authentication code
            app.UseAuthentication();
            //-------------
            app.UseHttpsRedirection();
            app.UseRouting();

            //--Code CORS--
            app.UseCors(builder =>
                        builder.AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader());
            //-------------

            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
            DBInitializer.Initialize(BContext);
        }
예제 #2
0
        public static void Initialize(BugattiContext context)
        {
            //---TEMPORARY FOR DEBUGGING---
            //Delete DB if it exists
            context.Database.EnsureDeleted();
            //-----------------------------
            //Create the DB if not yet exists
            context.Database.EnsureCreated();

            //Cars
            Car t35 = null, t41 = null, t57 = null, aero = null, atl = null, veyr = null, chir = null, noire = null;
            //Creators
            Creator jean = null, ettore = null, jozef = null, achim = null, etienne = null;
            //countries
            Country italy = null, france = null, germany = null;
            //car countries
            Car_Country_JoinTable t35_IT = null, t41_FR = null, t57_FR = null, aero_DE = null, atl_FR = null, atl_DE = null, veyr_FR = null, chir_FR = null, chir_IT = null, noire_FR = null;


            #region ---COUNTRIES---

            if (!context.Countries.Any())
            {
                italy = new Country()
                {
                    //id
                    Name = "Italy",
                    //CreatorList = ,
                    //CarList = ,
                    InEU = true
                };
                france = new Country()
                {
                    //id
                    Name = "France",
                    //CreatorList = ,
                    //CarList = ,
                    InEU = true
                };
                germany = new Country()
                {
                    //id
                    Name = "Germany",
                    //CreatorList = ,
                    //CarList = ,
                    InEU = true
                };
                //add country to collection of countries
                context.Countries.Add(italy);
                context.Countries.Add(france);
                context.Countries.Add(germany);
                //save all the changes to the DB
                context.SaveChanges();
            }
            #endregion

            #region ---CREATORS---
            //ALL PROPERTIES:
            // Id, FirstName, LastName, Cars, Birthday, BirthPlace, FirstNameDad, LastNameDad, FirstNameMom, LastNameMom
            if (!context.Creators.Any())
            {
                //create new Creators
                ettore = new Creator()
                {
                    FirstName    = "Ettore",
                    LastName     = "Bugatti",
                    Birthday     = new DateTime(1881, 9, 15),
                    BirthPlace   = italy,
                    FirstNameDad = "Carlo",
                    LastNameDad  = "Bugatti",
                    FirstNameMom = "Teresa",
                    LastNameMom  = "Lorioli"
                };
                jean = new Creator()
                {
                    FirstName    = "Jean",
                    LastName     = "Bugatti",
                    Birthday     = new DateTime(1909, 1, 15),
                    BirthPlace   = france,
                    FirstNameDad = "Ettore",
                    LastNameDad  = "Bugatti",
                    FirstNameMom = "Barbara",
                    LastNameMom  = "Mascherpa"
                };
                jozef = new Creator()
                {
                    FirstName    = "Jozef",
                    LastName     = "Kaban",
                    Birthday     = new DateTime(1973, 1, 4),
                    BirthPlace   = germany,
                    FirstNameDad = "/",
                    LastNameDad  = "/",
                    FirstNameMom = "/",
                    LastNameMom  = "/"
                };
                achim = new Creator()
                {
                    FirstName    = "Achim",
                    LastName     = "Anscheidt",
                    Birthday     = new DateTime(1, 1, 1),
                    BirthPlace   = germany,
                    FirstNameDad = "/",
                    LastNameDad  = "Anscheidt",
                    FirstNameMom = "/",
                    LastNameMom  = "/"
                };
                etienne = new Creator()
                {
                    FirstName    = "Étienne",
                    LastName     = "Salomé",
                    Birthday     = new DateTime(1980, 9, 20),
                    BirthPlace   = france,
                    FirstNameDad = "/",
                    LastNameDad  = "Salomé",
                    FirstNameMom = "/",
                    LastNameMom  = "/"
                };
                //add Creators to collection of Creators
                context.Creators.Add(ettore);
                context.Creators.Add(jean);
                context.Creators.Add(jozef);
                context.Creators.Add(achim);
                context.Creators.Add(etienne);
                //save all the changes to the DB
                context.SaveChanges();
            }
            #endregion

            #region ---CARS---
            //ALL PROPERTIES:
            //  Id, Name, Creator, StartBuildYear, StopBuildYear, Countries, AvrgPrice, Horsepower, MaxSpeed, Weight, Prototype, WorldRecords, TotalBuilt, TotalRaceVictories, SmallDescription

            if (!context.Cars.Any())
            {
                t35 = new Car()
                {
                    //id
                    Name           = "Type 35",
                    Creator        = ettore,
                    StartBuildYear = new DateTime(1924, 1, 1),
                    StopBuildYear  = new DateTime(1931, 1, 1),
                    //Countries = List<Country>(france, italy);
                    AvrgPrice          = 2500000,
                    Horsepower         = 90,
                    MaxSpeed           = 200,
                    Weight             = 750,
                    Prototype          = false,
                    WorldRecords       = 0,
                    TotalBuilt         = 38,
                    TotalRaceVictories = 2000,
                    SmallDescription   = "..."
                };
                t41 = new Car()
                {
                    //id
                    Name           = "Type 41 Royale",
                    Creator        = ettore,
                    StartBuildYear = new DateTime(1926, 1, 1),
                    StopBuildYear  = new DateTime(1933, 1, 1),
                    //Countries = ,
                    AvrgPrice          = 9500000,
                    Horsepower         = 300,
                    MaxSpeed           = 205,
                    Weight             = 3125,
                    Prototype          = false,
                    WorldRecords       = 1,
                    TotalBuilt         = 8,
                    TotalRaceVictories = 0,
                    SmallDescription   = "..."
                };
                t57 = new Car()
                {
                    //id
                    Name           = "Type 57 s/sc",
                    Creator        = jean,
                    StartBuildYear = new DateTime(1934, 1, 1),
                    StopBuildYear  = new DateTime(1940, 1, 1),
                    //Countries = ,
                    AvrgPrice          = 1400000,
                    Horsepower         = 180,
                    MaxSpeed           = 200,
                    Weight             = 950,
                    Prototype          = false,
                    WorldRecords       = 0,
                    TotalBuilt         = 685,
                    TotalRaceVictories = 0,
                    SmallDescription   = "..."
                };
                aero = new Car()
                {
                    //id
                    Name           = "Type 57 Aérolithe",
                    Creator        = jean,
                    StartBuildYear = new DateTime(1935, 1, 1),
                    StopBuildYear  = new DateTime(1935, 1, 1),
                    //Countries = ,
                    AvrgPrice          = 0,
                    Horsepower         = 180,
                    MaxSpeed           = 200,
                    Weight             = 0,
                    Prototype          = true,
                    WorldRecords       = 0,
                    TotalBuilt         = 1,
                    TotalRaceVictories = 0,
                    SmallDescription   = "..."
                };
                atl = new Car()
                {
                    //id
                    Name           = "Type 57 s(c) atlantic",
                    Creator        = jean,
                    StartBuildYear = new DateTime(1936, 1, 1),
                    StopBuildYear  = new DateTime(1938, 1, 1),
                    //CountryList = tempList,
                    AvrgPrice          = 40000000,
                    Horsepower         = 200,
                    MaxSpeed           = 200,
                    Weight             = 950,
                    Prototype          = false,
                    WorldRecords       = 1,
                    TotalBuilt         = 4,
                    TotalRaceVictories = 0,
                    SmallDescription   = "..."
                };
                veyr = new Car()
                {
                    //id
                    Name           = "veyron super sport",
                    Creator        = jozef,
                    StartBuildYear = new DateTime(2005, 1, 1),
                    StopBuildYear  = new DateTime(2015, 1, 1),
                    //Countries = ,
                    AvrgPrice          = 2000000,
                    Horsepower         = 1200,
                    MaxSpeed           = 431,
                    Weight             = 1838,
                    Prototype          = false,
                    WorldRecords       = 1,
                    TotalBuilt         = 30,
                    TotalRaceVictories = 0,
                    SmallDescription   = "..."
                };
                chir = new Car()
                {
                    //id
                    Name           = "chiron super sport",
                    Creator        = achim,
                    StartBuildYear = new DateTime(2019, 1, 1),
                    StopBuildYear  = new DateTime(1, 1, 1),
                    //Countries = ,
                    AvrgPrice          = 3500000,
                    Horsepower         = 1500,
                    MaxSpeed           = 490,
                    Weight             = 1995,
                    Prototype          = false,
                    WorldRecords       = 1,
                    TotalBuilt         = 30,
                    TotalRaceVictories = 0,
                    SmallDescription   = "..."
                };
                noire = new Car()
                {
                    //id
                    Name           = "La voiture noir",
                    Creator        = etienne,
                    StartBuildYear = new DateTime(2019, 1, 1),
                    StopBuildYear  = new DateTime(1, 1, 1),
                    //Countries = ,
                    AvrgPrice          = 16000000,
                    Horsepower         = 1500,
                    MaxSpeed           = 420,
                    Weight             = 0,
                    Prototype          = false,
                    WorldRecords       = 1,
                    TotalBuilt         = 1,
                    TotalRaceVictories = 0,
                    SmallDescription   = "..."
                };

                //add car to collection of cars
                context.Cars.Add(t35);
                context.Cars.Add(t41);
                context.Cars.Add(t57);
                context.Cars.Add(aero);
                context.Cars.Add(atl);
                context.Cars.Add(veyr);
                context.Cars.Add(chir);
                context.Cars.Add(noire);
                //save all the changes to the DB
                context.SaveChanges();
            }
            #endregion

            #region ---CAR-COUNTRIES---

            if (!context.CarCountries.Any())
            {
                atl_FR = new Car_Country_JoinTable()
                {
                    CarId     = atl.Id,
                    Car       = atl,
                    CountryId = france.Id,
                    Country   = france
                };
                atl_DE = new Car_Country_JoinTable()
                {
                    CarId     = atl.Id,
                    Car       = atl,
                    CountryId = germany.Id,
                    Country   = germany
                };
                t35_IT = new Car_Country_JoinTable()
                {
                    CarId     = t35.Id,
                    Car       = t35,
                    CountryId = italy.Id,
                    Country   = italy
                };
                t41_FR = new Car_Country_JoinTable()
                {
                    CarId     = t41.Id,
                    Car       = t41,
                    CountryId = france.Id,
                    Country   = france
                };
                t57_FR = new Car_Country_JoinTable()
                {
                    CarId     = t57.Id,
                    Car       = t57,
                    CountryId = france.Id,
                    Country   = france
                };
                aero_DE = new Car_Country_JoinTable()
                {
                    CarId     = aero.Id,
                    Car       = aero,
                    CountryId = germany.Id,
                    Country   = germany
                };
                veyr_FR = new Car_Country_JoinTable()
                {
                    CarId     = veyr.Id,
                    Car       = veyr,
                    CountryId = france.Id,
                    Country   = france
                };
                chir_IT = new Car_Country_JoinTable()
                {
                    CarId     = chir.Id,
                    Car       = chir,
                    CountryId = italy.Id,
                    Country   = italy
                };
                chir_FR = new Car_Country_JoinTable()
                {
                    CarId     = chir.Id,
                    Car       = chir,
                    CountryId = france.Id,
                    Country   = france
                };
                noire_FR = new Car_Country_JoinTable()
                {
                    CarId     = noire.Id,
                    Car       = noire,
                    CountryId = france.Id,
                    Country   = france
                };
            }
            context.CarCountries.Add(atl_FR);
            context.CarCountries.Add(atl_DE);
            context.CarCountries.Add(t35_IT);
            context.CarCountries.Add(t41_FR);
            context.CarCountries.Add(t57_FR);
            context.CarCountries.Add(aero_DE);
            context.CarCountries.Add(veyr_FR);
            context.CarCountries.Add(chir_FR);
            context.CarCountries.Add(chir_IT);
            context.CarCountries.Add(noire_FR);
            //save all the changes to the DB
            context.SaveChanges();
            #endregion

            //save all the changes to the DB
            context.SaveChanges();
        }