// // GET+POST: /Backend/AddCategory[?parent={id}] public ActionResult AddCategory() { long parent = 0; if (Request.Params.AllKeys.Contains("parent")) { try { parent = long.Parse(Request.Params["parent"]); } catch { } } string name = "Base imaginary category (root)"; if (parent > 0) { category c = this._app.categories().getById(parent); if (c != null) { name = c.name; } } ViewData["name"] = name; Form_Category_Add form = new Form_Category_Add(parent); if (Request.HttpMethod.ToLower() == form.getMethod().ToString()) { if (form.isValid(Request.Form)) { if (this._app.categories().add(parent, form)) { _messages.addMessage("The category has been successfully added"); return Redirect("/backend/ListCategories?parent=" + parent.ToString()); } } } ViewData["form"] = form.render(); return View(); }
// // GET+POST: /Backend/EditCategory?id={id} public ActionResult EditCategory() { if (Request.Params.AllKeys.Contains("id")) { long id = 0; try { id = long.Parse(Request.Params["id"]); } catch { } category c = this._app.categories().getById(id); if (c != null) { Form_Category_Add form = new Form_Category_Add(0); if (Request.HttpMethod.ToLower() == form.getMethod().ToString()) { if (form.isValid(Request.Form)) { if (this._app.categories().save(form, c)) { _messages.addMessage("The category has been successfully saved"); if (c.parentid.HasValue) { return Redirect("/backend/ListCategories?parent=" + c.parentid); } return Redirect("/backend/ListCategories?parent=" + c.id); } } } form.setEditData(c); ViewData["form"] = form.render(); return View(); } } _messages.addError("Undefined or wrong parameter ID"); return RedirectToAction("listCategories", "backend"); }