Esempio n. 1
0
 // public T Get(long id)
 // {
 //     return entities.SingleOrDefault(s => s. == id);
 // }
 public void Insert(T entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException("entity");
     }
     entities.Add(entity);
     context.SaveChanges();
 }
        public IActionResult Create([FromBody] Product item)
        {
            if (item == null)
            {
                return(BadRequest());
            }
            _context.Products.Add(item);
            _context.SaveChanges();

            return(CreatedAtRoute("GetProduct", new { id = item.Id }, item));
        }
Esempio n. 3
0
        public static void SeedModels(VegaDbContext context)
        {
            var make1Id = context.Makes.SingleOrDefault(make => make.Name == "Make1").Id;
            var make2Id = context.Makes.SingleOrDefault(make => make.Name == "Make2").Id;

            var models = new List <Model>
            {
                new Model {
                    Name = "Model 1 - Make 1", MakeId = make1Id
                },
                new Model {
                    Name = "Model 2 - Make 1", MakeId = make1Id
                },
                new Model {
                    Name = "Model 1 - Make 2", MakeId = make2Id
                },
                new Model {
                    Name = "Model 2 - Make 2", MakeId = make2Id
                },
            };

            if (!context.Models.Any())
            {
                context.Models.AddRange(models);
                context.SaveChanges();
            }
        }
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            var optionsBuilder = new DbContextOptionsBuilder <VegaDbContext>();

            optionsBuilder.UseSqlServer(ConnectionStringLocalDB);

            using (var db = new VegaDbContext(optionsBuilder.Options))
            {
                var africaTwin = db.Models.Where(m => m.Name == "CRF1000L Africa Twin").SingleOrDefault();
                if (africaTwin != null)
                {
                    db.Models.Remove(africaTwin);
                }

                var crf250Rally = db.Models.Where(m => m.Name == "CRF250 Rally").SingleOrDefault();
                if (crf250Rally != null)
                {
                    db.Models.Remove(crf250Rally);
                }

                var r1200RSport = db.Models.Where(m => m.Name == "R 1200 R Sport").SingleOrDefault();
                if (r1200RSport != null)
                {
                    db.Models.Remove(r1200RSport);
                }

                db.SaveChanges();
            }
        }
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            var optionsBuilder = new DbContextOptionsBuilder <VegaDbContext>();

            optionsBuilder.UseSqlServer(ConnectionStringLocalDB);

            using (var db = new VegaDbContext(optionsBuilder.Options))
            {
                var makes = db.Makes.ToList();

                var honda    = db.Makes.Where(x => x.Name == "Honda").Single();
                var yamaha   = db.Makes.Where(x => x.Name == "Yamaha").Single();
                var kawasaki = db.Makes.Where(x => x.Name == "Kawasaki").Single();
                var suzuki   = db.Makes.Where(x => x.Name == "Suzuki").Single();
                var ducati   = db.Makes.Where(x => x.Name == "Ducati").Single();
                var bmw      = db.Makes.Where(x => x.Name == "BMW").Single();
                var triumph  = db.Makes.Where(x => x.Name == "Triumph").Single();

                var models = db.Models.ToList();

                var zx10rNinja = db.Models.Add(new Model()
                {
                    Name             = "Ninja ZX-10R",
                    MakeId           = kawasaki.Id,
                    Make             = kawasaki,
                    Year             = 2017,
                    EngineType       = "Liquid-cooled, 4-stroke In-Line Four",
                    Displacement     = 998,
                    BoreAndStroke    = "76 x 55 mm",
                    CompressionRatio = "13.0:1",
                    MaxPower         = "147.1 kW {200 PS} / 13,000 rpm",
                    MaxTorque        = "113.5 N•m {11.6 kgf•m} / 11,500 rpm",
                    Lubrication      = "Forced lubrication, wet sump with oil cooler",
                    Carburettor      = "Fuel injection: Ø 47 mm x 4 with dual injection",
                    Starter          = "Electric",
                    Transmission     = "6-speed, cassette",
                    FinalDrive       = "Sealed chain",
                    FuelConsumption  = "5.9 l/100 km",
                    Frame            = "Twin spar, cast aluminium",
                    FrontSuspension  = "43 mm inverted fork with rebound and compression damping, spring preload adjustability and top-out springs",
                    RearSuspension   = "Horizontal Back-link with gas-charged shock and top-out spring. Compression damping: Stepless, dual-range (high/low-speed). Rebound damping: Stepless. Spring preload: Fully adjustable",
                    FrontBrake       = "Dual semi-floating 310 mm petal discs. Caliper: Dual radial-mount, opposed 4-(aluminium) piston",
                    RearBrake        = "Single 220 mm petal disc. Caliper: Single-bore pin-slide, aluminium piston",
                    FrontTyre        = "120/70ZR17M/C (58W)",
                    RearTyre         = "190/55ZR17M/C (75W)",
                    Length           = 2090,
                    Width            = 740,
                    Height           = 1145,
                    SeatHeight       = 835,
                    WheelBase        = 1440,
                    GroundClearance  = 145,
                    FuelCapacity     = 17,
                    WetWeight        = 206
                });

                db.SaveChanges();
            }
        }
            override public void InitializeVegaPlannerServerDbForTests(VegaDbContext db)
            {
                //service.InsertGenerator
                var testData = new SetupDefaultTestData(db);

                testData.CreateCustomer("TestUser1");
                testData.CreateProjectGeneratorsStates(noOfGenerators: 1, noOfStates: TestSettings.FiftyStates);
                db.SaveChanges();
            }
        public IActionResult Delete(int id)
        {
            var order = _context.Orders.FirstOrDefault(o => o.Id == id);

            if (order == null)
            {
                return(NotFound());
            }
            _context.Orders.Remove(order);
            _context.SaveChanges();
            return(new NoContentResult());
        }
        public User Create(User user, string password)
        {
            // validation
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new AppException("Password is required");
            }

            if (_context.Users.Any(x => x.Username == user.Username))
            {
                throw new AppException("Username " + user.Username + " is already taken");
            }

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            _context.Users.Add(user);
            _context.SaveChanges();

            return(user);
        }
