Ejemplo n.º 1
0
        public ActionResult Create(Category category)
        {
            if (ModelState.IsValid)
            {
                _categoryRepository.InsertOrUpdate(category);
                _categoryRepository.Save();
                return RedirectToAction("Index");
            }

            return View(category);
        }
Ejemplo n.º 2
0
 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;
     }
 }