public ActionResult PromoteUser() { if (Request.Params.AllKeys.Contains("id")) { long id = 0; try { id = long.Parse(Request.Params["id"]); } catch { } Form_Author_Add form = new Form_Author_Add(id); if (Request.HttpMethod.ToLower() == form.getMethod().ToString()) { if (form.isValid(Request.Form)) { if (this._app.users().promoteUser(form, id)) { _messages.addMessage("The user has been successfully promoted"); return Redirect("/backend/ListUsers"); } else { _messages.addMessage("There was an error while promoting the user"); } } } ViewData["form"] = form.render(); return View(); } else { _messages.addError("Undefined parameter ID"); return RedirectToAction("listUsers", "backend"); } }
/// <summary> /// Save changes to the given author /// </summary> /// <param name="form">Author data</param> /// <param name="edited">Edited author</param> /// <returns>success</returns> public bool saveAuthor(Form_Author_Add form, author edited) { author toSave = new author(); toSave.id = edited.id; toSave.lastname = form["lastname"].getValue(); toSave.description = form["description"].getValue(); toSave.name = form["name"].getValue(); toSave.usersid = edited.usersid; toSave.date = edited.date; using (LangDataContext a = new LangDataContext()) { a.authors.Attach(toSave, edited); try { a.SubmitChanges(); } catch (Exception) { return false; } return true; } }
public ActionResult EditAuthor() { if (Request.Params.AllKeys.Contains("uid")) { long uid = 0; try { uid = long.Parse(Request.Params["uid"]); } catch { } author edited = this._app.users().getAuthorByUserId(uid); Form_Author_Add form = new Form_Author_Add(uid); form.setEditData(edited); if (Request.HttpMethod.ToLower() == form.getMethod().ToString()) { if (form.isValid(Request.Form)) { if (this._app.users().saveAuthor(form, edited)) { _messages.addMessage("The author has been successfully saved"); return Redirect("/backend/ListUsers"); } else { _messages.addError("There was an error while saving the author"); } } } ViewData["form"] = form.render(); return View(); } else { _messages.addError("Undefined parameter UID"); return RedirectToAction("listUsers", "backend"); } }
/// <summary> /// Adds an author to the system /// </summary> /// <param name="form">Author data</param> /// <param name="id">User id</param> /// <returns>success</returns> public bool promoteUser(Form_Author_Add form, long id) { using (LangDataContext a = new LangDataContext()) { author toSave = new author(); toSave.date = DateTime.Now; toSave.description = form["description"].getValue(); toSave.lastname = form["lastname"].getValue(); toSave.name = form["name"].getValue(); toSave.usersid = id; a.authors.InsertOnSubmit(toSave); try { a.SubmitChanges(); } catch(Exception e) { CMS.Services.CMS_Services_Message.getInstance().addError(e.Message); return false; } } return true; }