コード例 #1
0
 public ActionResult Create(Cake cake)
 {
     if (ModelState.IsValid)
         {
             try{
                 db.Cakes.AddObject(cake);
             db.SaveChanges();
             return RedirectToAction("Index");
             }
             catch (System.Data.Entity.Validation.DbEntityValidationException)
             {
                 return RedirectToAction("Index");
             }
         }
     return View(cake);
 }
コード例 #2
0
 /// <summary>
 /// Create a new Cake object.
 /// </summary>
 /// <param name="cakeID">Initial value of the CakeID property.</param>
 public static Cake CreateCake(global::System.Int32 cakeID)
 {
     Cake cake = new Cake();
     cake.CakeID = cakeID;
     return cake;
 }
コード例 #3
0
 public ActionResult Edit(Cake cake)
 {
     if (ModelState.IsValid)
     {
         db.Cakes.Attach(cake);
         db.ObjectStateManager.ChangeObjectState(cake, EntityState.Modified);
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(cake);
 }
コード例 #4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Cakes EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCakes(Cake cake)
 {
     base.AddObject("Cakes", cake);
 }