Esempio n. 9
0
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            var optionsBuilder = new DbContextOptionsBuilder <VegaDbContext>();

            optionsBuilder.UseSqlServer(ConnectionStringLocalDB);

            using (var db = new VegaDbContext(optionsBuilder.Options))
            {
                var makes = db.Makes.ToList();
                if (makes.Any())
                {
                    db.Makes.RemoveRange(makes);
                    db.SaveChanges();
                }
            }
        }
Esempio n. 10
0
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            var optionsBuilder = new DbContextOptionsBuilder <VegaDbContext>();

            optionsBuilder.UseSqlServer(ConnectionStringLocalDB);

            using (var db = new VegaDbContext(optionsBuilder.Options))
            {
                var zx10rNinja = db.Models.Where(m => m.Name == "Ninja ZX-10R").SingleOrDefault();
                if (zx10rNinja != null)
                {
                    db.Models.Remove(zx10rNinja);
                    db.SaveChanges();
                }
            }
        }
Esempio n. 11
0
        public static void SeedMakes(VegaDbContext context)
        {
            var makes = new List <Make>
            {
                new Make {
                    Name = "Make1"
                },
                new Make {
                    Name = "Make2"
                }
            };

            if (!context.Makes.Any())
            {
                context.Makes.AddRange(makes);
                context.SaveChanges();
            }
        }
Esempio n. 12
0
        public static void SeedFeatures(VegaDbContext context)
        {
            var features = new List <Feature>
            {
                new Feature {
                    Name = "Feature1"
                },
                new Feature {
                    Name = "Feature2"
                },
                new Feature {
                    Name = "Feature3"
                }
            };

            if (!context.Features.Any())
            {
                context.Features.AddRange(features);
                context.SaveChanges();
            }
        }
        public VegaDbContext CreateCustomer(string userName)
        {
            var testCustomer = new Customer()
            {
                CustomerAddress = new Address {
                    AddressLine1 = "Test Address Line 1",
                    Postcode     = "TST A01",
                    City         = "TST CITY 1",
                    County       = "TST County 1"
                },

                CustomerContact = new Contact {
                    FirstName       = "TST First Name",
                    LastName        = userName,
                    TelephoneMobile = "9999999999999"
                }
            };

            db.Customers.Add(testCustomer);
            db.SaveChanges();
            return(db);
        }
