예제 #1
0
        // 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");
        }
예제 #2
0
        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"));
        }