/// <summary> /// Adds a new comment to the article specifed with given id /// </summary> /// <param name="id">comment id</param> /// <param name="form">form containing data</param> /// <param name="ip">Client IP address</param> /// <returns></returns> public bool add(long id, Form_Comment_New form, string ip) { comment c = new comment(); c.useralias = form["name"].getValue(); c.title = form["title"].getValue(); c.text = form["text"].getValue(); c.parentid = null; c.ip = ip; c.email = form["email"].getValue(); c.articlesid = id; if (this._app.users().isLogged()) { c.usersid = this._app.users().getLogged().id; } try { using (LangDataContext a = new LangDataContext()) { a.comments.InsertOnSubmit(c); a.SubmitChanges(); } } catch { return false; } return true; }
// // GET+POST: /Comment/Add public ActionResult Add() { try { if (Request.Params.AllKeys.Contains("aid")) { long id = long.Parse(Request.Params["aid"]); Form_Comment_New form = new Form_Comment_New(id,"aid"); if (Request.HttpMethod.ToLower() == form.getMethod().ToString()) { if (form.isValid(Request.Form)) { if (this._app.comments().add(id, form, Request.UserHostAddress)) { _messages.addMessage("The comment has been successfully saved"); return Redirect("/article/detail?chapter=0&id=" + id); } } } ViewData["form"] = form.render(); return View(); } else if (Request.Params.AllKeys.Contains("id")) { long id = long.Parse(Request.Params["id"]); Form_Comment_New form = new Form_Comment_New(id, "id"); if (Request.HttpMethod.ToLower() == form.getMethod().ToString()) { if (form.isValid(Request.Form)) { long aid; if (this._app.comments().reply(id, form, Request.UserHostAddress, out aid)) { _messages.addMessage("The comment has been successfully saved"); return Redirect("/article/detail?chapter=0&id="+aid); } } } ViewData["form"] = form.render(); return View(); } }catch{ } return RedirectToAction("Index", "Home"); }
/// <summary> /// Saves a reply to a comment with the given id /// </summary> /// <param name="id">Comment id</param> /// <param name="form">Reply data</param> /// <param name="aid">Article id</param> /// <param name="ip">Client IP address</param> /// <returns></returns> public bool reply(long id, Form_Comment_New form, string ip, out long aid) { comment c = new comment(); c.useralias = form["name"].getValue(); c.title = form["title"].getValue(); c.text = form["text"].getValue(); c.parentid = id; c.ip = ip; c.email = form["email"].getValue(); if (this._app.users().isLogged()) { c.usersid = this._app.users().getLogged().id; } try { using (LangDataContext a = new LangDataContext()) { comment replied = a.comments.Where(x => x.id == id).Single(); aid = c.articlesid = replied.articlesid; a.comments.InsertOnSubmit(c); a.SubmitChanges(); } } catch { aid = 0; return false; } return true; }