Esempio n. 14
0
 public void Complete()
 {
     vegaDbContext.SaveChanges();
 }
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            var optionsBuilder = new DbContextOptionsBuilder <VegaDbContext>();

            optionsBuilder.UseSqlServer(ConnectionStringLocalDB);

            using (var db = new VegaDbContext(optionsBuilder.Options))
            {
                var makes = db.Makes.ToList();

                var honda    = db.Makes.Where(x => x.Name == "Honda").Single();
                var yamaha   = db.Makes.Where(x => x.Name == "Yamaha").Single();
                var kawasaki = db.Makes.Where(x => x.Name == "Kawasaki").Single();
                var suzuki   = db.Makes.Where(x => x.Name == "Suzuki").Single();
                var ducati   = db.Makes.Where(x => x.Name == "Ducati").Single();
                var bmw      = db.Makes.Where(x => x.Name == "BMW").Single();
                var triumph  = db.Makes.Where(x => x.Name == "Triumph").Single();

                var models = db.Models.ToList();

                var africaTwin = db.Models.Add(new Model()
                {
                    Name             = "CRF1000L Africa Twin",
                    MakeId           = honda.Id,
                    Make             = honda,
                    Year             = 2017,
                    EngineType       = "998cc liquid-cooled 4-stroke Unicam 8-valve Parallel Twin with 270º crank",
                    Displacement     = 998,
                    BoreAndStroke    = "92mm x 75mm",
                    CompressionRatio = "10:1",
                    MaxPower         = "70kW/7,500rpm (95/1/EC)",
                    MaxTorque        = "98Nm/6,000rpm (95/1/EC)",
                    Lubrication      = "Forced lubrication, wet sump with oil cooler",
                    ClutchType       = "Wet, multi-plate with coil springs, aluminum cam assist and slipper clutch",
                    Starter          = "Electric",
                    Transmission     = "Constant mesh 6-speed MT",
                    FinalDrive       = "O-ring sealed chain",
                    FuelConsumption  = "21.7 km/l (WMTC)",
                    Frame            = "Steel semi-double cradle type with high-tensile strength steel rear sub-frame",
                    FrontSuspension  = "Show 45mm cartridge-type inverted telescopic fork with dial-style preload adjuster and DF adjustment, 230mm stroke",
                    RearSuspension   = "Monoblock cast aluminium swing arm with Pro-Link with gas-charged damper, hydraulic dial-style preload adjuster and rebound damping adjustment, 220 mm rear wheel travel",
                    FrontBrake       = "310mm dual wave floating hydraulic disc with aluminum hub and radial fit 4-piston calipers and sintered metal pads",
                    RearBrake        = "256mm wave hydraulic disc with 2-piston caliper and sintered metal pads",
                    FrontTyre        = "90/90-R21 tube type",
                    RearTyre         = "150/70-R18 tube type",
                    Length           = 2335,
                    Width            = 930,
                    Height           = 1475,
                    SeatHeight       = 850,
                    WheelBase        = 1440,
                    GroundClearance  = 250,
                    FuelCapacity     = 18.8,
                    WetWeight        = 232
                });

                var crf250Rally = db.Models.Add(new Model()
                {
                    Name             = "CRF250 Rally",
                    MakeId           = honda.Id,
                    Make             = honda,
                    Year             = 2017,
                    EngineType       = "Liquid-cooled, Single, DOHC",
                    Displacement     = 250,
                    BoreAndStroke    = "76.0 x 55.0",
                    CompressionRatio = "10.7:1",
                    MaxPower         = "18.2kW/8500rpm",
                    MaxTorque        = "22.6Nm/6750rpm",
                    ClutchType       = "Wet multiplate hydraulic",
                    Carburettor      = "PGM-FI",
                    Starter          = "Electric",
                    Transmission     = "6-speed",
                    FinalDrive       = "Chain",
                    FuelConsumption  = "33.3km/litre",
                    Frame            = "Steel Twin Tube",
                    FrontSuspension  = "43mm Telescopic Upsidedown",
                    RearSuspension   = "Prolink",
                    FrontTyre        = "3.00-21 51P",
                    RearTyre         = "120/80-18M/C 62P",
                    Length           = 2210,
                    Width            = 900,
                    Height           = 1425,
                    SeatHeight       = 895,
                    WheelBase        = 1455,
                    GroundClearance  = 270,
                    FuelCapacity     = 10.1,
                    WetWeight        = 157
                });

                var r1200rSport = db.Models.Add(new Model()
                {
                    Name             = "R 1200 R Sport",
                    MakeId           = bmw.Id,
                    Make             = bmw,
                    Year             = 2017,
                    EngineType       = "Air/oil-cooled, Boxer twin",
                    Displacement     = 1170,
                    BoreAndStroke    = "101.0 x 73.0 mm",
                    CompressionRatio = "12.5:1",
                    MaxPower         = "125 bhp at 7,750 rpm",
                    MaxTorque        = "125 Nm at 6,500 rpm",
                    Lubrication      = "Dry sump",
                    ClutchType       = "Wet eight-disc clutch with anti-hopping function, hydraulically operated",
                    Carburettor      = "Injection. Digital engine management with electronic fuel injection, electronic throttle valve control (fly by wire)",
                    Starter          = "Electric",
                    Transmission     = "6-speed",
                    FinalDrive       = "Shaft drive (cardan)",
                    Frame            = "Two-section frame, front- and bolted on rear frame, load-bearing engine",
                    FrontSuspension  = "Upside-down telescopic fork. diameter 45 mm, silver-anodized",
                    RearSuspension   = "BMW Motorrad EVO Paralever",
                    FrontBrake       = "Double disc. ABS. Four-piston calipers",
                    RearBrake        = "Single disc. ABS. Floating disc. Two-piston calipers.",
                    FrontTyre        = "120/70-ZR17",
                    RearTyre         = "180/55-ZR17",
                    Length           = 2165,
                    Width            = 880,
                    Height           = 1300,
                    SeatHeight       = 790,
                    WheelBase        = 1515,
                    GroundClearance  = 270,
                    FuelCapacity     = 18,
                    WetWeight        = 232
                });

                db.SaveChanges();
            }
        }
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            var optionsBuilder = new DbContextOptionsBuilder <VegaDbContext>();

            optionsBuilder.UseSqlServer(ConnectionStringLocalDB);

            using (var db = new VegaDbContext(optionsBuilder.Options))
            {
                var models = db.Models.ToList();

                var mt10Sp          = models.Where(m => m.Name == "MT10SP").Single();
                var scr950          = models.Where(m => m.Name == "SCR950").Single();
                var streetScrambler = models.Where(m => m.Name == "Street Scrambler").Single();
                var zx10rNinja      = models.Where(m => m.Name == "Ninja ZX-10R").Single();
                var africaTwin      = models.Where(m => m.Name == "CRF1000L Africa Twin").Single();
                var crf250Rally     = models.Where(m => m.Name == "CRF250 Rally").Single();
                var r1200rSport     = models.Where(m => m.Name == "R 1200 R Sport").Single();

                var crossplaneEngine = db.Features.Add(new Feature()
                {
                    Name        = "Latest Generation Crossplane Crankshaft Engine",
                    Description = "The potent 998cc inline 4-cylinder engine features the same Crossplane Crankshaft technology "
                                  + "developed in Yamaha’s renowned YZF-R1 superbike. Tuned specifically for the FZ-10™, this engine "
                                  + "develops awesome low- and mid-rpm torque with arm-stretching top-end power."
                });
                var ycct = db.Features.Add(new Feature()
                {
                    Name        = "Yamaha Chip Controlled Throttle with D-MODE and Cruise Control",
                    Description = "The FZ-10 features YCC-T®—a ride-by-wire throttle system that provides exceptionally precise "
                                  + "engine control—and D-MODE, which allows the rider to select a preferred engine response at the flick of "
                                  + "a switch. The FZ-10 also includes cruise control for improved highway cruising comfort."
                });
                var tractionControl = db.Features.Add(new Feature()
                {
                    Name        = "Traction Control System",
                    Description = "An advanced Traction Control System (TCS) assists the rider in managing traction on various road "
                                  + "conditions by quickly modulating throttle opening, ignition timing, fuel volume and other parameters."
                });
                var deltaboxFrame = db.Features.Add(new Feature()
                {
                    Name        = "Deltabox® Aluminum Frame",
                    Description = "Like the YZF-R1® superbike, the FZ-10 uses an aluminum Deltabox frame to create a lightweight "
                                  + "and responsive chassis built for agility, featuring an ultra-compact 55.1-inch wheelbase."
                });
                var kybSuspension = db.Features.Add(new Feature()
                {
                    Name        = "Fully-Adjustable KYB® Suspension",
                    Description = "The FZ-10 features a fully-adjustable inverted KYB® front fork and a four-way-adjustable, "
                                  + "linkage-type KYB® shock, for excellent road holding along with a tuning range ready for a wide range of "
                                  + "street conditions."
                });
                var abs = db.Features.Add(new Feature()
                {
                    Name        = "Powerful, Controllable Brakes with ABS",
                    Description = "An advanced Anti-lock Braking System (ABS) is mated to high-specification braking components "
                                  + "for strong braking power with excellent feedback and control."
                });
                var agressiveEgonomics = db.Features.Add(new Feature()
                {
                    Name        = "Aggressive Ergonomics and Styling",
                    Description = "The FZ-10 displays raw aggression from every angle, with upright ergonomics that perfectly balance "
                                  + "sport riding feedback and relaxed comfort. High-tech LED lighting and an all-LCD instrument panel boost both "
                                  + "style and function."
                });
                var inclineDetection = db.Features.Add(new Feature()
                {
                    Name        = "Incline Detection",
                    Description = "While you're riding uphill, upshifts are delayed to keep rpm in the thicker part of the powerband."
                });
                var sixSpeed = db.Features.Add(new Feature()
                {
                    Name        = "6-speed manual gearbox",
                    Description = ""
                });
                var dct = db.Features.Add(new Feature()
                {
                    Name        = "Dual-Clutch Transmission",
                    Description = "Optional dual-clutch transmission that allows for fully automatic shifting."
                });
                var offRoad = db.Features.Add(new Feature()
                {
                    Name        = "Off-road ability",
                    Description = ""
                });
                var titaniumValves = db.Features.Add(new Feature()
                {
                    Name        = "Titanium intake valves",
                    Description = ""
                });
                var quickshifter = db.Features.Add(new Feature()
                {
                    Name        = "Quickshifter",
                    Description = ""
                });
                var boschImu = db.Features.Add(new Feature()
                {
                    Name        = "Bosch 5-axis IMU",
                    Description = ""
                });
                var klcm = db.Features.Add(new Feature()
                {
                    Name        = "Kawasaki Launch Control Mode",
                    Description = ""
                });
                var brakeLight = db.Features.Add(new Feature()
                {
                    Name        = "Dynamic Brake Light",
                    Description = ""
                });
                var shaftDrive = db.Features.Add(new Feature()
                {
                    Name        = "Shaft drive",
                    Description = ""
                });
                var spokedWheels = db.Features.Add(new Feature()
                {
                    Name        = "Spoked Wheels",
                    Description = ""
                });
                var stabilityControl = db.Features.Add(new Feature()
                {
                    Name        = "Automatic Stability Control",
                    Description = ""
                });
                var leds = db.Features.Add(new Feature()
                {
                    Name        = "LED Indicators",
                    Description = ""
                });

                db.SaveChanges();

                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = crossplaneEngine.Entity,
                    FeatureId = crossplaneEngine.Entity.Id,
                    Model     = mt10Sp,
                    ModelId   = mt10Sp.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = ycct.Entity,
                    FeatureId = ycct.Entity.Id,
                    Model     = mt10Sp,
                    ModelId   = mt10Sp.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = tractionControl.Entity,
                    FeatureId = tractionControl.Entity.Id,
                    Model     = mt10Sp,
                    ModelId   = mt10Sp.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = tractionControl.Entity,
                    FeatureId = tractionControl.Entity.Id,
                    Model     = zx10rNinja,
                    ModelId   = zx10rNinja.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = tractionControl.Entity,
                    FeatureId = tractionControl.Entity.Id,
                    Model     = r1200rSport,
                    ModelId   = r1200rSport.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = tractionControl.Entity,
                    FeatureId = tractionControl.Entity.Id,
                    Model     = africaTwin,
                    ModelId   = africaTwin.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = deltaboxFrame.Entity,
                    FeatureId = deltaboxFrame.Entity.Id,
                    Model     = mt10Sp,
                    ModelId   = mt10Sp.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = kybSuspension.Entity,
                    FeatureId = kybSuspension.Entity.Id,
                    Model     = mt10Sp,
                    ModelId   = mt10Sp.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = kybSuspension.Entity,
                    FeatureId = kybSuspension.Entity.Id,
                    Model     = streetScrambler,
                    ModelId   = streetScrambler.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = abs.Entity,
                    FeatureId = abs.Entity.Id,
                    Model     = mt10Sp,
                    ModelId   = mt10Sp.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = abs.Entity,
                    FeatureId = abs.Entity.Id,
                    Model     = streetScrambler,
                    ModelId   = streetScrambler.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = abs.Entity,
                    FeatureId = abs.Entity.Id,
                    Model     = zx10rNinja,
                    ModelId   = zx10rNinja.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = abs.Entity,
                    FeatureId = abs.Entity.Id,
                    Model     = africaTwin,
                    ModelId   = africaTwin.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = abs.Entity,
                    FeatureId = abs.Entity.Id,
                    Model     = crf250Rally,
                    ModelId   = crf250Rally.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = abs.Entity,
                    FeatureId = abs.Entity.Id,
                    Model     = r1200rSport,
                    ModelId   = r1200rSport.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = agressiveEgonomics.Entity,
                    FeatureId = agressiveEgonomics.Entity.Id,
                    Model     = mt10Sp,
                    ModelId   = mt10Sp.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = inclineDetection.Entity,
                    FeatureId = inclineDetection.Entity.Id,
                    Model     = africaTwin,
                    ModelId   = africaTwin.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = sixSpeed.Entity,
                    FeatureId = sixSpeed.Entity.Id,
                    Model     = mt10Sp,
                    ModelId   = mt10Sp.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = sixSpeed.Entity,
                    FeatureId = sixSpeed.Entity.Id,
                    Model     = zx10rNinja,
                    ModelId   = zx10rNinja.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = sixSpeed.Entity,
                    FeatureId = sixSpeed.Entity.Id,
                    Model     = africaTwin,
                    ModelId   = africaTwin.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = sixSpeed.Entity,
                    FeatureId = sixSpeed.Entity.Id,
                    Model     = r1200rSport,
                    ModelId   = r1200rSport.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = dct.Entity,
                    FeatureId = dct.Entity.Id,
                    Model     = africaTwin,
                    ModelId   = africaTwin.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = offRoad.Entity,
                    FeatureId = offRoad.Entity.Id,
                    Model     = africaTwin,
                    ModelId   = africaTwin.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = offRoad.Entity,
                    FeatureId = offRoad.Entity.Id,
                    Model     = streetScrambler,
                    ModelId   = streetScrambler.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = offRoad.Entity,
                    FeatureId = offRoad.Entity.Id,
                    Model     = crf250Rally,
                    ModelId   = crf250Rally.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = titaniumValves.Entity,
                    FeatureId = titaniumValves.Entity.Id,
                    Model     = zx10rNinja,
                    ModelId   = zx10rNinja.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = quickshifter.Entity,
                    FeatureId = quickshifter.Entity.Id,
                    Model     = mt10Sp,
                    ModelId   = mt10Sp.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = quickshifter.Entity,
                    FeatureId = quickshifter.Entity.Id,
                    Model     = zx10rNinja,
                    ModelId   = zx10rNinja.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = quickshifter.Entity,
                    FeatureId = quickshifter.Entity.Id,
                    Model     = r1200rSport,
                    ModelId   = r1200rSport.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = boschImu.Entity,
                    FeatureId = boschImu.Entity.Id,
                    Model     = zx10rNinja,
                    ModelId   = zx10rNinja.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = klcm.Entity,
                    FeatureId = klcm.Entity.Id,
                    Model     = zx10rNinja,
                    ModelId   = zx10rNinja.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = brakeLight.Entity,
                    FeatureId = brakeLight.Entity.Id,
                    Model     = r1200rSport,
                    ModelId   = r1200rSport.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = shaftDrive.Entity,
                    FeatureId = shaftDrive.Entity.Id,
                    Model     = r1200rSport,
                    ModelId   = r1200rSport.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = spokedWheels.Entity,
                    FeatureId = spokedWheels.Entity.Id,
                    Model     = streetScrambler,
                    ModelId   = streetScrambler.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = spokedWheels.Entity,
                    FeatureId = spokedWheels.Entity.Id,
                    Model     = africaTwin,
                    ModelId   = africaTwin.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = spokedWheels.Entity,
                    FeatureId = spokedWheels.Entity.Id,
                    Model     = crf250Rally,
                    ModelId   = crf250Rally.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = stabilityControl.Entity,
                    FeatureId = stabilityControl.Entity.Id,
                    Model     = r1200rSport,
                    ModelId   = r1200rSport.Id
                });
                db.ModelFeatures.Add(new ModelFeature()
                {
                    Feature   = leds.Entity,
                    FeatureId = leds.Entity.Id,
                    Model     = r1200rSport,
                    ModelId   = r1200rSport.Id
                });

                db.SaveChanges();
            }
        }
