Exemplo n.º 1
0
 public ActionResult Edit(CategoryModel category)
 {
     try
     {
         _categoryDataAccess.UpdateCategory(category);
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
Exemplo n.º 2
0
        public ActionResult Create(CategoryModel category)
        {
            try
            {
                _categoryDataAccess.AddCategory(category);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Exemplo n.º 3
0
        public void UpdateCategory(CategoryModel category)
        {
            using (var db = new EventSignInEntities())
            {
                var dbCategory = db.Categories.FirstOrDefault(c => c.Id == category.Id);

                if (dbCategory == null)
                {
                    throw new InvalidOperationException(string.Format("Could not find Category with ID: {0}", category.Id));
                }

                dbCategory.Name = category.Name;
                dbCategory.Description = category.Description;
                db.SaveChanges();
            }
        }
Exemplo n.º 4
0
        public int AddCategory(CategoryModel category)
        {
            using (var db = new EventSignInEntities())
            {
                var newCategory = new Category
                    {
                        Name = category.Name,
                        Description = category.Description
                    };

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

                return newCategory.Id;
            }
        }