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)); }
public IActionResult Create(Make make) { if (ModelState.IsValid) { _db.Add(make); _db.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(make)); }
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)); }
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(); } }