Esempio n. 17
0
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            var optionsBuilder = new DbContextOptionsBuilder <VegaDbContext>();

            optionsBuilder.UseSqlServer(ConnectionStringLocalDB);

            using (var db = new VegaDbContext(optionsBuilder.Options))
            {
                var makes = db.Makes.ToList();
                if (!makes.Any())
                {
                    db.Makes.Add(new Make()
                    {
                        Name = "Honda", Country = "Japan"
                    });
                    db.Makes.Add(new Make()
                    {
                        Name = "Kawasaki", Country = "Japan"
                    });
                    db.Makes.Add(new Make()
                    {
                        Name = "Yamaha", Country = "Japan"
                    });
                    db.Makes.Add(new Make()
                    {
                        Name = "Suzuki", Country = "Japan"
                    });
                    db.Makes.Add(new Make()
                    {
                        Name = "KTM", Country = "Austria"
                    });
                    db.Makes.Add(new Make()
                    {
                        Name = "Ducati", Country = "Italy"
                    });
                    db.Makes.Add(new Make()
                    {
                        Name = "BMW", Country = "Germany"
                    });
                    db.Makes.Add(new Make()
                    {
                        Name = "Triumph", Country = "United Kingdom"
                    });
                    db.Makes.Add(new Make()
                    {
                        Name = "Harley Davidson", Country = "USA"
                    });
                    db.Makes.Add(new Make()
                    {
                        Name = "Aprilia", Country = "Italy"
                    });

                    db.SaveChanges();
                }

                var honda    = db.Makes.Where(x => x.Name == "Honda").Single();
                var yamaha   = db.Makes.Where(x => x.Name == "Yamaha").Single();
                var kawasaki = db.Makes.Where(x => x.Name == "Kawasaki").Single();
                var suzuki   = db.Makes.Where(x => x.Name == "Suzuki").Single();
                var ducati   = db.Makes.Where(x => x.Name == "Ducati").Single();
                var bmw      = db.Makes.Where(x => x.Name == "BMW").Single();
                var triumph  = db.Makes.Where(x => x.Name == "Triumph").Single();

                var models = db.Models.ToList();
                if (!models.Any())
                {
                    var mt10Sp = db.Models.Add(new Model()
                    {
                        Name             = "MT10SP",
                        MakeId           = yamaha.Id,
                        Make             = yamaha,
                        Year             = 2017,
                        EngineType       = "liquid-cooled, 4-stroke, DOHC, 4-valves",
                        Displacement     = 998,
                        BoreAndStroke    = "79.0 mm x 50.9 mm",
                        CompressionRatio = "12 : 1",
                        MaxPower         = "118.0 kW (160.4PS) @ 11,500 rpm",
                        MaxTorque        = "111.0 Nm (11.3 kg-m) @ 9,000 rpm",
                        Lubrication      = "Wet sump",
                        ClutchType       = "Wet, Multiple Disc",
                        Carburettor      = "Fuel Injection",
                        Ignition         = "TCI",
                        Starter          = "Electric",
                        Transmission     = "Constant Mesh, 6-speed",
                        FinalDrive       = "Chain",
                        FuelConsumption  = "8.0 l/100km",
                        Frame            = "Aluminium Deltabox",
                        FrontSuspension  = "Telescopic forks, Ø 43 mm",
                        RearSuspension   = "Swingarm, (link suspension)",
                        FrontBrake       = "Hydraulic dual disc, Ø 320 mm",
                        RearBrake        = "Hydraulic single disc, Ø 220 mm",
                        FrontTyre        = "20/70 ZR17 M/C (58W)",
                        RearTyre         = "190/55 ZR17 M/C (75W)",
                        Length           = 2095,
                        Width            = 800,
                        Height           = 1110,
                        SeatHeight       = 825,
                        WheelBase        = 1400,
                        GroundClearance  = 130,
                        FuelCapacity     = 17,
                        WetWeight        = 210
                    });

                    var scr950 = db.Models.Add(new Model()
                    {
                        Name             = "SCR950",
                        MakeId           = yamaha.Id,
                        Make             = yamaha,
                        Year             = 2017,
                        EngineType       = "4-stroke, air-cooled, 4-valves, SOHC, V-type 2-cylinder",
                        Displacement     = 942,
                        BoreAndStroke    = "85.0 mm x 83.0 mm",
                        CompressionRatio = "9.0 : 1",
                        MaxPower         = "40 kW (54.3PS) @ 5,500 rpm",
                        MaxTorque        = "79.5 Nm (8.1 kg-m) @ 3,000 rpm",
                        Lubrication      = "Wet sump",
                        ClutchType       = "Wet, Multiple Disc",
                        Carburettor      = "Fuel Injection",
                        Ignition         = "TCI",
                        Starter          = "Electric",
                        Transmission     = "Constant Mesh, 5-speed",
                        FinalDrive       = "Belt",
                        FuelConsumption  = "5.0 l/100km",
                        Frame            = "double cradle",
                        FrontSuspension  = "Telescopic forks, Ø 41 mm",
                        RearSuspension   = "Swingarm",
                        FrontBrake       = "Hydraulic single disc, Ø 298 mm",
                        RearBrake        = "Hydraulic single disc, Ø 298 mm",
                        FrontTyre        = "100/90-19M/C 57H",
                        RearTyre         = "140/80R17M/C 69H",
                        Length           = 2255,
                        Width            = 895,
                        Height           = 1170,
                        SeatHeight       = 830,
                        WheelBase        = 1575,
                        GroundClearance  = 145,
                        FuelCapacity     = 13,
                        WetWeight        = 252
                    });

                    var streetScrambler = db.Models.Add(new Model()
                    {
                        Name             = "Street Scrambler",
                        MakeId           = triumph.Id,
                        Make             = triumph,
                        Year             = 2017,
                        EngineType       = "Liquid cooled, 8 valve, SOHC, 270° crank angle parallel twin",
                        Displacement     = 900,
                        BoreAndStroke    = "84.6 mm x 80 mm",
                        CompressionRatio = "10.55: 1",
                        MaxPower         = "55 PS / 54 BHP (40.5kW) @ 6000 rpm",
                        MaxTorque        = "80Nm @ 2850 rpm",
                        Carburettor      = "Fuel Injection",
                        Starter          = "Electric",
                        Transmission     = "5-speed",
                        FinalDrive       = "Chain",
                        FrontBrake       = "Single 310mm solid disc, 2-piston Nissin floating caliper, ABS",
                        RearBrake        = "Single 255mm disc, Nissin 2-piston floating caliper, ABS",
                        FrontTyre        = "100/90-19 Metzler Tourance",
                        RearTyre         = "150/70 R17 Metzler Tourance",
                        Length           = 2178,
                        Width            = 831,
                        Height           = 1120,
                        SeatHeight       = 792,
                        WheelBase        = 1446,
                        GroundClearance  = 145,
                        FuelCapacity     = 12,
                        WetWeight        = 213
                    });

                    db.SaveChanges();
                }
            }
        }
