public void AddCategory(CategoryModel category) { if (category.Description == null) category.Description = ""; context.CategoryModels.InsertOnSubmit(category); context.SubmitChanges(); }
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(); }
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(); } }
partial void DeleteCategoryModel(CategoryModel instance);
partial void UpdateCategoryModel(CategoryModel instance);
partial void InsertCategoryModel(CategoryModel instance);