Ejemplo n.º 1
0
 public void AddCategory(CategoryModel category)
 {
     if (category.Description == null)
         category.Description = "";
     context.CategoryModels.InsertOnSubmit(category);
     context.SubmitChanges();
 }
Ejemplo n.º 2
0
        public void EditCategory(int id, CategoryModel category)
        {
            var cat = context.CategoryModels.Single(c => c.ID == id);
            cat.Name = category.Name;
            if (category.Description != null)
                cat.Description = category.Description;
            else
                cat.Description = "";

            context.SubmitChanges();
        }
Ejemplo n.º 3
0
 public ActionResult Create(CategoryModel category)
 {
     try
     {
         if (ModelState.IsValid)
         {
             categories.AddCategory(category);
             if(Request.IsAjaxRequest())
                 return Json(new { success = true, name = category.Name, id = category.ID });
             return RedirectToAction("Index", new { id=category.ID });
         }
         if (Request.IsAjaxRequest())
             return Json(new { success = false, errors = ModelState.Values.SelectMany(v => v.Errors) });
         return View(category);
     }
     catch(Exception e)
     {
         if (Request.IsAjaxRequest())
             return Json(new { success = false, error = e.Message });
         return View();
     }
 }
Ejemplo n.º 4
0
 partial void DeleteCategoryModel(CategoryModel instance);
Ejemplo n.º 5
0
 partial void UpdateCategoryModel(CategoryModel instance);
Ejemplo n.º 6
0
 partial void InsertCategoryModel(CategoryModel instance);