コード例 #1
0
 public ActionResult Create(SubcategoryViewModel model)
 {
     if (ModelState.IsValid)
     {
         subcategoryService.Create(model);
         return RedirectToAction("List", "Subcategory");
     }
     return View(model);
 }
コード例 #2
0
 public ActionResult Delete(SubcategoryViewModel model)
 {
     try
     {
         subcategoryService.Delete(model.SubcategoryId);
         return RedirectToAction("List", "Subcategory");
     }
     catch
     {
         return View();
     }
 }
コード例 #3
0
 public void Create(SubcategoryViewModel model)
 {
     Subcategory subcategory = new Subcategory
     {
         CategoryId = model.CategoryId,
         SubcategoryName = model.SubcategoryName
     };
     using (var context = new WebShopMVCContext())
     {
         context.Subcategories.Add(subcategory);
         context.SaveChanges();
     }
 }
コード例 #4
0
 public void Update(SubcategoryViewModel model)
 {
     using (var context = new WebShopMVCContext())
     {
         var subcategory = context.Subcategories.Find(model.SubcategoryId);
         subcategory.SubcategoryName = model.SubcategoryName;
         subcategory.CategoryId = model.CategoryId;
         context.SaveChanges();
     }
 }