コード例 #1
0
ファイル: CarVariables.cs プロジェクト: nlarion/carForm
    public static void Main()
    {
      Car porsche = new Car("2014 Porsche 911",114991,7864,"/Content/img/911.jpg");
      Car.Save(porsche);

      Car ford = new Car("2011 Ford F450",55995,14241,"/Content/img/f450.jpg");
      Car.Save(ford);

      Car lexus = new Car("2013 Lexus RX 350",44700,20000,"/Content/img/lexus.jpg");
      Car.Save(lexus);

      Car mercedes = new Car("Mercedes Benz CLS550",39900,37979,"/Content/img/benz.JPG");
      Car.Save(mercedes);
    }
コード例 #2
0
ファイル: HomeModule.cs プロジェクト: Hreacon/CarDealer
    public HomeModule()
    {
      // Car bmw = new Car("BMW", "M3", 2003, 100000, 5000, "img/bmw.jpg");
      // bmw.Save(bmw);
      // bmw.Save(new Car("Porshe", "M3", 2003, 100000, 5000, "img/bmw.jpg"));

      Get["/"] = _ => {
        List<Car> listOfCars = Car.GetAllCars();
        // Console.WriteLine(listOfCars[1].getCar());
        return View["list_all_cars.cshtml", listOfCars];
      };
      Get["/car/{id}"] = parameters => {
        return View["car.cshtml", Car.getCarById(parameters.id)];
      };
      Get["/car/{id}/buy"] = parameters => {
        Car.buyCar(parameters.id);
        return View["list_all_cars.cshtml", Car.GetAllCars()];
      };
      Post["/addCar"] = _ => {
        // Get form data
        string fieldString = "year model make miles price pic"; // string of all the input names
        string[] fields = fieldString.Split(' '); // split the strings into array
        Dictionary<string, string> fieldData = new Dictionary<string,string>() {}; // Dictionary for the field data
        foreach(string field in fields) { // iterate through the array of fields
          fieldData.Add(field, Request.Form[field]);// store the field data in the dictionary
        }
        // foreach( KeyValuePair<string,string> row in fieldData ) { // write the field data to the console to see if it worked
        //   Console.WriteLine(row.Key + " " + row.Value);
        // }
        // Parse ints
        int milesInt = 0;
        int.TryParse(fieldData["miles"], out milesInt);
        int priceInt = 0;
        int.TryParse(fieldData["price"], out priceInt);
        int yearInt = 0;
        int.TryParse(fieldData["year"], out yearInt);

        // make a new car
        Car newCar = new Car(fieldData["make"], fieldData["model"], yearInt, milesInt, priceInt, fieldData["pic"]);
        newCar.Save(); // save the car to the list
        return View["list_all_cars.cshtml", Car.GetAllCars()]; // display list of all cars
      };
      Post["/search"] = _ => {
        string search = Request.Form["search"];
        return View["list_all_cars.cshtml", Car.searchByMakeModel(search)];
      };


    }
コード例 #3
0
ファイル: CarVariables.cs プロジェクト: nlarion/carForm
 public static void Save(Car car)
 {
   _carList.Add(car);
 }