コード例 #1
0
 public ActionResult Edit(Category category)
 {
     if (ModelState.IsValid)
     {
         context.Entry(category).State = EntityState.Modified;
         context.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(category);
 }
コード例 #2
0
        public ActionResult Create(Category category)
        {
            if (ModelState.IsValid)
            {
                context.Categories.Add(category);
                context.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(category);
        }
コード例 #3
0
        public virtual Category Categories_Save(int iD, string name)
        {
            //using (NuvolaResumeContext context = new NuvolaResumeContext())
            {
                Category item = new Category();

                if (iD > 0)
                {
                    //Find the item
                    item = _context.Categories.Include(x => x.CategoryItems).SingleOrDefault(x => x.ID == iD);
                }
                else
                {
                    //Create a new item, we don't have an ID
                    item = new Category();
                }

                //Update / Set properties
                item.Name = name;

                if (iD < 1)
                {
                    //Add the new item to the database
                    _context.Categories.Add(item);
                }

                _context.SaveChanges();

                return (item);
            }
        }