public ActionResult Index(string q, string client, string client_version, string debug) { ViewBag.Title = "Natural Date and Time"; if (!string.IsNullOrEmpty(q)) { q = HttpUtility.UrlDecode(q); q = q.Replace("_", " "); ViewBag.Title = q + " - Natural Date and Time"; var answerService = new AnswerService(); var answer = answerService.GetAnswer(q); var userAgent = String.Empty; if (Request.Headers["User-Agent"] != null) userAgent = Request.Headers["User-Agent"].ToString(); if (string.IsNullOrEmpty(client)) client = "web"; if (string.IsNullOrEmpty(client_version)) client_version = "2.0"; var dbContext = new NaturalDateTimeContext(); var questionLog = new QuestionLog(answer.Question, answer, DateTime.UtcNow, client, client_version, IsBot(userAgent)); dbContext.AddQuestionLog(questionLog); dbContext.SaveChanges(); return View("Index", new HomeViewModel(q, answer.AnswerText, answer.Note)); } return View(new HomeViewModel(!String.IsNullOrEmpty(debug))); }
public ActionResult LatestUserQuestionLogs() { var dbContext = new NaturalDateTimeContext(); var latestUserQuestionLogs = dbContext.QuestionLogCache.LatestUserQuestionLogs.OrderByDescending(x => x.UtcTime); var questionLogResultSet = new QuestionLogResultSet(NaturalDateTimeContext.MaxCacheEntries, latestUserQuestionLogs); return Json(questionLogResultSet, JsonRequestBehavior.AllowGet); }
public ActionResult Question(string question, string client, string client_version, string debug) { if (string.IsNullOrEmpty(question)) throw new HttpException(400, "Invalid request. Question not specified."); if (string.IsNullOrEmpty(client)) throw new HttpException(400, "Invalid request. Client not specified."); if (string.IsNullOrEmpty(client_version)) throw new HttpException(400, "Invalid request. Client version not specified."); question = HttpUtility.UrlDecode(question); var userAgent = String.Empty; if (Request.Headers["User-Agent"] != null) userAgent = Request.Headers["User-Agent"].ToString(); var answerService = new AnswerService(); var answer = answerService.GetAnswer(question, !String.IsNullOrEmpty(debug)); var dbContext = new NaturalDateTimeContext(); var questionLog = new QuestionLog(answer.Question, answer, DateTime.UtcNow, client, client_version, IsBot(userAgent)); dbContext.AddQuestionLog(questionLog); dbContext.SaveChanges(); return Json(new AnswerModel(answer), JsonRequestBehavior.AllowGet); }
public ActionResult QuestionLogEntries(int page, int pageSize, bool showBotRequests) { var dbContext = new NaturalDateTimeContext(); IQueryable<QuestionLog> questionsLogQuery = dbContext.QuestionLog; if(!showBotRequests) questionsLogQuery = questionsLogQuery.Where(x => !x.IsBot).AsQueryable(); var total = questionsLogQuery.Count(); var questionLogs = questionsLogQuery.OrderByDescending(x => x.Id).Skip((page - 1) * pageSize).Take(pageSize).ToList(); var questionLogResultSet = new QuestionLogResultSet(total, questionLogs); return Json(questionLogResultSet, JsonRequestBehavior.AllowGet); }