コード例 #1
0
        // GET: Questions/Details/5
        public IActionResult Details(int?id)
        {
            var cookie = this.HttpContext.Request.Cookies["RefreshFilter"];

            this.RouteData.Values["IsRefreshed"] = cookie != null && cookie.ToString() == this.HttpContext.Request.Path.ToString();

            if (id == null)
            {
                return(NotFound());
            }
            QuestionWithAnswersDto question;

            if ((bool)this.RouteData.Values["IsRefreshed"] == false)
            {
                question = _questionAppService.GetQuestion(new GetQuestionInput {
                    Id = id.Value, IncrementViewCount = true
                }).Question;
            }
            else
            {
                question = _questionAppService.GetQuestion(new GetQuestionInput {
                    Id = id.Value, IncrementViewCount = false
                }).Question;
            }

            if (question == null)
            {
                return(NotFound());
            }
            this.HttpContext.Response.Cookies.Append("RefreshFilter", this.HttpContext.Request.Path.ToString(), new CookieOptions {
                Expires = DateTime.Now.AddDays(5)
            });
            return(View(question));
        }
コード例 #2
0
 public ActionResult GetQuestion(long id)
 {
     try
     {
         var question = _questionAppService.GetQuestion(id);
         return(Ok(question));
     }
     catch (Exception ex)
     {
         return(new BadRequestObjectResult(ex.Message));
     }
 }