public ActionResult Create([Bind(Include = "Id,Brand,Model,Year,Price,New")] Car car) { if (ModelState.IsValid) { carRepository.CreateCar(car, HttpContext.User.Identity.Name); return(RedirectToAction("Index")); } return(View(car)); }
//Create a car private void CreateCar() { Console.Clear(); Cars newCar = new Cars(); Console.WriteLine("Please enter the make of the car:"); newCar.Make = Console.ReadLine().ToLower(); Console.WriteLine("Please enter the model of the car:"); newCar.Model = Console.ReadLine().ToLower(); Console.WriteLine("Please enter the year the car was released:"); string input = Console.ReadLine(); int number; bool isNumber = Int32.TryParse(input, out number); if (isNumber == true) { newCar.Year = number; } else { Console.WriteLine("Please input a valid number\n" + "Press any key to continue"); Console.ReadKey(); CreateCar(); } Console.WriteLine("Please specify the fuel type of the vehicle (electric, hybrid, or gas):"); string fuelInput = Console.ReadLine().ToLower(); if (fuelInput == "electric") { newCar.TypeOfFuel = Cars.FuelType.Electric; } else if (fuelInput == "hybrid") { newCar.TypeOfFuel = Cars.FuelType.Hybrid; } else if (fuelInput == "gas") { newCar.TypeOfFuel = Cars.FuelType.Gas; } _carRepo.CreateCar(newCar, newCar.TypeOfFuel); }