예제 #1
0
        public ActionResult Create([Bind(Include = "Id,Name,KilometersHourSpeed")] PlaneKind plane)
        {
            if (ModelState.IsValid)
            {
                db.Planes.Add(plane);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(plane));
        }
예제 #2
0
        public static void SeedData()
        {
            using (var context = new TuiContext())
            {
                context.Database.EnsureCreated();
                if (context.Tours.Any())
                {
                    return;
                }

                var countries = new Faker <Country>()
                                .RuleFor(x => x.Name, x => x.Address.Country())
                                .Generate(100);

                var cities = new Faker <City>()
                             .RuleFor(x => x.Name, x => x.Address.City())
                             .RuleFor(x => x.Country, x => x.PickRandom(countries))
                             .Generate(3000);

                var dateNow = DateTime.Now;
                var hotels  = new Faker <Hotel>()
                              .RuleFor(x => x.Address, x => $"{x.Address.StreetAddress()}, {x.Address.BuildingNumber()}")
                              .RuleFor(x => x.Name, x => x.Company.CompanyName())
                              .RuleFor(x => x.City, x => x.PickRandom(cities))
                              .RuleFor(x => x.YearOfCreation, x => x.Date.Past(50, dateNow).Year)
                              .Generate(60000);

                var apartmentTypes = new[] { "standard", "luxe", "deluxe" };
                var tours          = new Faker <Tour>()
                                     .RuleFor(x => x.Provider, "Tui")
                                     .RuleFor(x => x.ApartmentType, x => x.PickRandom(apartmentTypes))
                                     .RuleFor(x => x.DateDeparture, x => x.Date.Future())
                                     .RuleFor(x => x.DateArrival, (x, y) => x.Date.Soon(4, y.DateDeparture))
                                     .RuleFor(x => x.DateRegistration, (x, y) => x.Date.Soon(1, y.DateArrival))
                                     .RuleFor(x => x.NightCount, x => x.Random.Number(1, 20))
                                     .RuleFor(x => x.PricePerPerson, x => x.Random.Decimal(100, 1000))
                                     .RuleFor(x => x.AirlineName, x => x.Company.CompanyName())
                                     .RuleFor(x => x.RoomCapacity, x => x.Random.Number(1, 8))
                                     .RuleFor(x => x.CityDeparture, x => x.PickRandom(cities))
                                     .RuleFor(x => x.CityArrival, x => x.PickRandom(cities))
                                     .RuleFor(x => x.Hotel, x => x.PickRandom(hotels))
                                     .Generate(1000000);

                context.Tours.AddRange(tours);
                context.SaveChanges();
            }
        }
예제 #3
0
 public T Create(T model)
 {
     _context.Add(model);
     _context.SaveChanges();
     return(model);
 }