コード例 #1
0
        public ActionResult Create(CarModel model)
        {
            if(ModelState.IsValid)
            {
                if (model.Id == 0)
                {

                    var newCar = new Car
                                     {
                                         Color = model.Color,
                                         OptionsMacroText = model.OptionsMacroText,
                                         Model = model.VehicleModel,
                                         Price = model.Price,
                                         SportsPackage = model.SportsPackage
                                     };

                    Repository.AddCar(newCar);
                    Repository.Context.SaveChanges();
                    model.Id = newCar.Id;
                    return View("Details", model);
                }
            }
            SetDropDownLists();
            return View("Create");
        }
コード例 #2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Cars EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCars(Car car)
 {
     base.AddObject("Cars", car);
 }
コード例 #3
0
 /// <summary>
 /// Create a new Car object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 public static Car CreateCar(global::System.Int32 id)
 {
     Car car = new Car();
     car.Id = id;
     return car;
 }