예제 #1
0
        public async Task <IActionResult> Create([Bind("Id,Name")] CarDealer carDealer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(carDealer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(carDealer));
        }
예제 #2
0
        public IActionResult Create(Make make)
        {
            if (ModelState.IsValid)
            {
                _db.Add(make);
                _db.SaveChanges();
                return(RedirectToAction(nameof(Index)));
            }

            return(View(make));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("Id,Model,Motor,EngineType,Year,Price,ManufacturerId,CarDealerId")] Car car)
        {
            if (ModelState.IsValid)
            {
                _context.Add(car);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CarDealerId"]    = new SelectList(_context.CarDealers, "Id", "Id", car.CarDealerId);
            ViewData["ManufacturerId"] = new SelectList(_context.Manufacturers, "Id", "Id", car.ManufacturerId);
            return(View(car));
        }
예제 #4
0
        private static void InsertData()
        {
            var cars = ProcessCar("/Users/javiermayorga/Documents/Dev/LINQFundamentalsC-sharp/LinqAndEntityFramework/src/LINQAndEntityFrameworkExample/context/fuel.csv");
            var db   = new CarsDbContext();

            db.Database.EnsureCreated();

            if (!db.Cars.Any())
            {
                foreach (var car in cars)
                {
                    db.Add(car);
                }
                db.SaveChanges();
            }
        }