Ejemplo n.º 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");
        }
Ejemplo n.º 2
0
        //[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));
        }