Exemple #1
0
        public IActionResult Questions(string questionsType, int?pageNumber)
        {
            QuestionsViewModel questionsViewModel = new QuestionsViewModel();

            questionsViewModel.questionsViewModel = new List <QuestionViewModel>();

            using (var unitOfWork = new UnitOfWork(new CuriousDriveContext()))
            {
                List <Question> questions = unitOfWork.Questions.GetRecentQuestions();

                foreach (Question question in questions)
                {
                    QuestionViewModel questionViewModel = new QuestionViewModel();

                    questionViewModel.questionId    = question.QuestionId;
                    questionViewModel.questionTitle = question.QuestionTitle;
                    questionViewModel.createdDate   = question.CreatedDate;

                    questionViewModel.answerCount = unitOfWork.QuestionAnswers.GetAnswerCountByQuestionId(question.QuestionId);
                    List <QuestionClass> questionClasses = unitOfWork.QuestionClasses.GetQuestionClassesByQuestionId(question.QuestionId);

                    questionViewModel.questionClassesViewModel = new List <QuestionClassViewModel>();

                    foreach (QuestionClass questionClass in questionClasses)
                    {
                        QuestionClassViewModel questionClassViewModel = new QuestionClassViewModel();

                        questionClassViewModel.classId   = questionClass.ClassId;
                        questionClassViewModel.className = questionClass.Class.ClassName;

                        questionViewModel.questionClassesViewModel.Add(questionClassViewModel);
                    }

                    User user = unitOfWork.Users.Get((int)question.CreatedBy);

                    questionViewModel.userDetailsViewModel             = new UserDetailsViewModel();
                    questionViewModel.userDetailsViewModel.userId      = user.UserId;
                    questionViewModel.userDetailsViewModel.displayName = user.DisplayName;
                    questionViewModel.userDetailsViewModel.urlTitle    = Utility.GetURLTitle(user.DisplayName);

                    questionViewModel.userDetailsViewModel.profilePictureViewModel = new ProfilePictureViewModel();

                    questionsViewModel.questionsViewModel.Add(questionViewModel);
                }
            }

            return(View(questionsViewModel));
        }
Exemple #2
0
        public IActionResult Question(int questionId, string title)
        {
            int lintUserId = HttpContext.Session.GetInt32("UserId") ?? 0;
            QuestionViewModel questionViewModel = new QuestionViewModel();

            using (var unitOfWork = new UnitOfWork(new CuriousDriveContext()))
            {
                Question question = unitOfWork.Questions.GetQuestionDetails(questionId);

                questionViewModel.questionId    = question.QuestionId;
                questionViewModel.questionTitle = question.QuestionTitle;
                questionViewModel.questionHtml  = question.QuestionHtml;
                questionViewModel.createdDate   = question.CreatedDate;

                questionViewModel.userDetailsViewModel = new UserDetailsViewModel();

                questionViewModel.userDetailsViewModel.userId      = question.User.UserId;
                questionViewModel.userDetailsViewModel.displayName = question.User.DisplayName;
                questionViewModel.userDetailsViewModel.urlTitle    = Utility.GetURLTitle(question.User.DisplayName);

                questionViewModel.userDetailsViewModel.profilePictureViewModel = new ProfilePictureViewModel();

                questionViewModel.userTagListViewModel = new List <UserTagViewModel>();

                foreach (Tag tag in question.Tag)
                {
                    foreach (TagDetail tagDetail in tag.TagDetail)
                    {
                        UserTagViewModel userTagViewModel = new UserTagViewModel();

                        userTagViewModel.userId  = tagDetail.TaggedUser.UserId;
                        userTagViewModel.userTag = tagDetail.TaggedUser.DisplayName;

                        questionViewModel.userTagListViewModel.Add(userTagViewModel);
                    }
                }

                questionViewModel.commentsViewModel = new List <CommentViewModel>();

                foreach (Comment comment in question.Comment)
                {
                    CommentViewModel commentViewModel = new CommentViewModel();

                    commentViewModel.commentId   = comment.CommentId;
                    commentViewModel.commentHtml = comment.CommentHtml;
                    commentViewModel.userId      = comment.User.UserId;
                    commentViewModel.displayName = comment.User.DisplayName;
                    commentViewModel.urlTitle    = Utility.GetURLTitle(comment.User.DisplayName);

                    questionViewModel.commentsViewModel.Add(commentViewModel);
                }

                questionViewModel.questionAnswersViewModel = new List <QuestionAnswerViewModel>();

                foreach (QuestionAnswer questionAnswer in question.QuestionAnswer)
                {
                    QuestionAnswerViewModel questionAnswerViewModel = new QuestionAnswerViewModel();

                    questionAnswerViewModel.questionId       = question.QuestionId;
                    questionAnswerViewModel.questionAnswerId = questionAnswer.QuestionAnswerId;
                    questionAnswerViewModel.answerHtml       = questionAnswer.AnswerHtml;
                    questionAnswerViewModel.createdDate      = questionAnswer.CreatedDate;

                    questionAnswerViewModel.commentsViewModel = new List <CommentViewModel>();

                    foreach (Comment comment in questionAnswer.Comment)
                    {
                        CommentViewModel commentViewModel = new CommentViewModel();

                        commentViewModel.commentId   = comment.CommentId;
                        commentViewModel.commentHtml = comment.CommentHtml;
                        commentViewModel.userId      = comment.User.UserId;
                        commentViewModel.displayName = comment.User.DisplayName;
                        commentViewModel.urlTitle    = Utility.GetURLTitle(comment.User.DisplayName);

                        questionAnswerViewModel.commentsViewModel.Add(commentViewModel);
                    }

                    questionAnswerViewModel.userDetailsViewModel = new UserDetailsViewModel();

                    questionAnswerViewModel.userDetailsViewModel.userId      = questionAnswer.UserId;
                    questionAnswerViewModel.userDetailsViewModel.displayName = questionAnswer.User.DisplayName;
                    questionAnswerViewModel.userDetailsViewModel.urlTitle    = Utility.GetURLTitle(questionAnswer.User.DisplayName);

                    questionAnswerViewModel.userDetailsViewModel.profilePictureViewModel = new ProfilePictureViewModel();

                    questionViewModel.questionAnswersViewModel.Add(questionAnswerViewModel);
                }

                questionViewModel.questionClassesViewModel = new List <QuestionClassViewModel>();

                foreach (QuestionClass questionClass in question.QuestionClass)
                {
                    QuestionClassViewModel questionClassViewModel = new QuestionClassViewModel();

                    questionClassViewModel.classId   = questionClass.ClassId;
                    questionClassViewModel.className = questionClass.Class.ClassName;

                    questionViewModel.questionClassesViewModel.Add(questionClassViewModel);
                }
            }

            return(View(questionViewModel));
        }