コード例 #1
0
 public void InsertOrUpdate(Product products)
 {
     if (products.Id == default(int)) {
         // New entity
         context.Products.Add(products);
     } else {
         // Existing entity
         context.Products.Attach(products);
         context.Entry(products).State = EntityState.Modified;
     }
 }
コード例 #2
0
 public ActionResult Create(Product products)
 {
     if (ModelState.IsValid) {
         productsRepository.InsertOrUpdate(products);
         productsRepository.Save();
         return RedirectToAction("Index");
     } else {
         ViewBag.PossibleCategories = categoriesRepository.All;
         return View();
     }
 }