Esempio n. 18
0
 public void Complete()
 {
     context.SaveChanges();
 }
Esempio n. 19
0
 public void AddVehicle(Vehicle vehicle)
 {
     context.Vehicles.Add(vehicle);
     context.SaveChanges();
 }
Esempio n. 20
0
        public static void SeedDefaultData(VegaDbContext _ctx)
        {
            if (!_ctx.Manufacturers.Any())
            {
                List <Manufacturer> manufacturers = new List <Manufacturer>
                {
                    new Manufacturer
                    {
                        Name = "BMW"
                    },
                    new Manufacturer
                    {
                        Name = "Mercedes"
                    },
                    new Manufacturer
                    {
                        Name = "Audi"
                    },
                    new Manufacturer
                    {
                        Name = "Mitsubishi"
                    },
                    new Manufacturer
                    {
                        Name = "Lamborghini"
                    }
                };
                _ctx.Manufacturers.AddRange(manufacturers);
                _ctx.SaveChanges();



                //manufacturers.ForEach(delegate (Manufacturer manufacturer)
                //{
                //    if (manufacturer == bmw)
                //    {
                //        manufacturer.Models = new List<Model>
                //        {
                //            new Model
                //            {
                //                Name = "I8",
                //                ManufacturerId = manufacturer.Id
                //            },
                //            new Model
                //            {
                //                Name = "X3",
                //                ManufacturerId = manufacturer.Id
                //            },
                //            new Model
                //            {
                //                Name = "M3",
                //                ManufacturerId = manufacturer.Id
                //            }
                //        };
                //    }
                //    if (manufacturer == mercedes)
                //    {
                //        manufacturer.Models = new List<Model>
                //        {
                //            new Model
                //            {
                //                Name = "S Class",
                //                ManufacturerId = manufacturer.Id
                //            },
                //            new Model
                //            {
                //                Name = "C Class",
                //                ManufacturerId = manufacturer.Id
                //            }
                //        };
                //    }
                //    if (manufacturer == audi)
                //    {
                //        manufacturer.Models = new List<Model>
                //        {
                //            new Model
                //            {
                //                Name = "A3",
                //                ManufacturerId = manufacturer.Id
                //            },
                //            new Model
                //            {
                //                Name = "A4",
                //                ManufacturerId = manufacturer.Id
                //            }
                //        };
                //    }
                //});

                //var bmwId = _ctx.Manufacturers.Where(m => m.Name == "BMW").Select(m => m.Id).FirstOrDefault();
                //var mercedesId = _ctx.Manufacturers.Where(m => m.Name == "Mercedes").Select(m => m.Id).FirstOrDefault();
                //var audiId = _ctx.Manufacturers.Where(m => m.Name == "Audi").Select(m => m.Id).FirstOrDefault();

                var bmw      = _ctx.Manufacturers.Where(m => m.Name == "BMW").FirstOrDefault();
                var mercedes = _ctx.Manufacturers.Where(m => m.Name == "Mercedes").FirstOrDefault();
                var audi     = _ctx.Manufacturers.Where(m => m.Name == "Audi").FirstOrDefault();

                // now add models
                ICollection <Model> models = new Collection <Model>
                {
                    new Model
                    {
                        Name           = "I8",
                        ManufacturerId = bmw.Id,
                        Manufacturer   = bmw
                    },
                    new Model
                    {
                        Name           = "X3",
                        ManufacturerId = bmw.Id,
                        Manufacturer   = bmw
                    },
                    new Model
                    {
                        Name           = "M3",
                        ManufacturerId = bmw.Id,
                        Manufacturer   = bmw
                    },
                    new Model
                    {
                        Name           = "A3",
                        ManufacturerId = audi.Id,
                        Manufacturer   = audi
                    },
                    new Model
                    {
                        Name           = "A4",
                        ManufacturerId = audi.Id,
                        Manufacturer   = audi
                    },
                    new Model
                    {
                        Name           = "S Class",
                        ManufacturerId = mercedes.Id,
                        Manufacturer   = mercedes
                    },
                    new Model
                    {
                        Name           = "C Class",
                        ManufacturerId = mercedes.Id,
                        Manufacturer   = mercedes
                    }
                };

                _ctx.Models.AddRange(models);
                _ctx.SaveChanges();
            }
        }
Esempio n. 21
0
 public void saveChanges()
 {
     context.SaveChanges();
 }