コード例 #1
0
 public int AddCategory(Category category)
 {
     using (var context = new EFSportsStoreContext())
     {
         context.Category.Add(category);
         context.SaveChanges();
     };
     return category.Id;
 }
コード例 #2
0
 public void SaveCategory(Category category)
 {
     if (category.CategoryID == 0)
     {
         context.Categories.Add(category);
     }
     else
     {
         context.Entry(category).State = EntityState.Modified;
     }
     context.SaveChanges();
 }
コード例 #3
0
 public ActionResult EditCategory(Category category)
 {
     if (ModelState.IsValid)
     {
         repository.SaveCategory(category);
         TempData["message"] = string.Format("{0} has been saved", category.Name);
         return RedirectToAction("Categories");
     }
     else
     {
         // there is something wrong with the data values
         return View(category);
     }
 }
コード例 #4
0
        public bool EditCategory(Category category)
        {
            var isUpdated = false;
            using (var context = new EFSportsStoreContext())
            {
                var existingcategory = GetExistingCategory(category.Id, context);
                if (existingcategory != null)
                {
                    existingcategory.Name = category.Name;

                    context.Entry(existingcategory).State = EntityState.Modified;
                    context.SaveChanges();
                    isUpdated = true;
                }
            }
            return isUpdated;
        }
コード例 #5
0
 public void Update(Category updatedCategory)
 {
     Name = updatedCategory.Name;
 }
コード例 #6
0
 public void DeleteCategory(Category category)
 {
     context.Categories.Remove(category);
     context.SaveChanges();
 }