//[ExportModelStateToTempData] public ActionResult Index(QAModel model, string Sort = "") { try { if (model.question == null) { model.question = new Question(); } if (model.question.questions == null) { QuestionWS Qws = new QuestionWS(); model.question = Qws.GetQuestionsBySortFilter(Sort); } if (Sort != null) { TempData["Title"] = Sort + " questions"; } if (model.question.questions.Count > 0) { return(View(model)); } } catch (Exception) { //TODO: log this error } TempData["ErrorPrevention"] = "Do you want to <a href='/Questions/Create'> ask a question </a>?"; ModelState.AddModelError("", "An error occured while retrieving questions"); return(View("Error")); }
public ActionResult Create(QAModel model) { Question question = model.question; try { QuestionWS Qws = new QuestionWS(); DBUtil objDBUtil = new DBUtil(3); DataSet AddQuestion = Qws.WriteQuestion(question, 1, this); if (AddQuestion.RowsExists()) { int resTbl = AddQuestion.Tables.Count - 1; TempData["StatusMsg"] = AddQuestion.Tables[resTbl].Rows[0]["StatusMsg"].ToString(); if (int.Parse(AddQuestion.Tables[resTbl].Rows[0]["StatusCode"].ToString()) == 1) { question.QuestionId = int.Parse(AddQuestion.Tables[resTbl].Rows[0]["QuestionId"].ToString()); } else if (int.Parse(AddQuestion.Tables[resTbl].Rows[0]["StatusCode"].ToString()) == 9) { question.QuestionId = int.Parse(AddQuestion.Tables[resTbl].Rows[0]["Duplicate QuestionId"].ToString()); } return(RedirectToActionPermanent("Details", "Questions", new { QuestionId = model.question.QuestionId })); } } catch { } ModelState.AddModelError("", "An error occured while adding the question"); return(View(model)); }
// 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")); }
public ActionResult Update(QAModel model) { //try //{ Question question = model.question; QuestionWS Qws = new QuestionWS(); DBUtil objDBUtil = new DBUtil(3); DataSet AddQuestion = Qws.WriteQuestion(question, 2, this); if (AddQuestion.RowsExists()) { //taking from 0th table because it will accomodate updates from other users as well if (int.Parse(AddQuestion.Tables[0].Rows[0]["StatusCode"].ToString()) == 1) { TempData["StatusMsg"] = AddQuestion.Tables[0].Rows[0]["StatusMsg"].ToString(); } return(RedirectToActionPermanent("Details", "Questions", new { QuestionId = model.question.QuestionId })); } //} //catch { } ModelState.AddModelError("", "An error occured while updating the question"); return(RedirectPermanent(this.GetRequestReferrer())); }
public ActionResult Create(QAModel model) // int pQuestionId, string pCommentTxt, int pCommentBy { if (model.question.questionComment.CommentTxt.Length > 500) { TempData["StatusMsg"] = "Sorry! comments cannot be more than 500 charachters"; return(RedirectToActionPermanent("Details", "Questions", new { QuestionId = model.question.QuestionId })); } if (!Request.IsAuthenticated) { TempData["RedirectMsg"] = "You must be logged in first"; TempData["UrlReferrer"] = this.GetRequestReferrer(); return(View("~/Views/Account/Login.cshtml")); } dbUtil = new DBUtil(3); cmd = new MySqlCommand("spAddQuestionComment"); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("pQuestionId", model.question.QuestionId); cmd.Parameters.AddWithValue("pCommentTxt", model.question.questionComment.CommentTxt.SanitizeInput()); cmd.Parameters.AddWithValue("pCommentTxtHtml", model.question.questionComment.CommentTxtHtml.ConvertMdToHtml()); cmd.Parameters.AddWithValue("pCommentBy", User.Identity.GetCurUserNumber()); DataSet AddQuestionComment = dbUtil.FillDataSet(cmd); if (AddQuestionComment.RowsExists()) { int resTbl = AddQuestionComment.Tables.Count - 1; TempData["StatusMsg"] = AddQuestionComment.Tables[resTbl].Rows[0]["StatusMsg"].ToString(); return(RedirectToActionPermanent("Details", "Questions", new { QuestionId = model.question.QuestionId })); } return(View("Error")); }
// // GET: /QA/ public ActionResult Index() { QAModel model = new QAModel(); QAViewModel viewmodel = new QAViewModel(); viewmodel.GetQuestionPaged = model.GetQuestionPaged(1, 10); return(View(viewmodel)); }
// 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 IActionResult Create_() { QAModel m = new QAModel(); m.ID_user = HttpContext.Session.GetString("ID"); //"2020000";// HttpContext.Session.GetString("ID"); m.question = Request.Form["question"]; m.date_q = DateTime.Now.ToString("yyyy-MM-dd"); m.time_q = DateTime.Now.ToString("T"); Sql.Execute("INSERT INTO OnlineQ(ID,date,time,detail,isAns) VALUES(@0,@1,@2,@3,@4)", m.ID_user, m.date_q, m.time_q, m.question, 0); return(RedirectToAction("Index_QA"));//这个东西还没有 //return RedirectToAction("Answer_Index"); }
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 QuestionsByUser(int Q_By, string Q_ByUName) { QAModel model = new QAModel(); QuestionWS Qws = new QuestionWS(); model.question = Qws.QuestionsByUser(Q_By); TempData["Title"] = string.Format("Questions asked by {0}", Q_ByUName); return(View("Index", model)); }
public static List <QAModel> GetQAModel(string OEORI_RowId) { List <QAModel> results = new List <QAModel>(); using (var con = new CacheConnection(conString)) { con.Open(); using (var cmd = new CacheCommand(QueryString.GetQuesAns(OEORI_RowId), con)) { using (var reader = cmd.ExecuteReader()) { string type = string.Empty; while (reader.Read()) { QAModel qam = new QAModel(); string[] spilts = reader["QUES_Code"].ToString().Split('_'); if (Regex.IsMatch(reader["QUES_Desc"].ToString(), @"<[^>]*>")) { type = spilts.Length > 2 ? spilts[2] : ""; qam.QUES_Code = reader["QUES_Code"].ToString(); qam.QUES_Desc = reader["QUES_Desc"].ToString(); qam.QA_Answer = reader["QA_Answer"].ToString(); qam.QUES_ControlType = reader["QUES_ControlType"].ToString(); qam.QUES_Type = type; results.Add(qam); } else { if (!string.IsNullOrEmpty(reader["QA_Answer"].ToString())) { qam.QUES_Code = reader["QUES_Code"].ToString(); qam.QUES_Desc = reader["QUES_Desc"].ToString(); qam.QA_Answer = reader["QA_Answer"].ToString(); qam.QUES_ControlType = reader["QUES_ControlType"].ToString(); qam.QUES_Type = type; results.Add(qam); } } } } } } return(results); }
public void Post([FromBody] QAModel model) { var jsonModel = JsonConvert.DeserializeObject <QAModel[]>(System.IO.File.ReadAllText(_pathQAs)); foreach (var token in jsonModel) { if (token.lang == model.lang) { token.qAs.AddRange(model.qAs); } } var newJson = JsonConvert.SerializeObject(jsonModel); System.IO.File.WriteAllText(_pathQAs, newJson); }
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 IActionResult Answer_() { QAModel m = new QAModel(); m.ID_exp = HttpContext.Session.GetString("ID"); //"202001";// HttpContext.Session.GetString("ID"); m.answer = Request.Form["answer"]; m.date_q = DateTime.Now.ToString("yyyy-MM-dd"); m.time_q = DateTime.Now.ToString("T"); m.ID_question = Request.Form["question_id"]; Sql.Execute("INSERT INTO ExperAnswer(ID,date,time,detail,ID_Q) VALUES(@0,@1,@2,@3,@4)", m.ID_exp, m.date_q, m.time_q, m.answer, m.ID_question); //上面这句有问题 //12.10最后那个isAns改了问题的ID属性,不知道数据库里有没有 //我不知道这个表叫啥 Sql.Execute("UPDATE OnlineQ SET isAns = @0 WHERE id_number = @1", 1, m.ID_question); return(RedirectToAction("Answer_Index")); }
}//最好存用户昵称不存ID,加一个查询就行了 public IActionResult Answer() { QAModel m = new QAModel(); m.ID_exp = HttpContext.Session.GetString("ID"); //"202001";// HttpContext.Session.GetString("ID"); m.ID_question = Request.Form["question_id"]; var name = Sql.Read("SELECT ID, detail,date,time FROM OnlineQ WHERE id_number=@0", m.ID_question); foreach (DataRow n in name) { m.ID_user = n[0].ToString(); m.question = n[1].ToString(); m.date_q = n[2].ToString(); m.time_q = n[3].ToString(); } return(View(m));//没有显示问题本身,在View里面 }
//[Authorize] public ActionResult Edit(int QuestionId) { TempData["UrlReferrer"] = this.GetRequestReferrer(); if (!Request.IsAuthenticated) { TempData["RedirectMsg"] = "You must be logged in first"; return(View("~/Views/Account/Login.cshtml")); } QAModel model = new QAModel(); TempData["Title"] = "Improve question!"; QuestionWS QWS = new QuestionWS(); model.question = QWS.GetQuestionById(QuestionId, this.GetVisitorIP(Session["VisitorIP"])); 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())); }
// // GET: /Result/ public ActionResult Index(string keyword) { // If keyword is null or empty then system will redirect to home page if (keyword == null || keyword.Trim().Equals("")) { return(RedirectToAction("Index", "Home")); } // Instance model layer ResultModel resultModel = new ResultModel(); // Instance view model for result ResultViewModel resultViewModel = new ResultViewModel(); // Get entry by keyword WordIndex entry = resultModel.GetEntryByKeyword(keyword); // Property of search history bool isExistData = true; // Check has entry if (entry != null) { //set view model resultViewModel.Entry = entry; // List result if (entry.Synsets.Where(x => x.Category == "n").Count() > 0) { ViewBag.Noun = entry.Synsets.Where(x => x.Category == "n"); } if (entry.Synsets.Where(x => x.Category == "v").Count() > 0) { ViewBag.Verb = entry.Synsets.Where(x => x.Category == "v"); } //add history isExistData = true; } else { isExistData = false; } //add history SearchHistoryModel searchHistoryModel = new SearchHistoryModel(); searchHistoryModel.AddSearchHistory(keyword, isExistData); //add user history if (Request.IsAuthenticated) { UserHistoryModel userHistoryModel = new UserHistoryModel(); userHistoryModel.AddUserHistory(keyword); } //--------------------------------------- // Store 5 recent keywords if (Session["Recent"] == null) { Session["Recent"] = new List <string>(); } int countRecent = ((List <string>)Session["Recent"]).Count; if (((List <string>)Session["Recent"]).Contains(keyword)) { ((List <string>)Session["Recent"]).Remove(keyword); } else if (countRecent >= 5) { ((List <string>)Session["Recent"]).RemoveAt(0); } ((List <string>)Session["Recent"]).Add(keyword); //((List<string>)Session["Recent"]).Reverse(); //string[] arraySuggest = new string[((List<string>)Session["Recent"]).Count]; //((List<string>)Session["Recent"]).CopyTo(arraySuggest); //ViewBag.Recent = arraySuggest; //((List<string>)Session["Recent"]).Reverse(); //--------------------------------------- //ViewBag.Title ViewBag.Title = "Kết quả tra cứu cho '" + keyword + "'"; // add suggest terms EntriesModel entryModel = new EntriesModel(); resultViewModel.SuggestTerm = entryModel.SuggestTerm(keyword); // get questions QAModel qaModel = new QAModel(); resultViewModel.Questions = qaModel.GetQuestionPaged(1, 10); return(View(resultViewModel)); }
public JsonResult Qa() { List <QAModel> questions = new List <QAModel>(); try { //var customer = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer; Int32 languageId = EngineContext.Current.Resolve <IWorkContext>().WorkingLanguage.Id; var cs = new DataSettingsManager().LoadSettings().DataConnectionString; using (SqlConnection conn = new SqlConnection(cs)) { using (SqlCommand cmd = new SqlCommand("dbo.P_QAGet", conn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@LanguageId", SqlDbType.Int).Value = languageId; conn.Open(); var rdr = cmd.ExecuteReader(); Int32 id = 0; QAModel question = null; while (rdr.Read()) { if (rdr.GetInt32(0) != id) { if (question != null) { questions.Add(question); } id = rdr.GetInt32(0); question = new QAModel { Id = id, ControlTypeId = rdr.GetInt32(1), Question = rdr.GetString(2) }; } Answer answer = new Answer { Id = rdr.GetInt32(3), Name = rdr.GetString(4), IsPreSelected = rdr.GetBoolean(5) }; question?.Answers.Add(answer); } rdr.Close(); if (question != null) { questions.Add(question); } } } } catch (Exception ex) { return(Json(new { success = false, msg = ex.Message, qa = "" }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = true, msg = "", qa = questions }, JsonRequestBehavior.AllowGet)); }