コード例 #1
0
ファイル: CategoryRepository.cs プロジェクト: brianweet/Test
 public void InsertOrUpdate(Category category)
 {
     if (category.CategoryId == default(int)) {
         // New entity
         context.Categories.Add(category);
     } else {
         // Existing entity
         context.Entry(category).State = EntityState.Modified;
     }
 }
コード例 #2
0
ファイル: CategoryController.cs プロジェクト: brianweet/Test
 public ActionResult Create(Category category)
 {
     if (ModelState.IsValid) {
         _categoryRepository.InsertOrUpdate(category);
         _categoryRepository.Save();
         return RedirectToAction("Index");
     } else {
         return View();
     }
 }