コード例 #1
0
        public ActionResult Create(CategoryViewModel model)
        {
            try
            {
                Category newCategory = new Category();
                newCategory.Name = model.Name;

                ImagesContext.Categories.Add(newCategory);
                ImagesContext.SaveChanges();

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
コード例 #2
0
        public ActionResult Edit(CategoryViewModel model)
        {
            Category cat = ImagesContext.Categories.Where(c => c.Name == model.OldName).First();

            ImagesContext.Categories.Remove(cat);
            ImagesContext.SaveChanges();

            cat.Name = model.Name;
            ImagesContext.Categories.Add(cat);
            ImagesContext.SaveChanges();

            return RedirectToAction("Index");
        }
コード例 #3
0
        public ActionResult Edit(int id)
        {
            Category cat = ImagesContext.Categories.Where(c => c.CategoryID == id).First();
            CategoryViewModel category = new CategoryViewModel();

            category.Name = cat.Name;
            category.OldName = cat.Name;

            return PartialView(category);
        }