// GET: Answers/Details/5 /// <summary> /// Single reusable action for displaying answer /// </summary> /// <param name="AnswerCount"></param> /// <param name="model">The answer to display</param> /// <param name="_View">Eg: Details for display, Edit for editing, Delete for deleting </param> /// <returns>The view specified by _View</returns> public ActionResult Details(int AnswerId, QAModel model, string _View) { try { AnswerWS Aws = new AnswerWS(); if (AnswerId > 0) { model.answer = Aws.GetAnswerById(AnswerId, this.GetVisitorIP(Session["VisitorIP"])); } else if (model.question.QuestionId > 0) { model.answer = Aws.GetAnswersForQuestion(model.question.QuestionId); } return(View(_View, model)); } catch (Exception) { //TODO: log this exception } TempData["ErrorPrevention"] = "Maybe the data required to display the answer was incomplete. Do you want to <a href='/Questions/Create'> ask a question </a>?"; ModelState.AddModelError("", "An error occured while displaying answer"); return(View("Error")); }
// GET: Questions/Details/5 /// <summary> /// Single reusable action for displaying question /// </summary> /// <param name="model"> The question answer to display (with answer) </param> /// <param name="_View"> Eg: Details for display, Edit for editing, Delete for deleting </param> /// <param name="question"> The question to display </param> /// <returns> The view specified by _View </returns> //[ImportModelStateFromTempData] //[PageView] public ActionResult Details(int QuestionId, string _View) { QAModel model = new QAModel(); QuestionComment questionComment = new QuestionComment(); AnswerComment answerComment = new AnswerComment(); dbUtil = new DBUtil(3); if (_View == "Edit") { if (!Request.IsAuthenticated) { TempData["RedirectMsg"] = "You must be logged in first"; return(RedirectToActionPermanent("Login", "Account")); } } if (QuestionId > 0) { model.question = new Question(); QuestionWS Qws = new QuestionWS(); model.question = Qws.GetQuestionById(QuestionId, this.GetVisitorIP(Session["VisitorIP"])); if (model.question.AnswerCount > 0) { AnswerWS Aws = new AnswerWS(); model.answer = Aws.GenModel4mDS(Answers_ds: Aws.GetAnswersForQuestion(null, QuestionId)); } else { model.answer = Answer.InitializeIfNone(model.answer); } } if (TempData["StatusMsg"] == null) { TempData["Title"] = model.question.Q_Title; } else { TempData["Title"] = TempData["StatusMsg"]; } if (Request.IsAuthenticated) { TempData["LoggedInUser"] = User.Identity.GetCurUserNumber(); } else { TempData["LoggedInUser"] = 0; } return(View(_View, model)); //TempData["ErrorPrevention"] = "Maybe the data required to display the question was incomplete. Do you want to <a href='/Questions/Create'> ask a question </a>?"; //ModelState.AddModelError("", "An error occured while displaying question"); //return View("Error"); }
public ActionResult AnswersByUser(int A_By, string A_ByUName) { QAModel model = new QAModel(); AnswerWS Aws = new AnswerWS(); model.answer = Aws.AnswersByUser(A_By); TempData["Title"] = string.Format("Answers by {0}", A_ByUName); return(View("Index", model)); }
public ActionResult Index(int QuestionId, string Sort = "") { Answer model = new Answer(); try { if (model.answers == null && QuestionId > 0) { string procName; switch (Sort) { default: case "Top": procName = "spGetTopAnswersByQ_Id"; break; case "Live": procName = "spGetLiveAnswerByQ_Id"; break; case "Oldest": procName = "spGetOldestAnswerByQ_Id"; break; case "Newest": procName = "spGetAllAnswerByQ_Id"; break; } AnswerWS Aws = new AnswerWS(); model = Aws.GenModel4mDS( Answers_ds: Aws.GetAnswersForQuestion(procName, QuestionId)); } ViewBag.Filter = Sort; return(View(model)); } catch (Exception ex) { new ErrorUtil().LogException(ex, 10, "Some error occured while retrieving answers"); } TempData["ErrorPrevention"] = "Do you want to <a href='/Answers/Create?QuestionId=" + QuestionId + "'> answer this question </a>?"; ModelState.AddModelError("", "An error occured while retrieving answers"); return(View("Error")); }
public ActionResult Create(QAModel model) { AnswerWS Aws = new AnswerWS(); if (model.answer.QuestionId == 0) { model.answer.QuestionId = model.question.QuestionId; } TempData["StatusMsg"] = Aws.WriteAnswer(model.answer, 1, this); return(RedirectToActionPermanent("Details", "Questions", new { QuestionId = model.answer.QuestionId })); //ModelState.AddModelError("", "An error occured while adding the answer"); //return View(model); }
public ActionResult Update(QAModel model) { try { Answer answer = model.answer; AnswerWS Aws = new AnswerWS(); DBUtil objDBUtil = new DBUtil(3); TempData["StatusMsg"] = Aws.WriteAnswer(answer, 2, this); if (TempData["UrlReferrer"] != null) { return(RedirectPermanent(TempData["UrlReferrer"].ToString())); } return(RedirectToActionPermanent("Details", "Questions", new { QuestionId = model.question.QuestionId })); } catch { } ModelState.AddModelError("", "An error occured while updating the answer"); return(RedirectPermanent(this.GetRequestReferrer())); }
public ActionResult Edit(int AnswerId) { TempData["UrlReferrer"] = this.GetRequestReferrer(); if (!Request.IsAuthenticated) { TempData["RedirectMsg"] = "You must be logged in first"; return(View("~/Views/Account/Login.cshtml")); } Answer model = new Answer(); TempData["Title"] = "Improve answer!"; //TempData["Guideline"] = "Thanks for your contribution"; AnswerWS AWS = new AnswerWS(); model = AWS.GetAnswerById(AnswerId, this.GetVisitorIP(Session["VisitorIP"])); return(View(model)); }