Ejemplo n.º 1
0
        public ActionResult GetAllRecentQuestions()
        {
            HtmlToText    convert   = new HtmlToText();
            HomeViewModel homeModel = new HomeViewModel();

            IQueryable <Question> questions = _applicationDbContext.Questions
                                              .OrderByDescending(d => d.DateAsked)
                                              .Take(10);

            var questionList = new List <IndexQuestionViewModel>();

            foreach (var question in questions)
            {
                var questionModel = new IndexQuestionViewModel();
                questionModel.QuestionId = question.QuestionId;
                var User        = UserManager.FindByIdAsync(question.UserId);
                var ReportOwner = User.Result.NameExtension;
                questionModel.DisplayName = ReportOwner;

                questionModel.QuestionText  = question.QuestionText;
                questionModel.DateAsked     = question.DateAsked;
                questionModel.QuestionTitle = question.Title;

                questionList.Add(questionModel);
            }
            homeModel.IndexQuestionViewModels = questionList;
            //return View("Index", homeModel);
            return(PartialView("_RecentQuestions", homeModel));
        }
Ejemplo n.º 2
0
        public async Task UpdateQuestionShouldUpdateQuestionInQuizCorrectly()
        {
            var quizId = "123";
            var model  = new IndexQuestionViewModel();

            model.QuestionInputModel = new QuestionInputModel()
            {
                QuestionText = "A??",
                QuizId       = quizId,
            };


            var firstAnswer = new AnswerInputModel()
            {
                AnswerText      = "true",
                IsCorrectAnswer = true,
            };
            var secondAnswer = new AnswerInputModel()
            {
                AnswerText      = "false",
                IsCorrectAnswer = false,
            };

            model.AnswersInputModel = new List <AnswerInputModel>();
            model.AnswersInputModel.Add(firstAnswer);
            model.AnswersInputModel.Add(secondAnswer);

            var questionIdResult = await this.Service.AddQuestionAsync(model);

            var editModel = new IndexQuestionViewModel();

            editModel.QuestionInputModel = new QuestionInputModel()
            {
                QuestionText = "B??",
                QuizId       = quizId,
            };
            var firstNewAnswer = new AnswerInputModel()
            {
                AnswerText      = "false",
                IsCorrectAnswer = false,
            };
            var secondNewAnswer = new AnswerInputModel()
            {
                AnswerText      = "true",
                IsCorrectAnswer = true,
            };

            editModel.AnswersInputModel = new List <AnswerInputModel>();
            editModel.AnswersInputModel.Add(firstNewAnswer);
            editModel.AnswersInputModel.Add(secondNewAnswer);

            var quizIdResult = await this.Service.UpdateQuestionAsync(editModel, questionIdResult);

            var updatedQuestion = this.DbContext.Questions.FirstOrDefault();

            Assert.Equal(quizId, quizIdResult);
            Assert.NotEqual(model.QuestionInputModel.QuestionText, updatedQuestion.QuestionText);
            Assert.NotEqual(firstAnswer.AnswerText, updatedQuestion.Answers.FirstOrDefault().AnswerText);
            Assert.NotEqual(firstAnswer.IsCorrectAnswer, updatedQuestion.Answers.FirstOrDefault().IsCorrectAnswer);
        }
Ejemplo n.º 3
0
        public async Task AddQuestionShouldAddQuestionInQuizCorrectly()
        {
            var model = new IndexQuestionViewModel();

            model.QuestionInputModel = new QuestionInputModel()
            {
                QuestionText = "A??",
                QuizId       = "123",
            };

            var firstAnswer = new AnswerInputModel()
            {
                AnswerText      = "true",
                IsCorrectAnswer = true,
            };
            var secondAnswer = new AnswerInputModel()
            {
                AnswerText      = "false",
                IsCorrectAnswer = false,
            };

            model.AnswersInputModel = new List <AnswerInputModel>();
            model.AnswersInputModel.Add(firstAnswer);
            model.AnswersInputModel.Add(secondAnswer);

            var questionIdResult = await this.Service.AddQuestionAsync(model);

            var questionFromDb = this.DbContext.Questions.FirstOrDefault();

            Assert.NotNull(questionFromDb);
            Assert.Equal(questionFromDb.Id, questionIdResult);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create(string id)
        {
            var indexQestionodel = new IndexQuestionViewModel
            {
                QuizViewModel = await this.quizesService.GetQuizByIdAsync(id),
            };

            return(this.View(indexQestionodel));
        }
Ejemplo n.º 5
0
        public ActionResult Index(int page = 1)
        {
            int      totalQuestions = _questionService.GetAllQuestions().Count();
            var      questions      = _questionService.GetNQuestions(questionsPerPage, (page - 1) * questionsPerPage);
            PageInfo pageInfo       = new PageInfo {
                PageNumber = page, PageSize = questionsPerPage, TotalItems = totalQuestions
            };
            var iqvm = new IndexQuestionViewModel {
                PageInfo = pageInfo, Questions = questions
            };

            return(View(iqvm));
        }
Ejemplo n.º 6
0
        public async Task <string> UpdateQuestionAsync(IndexQuestionViewModel input, string questionId)
        {
            var question = await this.questionsRepo
                           .All()
                           .Where(x => x.Id == questionId)
                           .FirstOrDefaultAsync();

            question.QuestionText = input.QuestionInputModel.QuestionText;

            await this.answerService.UpdateAnswers(input.AnswersInputModel.ToList(), questionId);

            this.questionsRepo.Update(question);
            await this.questionsRepo.SaveChangesAsync();

            return(question.QuizId);
        }
Ejemplo n.º 7
0
        public async Task <string> AddQuestionAsync(IndexQuestionViewModel input)
        {
            var newQuestion = new Question()
            {
                QuestionText = input.QuestionInputModel.QuestionText,
                QuizId       = input.QuestionInputModel.QuizId,
                PictureId    = input.QuestionInputModel.PictureId,
            };

            newQuestion.Answers = this.answerService.AnswerInputsToModels(input.AnswersInputModel, newQuestion.Id);

            await this.questionsRepo.AddAsync(newQuestion);

            await this.questionsRepo.SaveChangesAsync();

            return(newQuestion.Id);
        }
Ejemplo n.º 8
0
        //TODO: needs validation
        public async Task <IActionResult> Edit(string id)
        {
            var indexViewModel = new IndexQuestionViewModel()
            {
                QuestionViewModel = await this.questionService.GetQuestionByIdAsync(id),
            };

            indexViewModel.QuizViewModel = await this.quizesService.GetQuizByIdAsync(indexViewModel.QuestionViewModel.QuizId);

            var creatorName = await this.quizesService.GetCreatorNameAsync(indexViewModel.QuestionViewModel.QuizId);

            if (creatorName != this.User.Identity.Name && !this.User.IsInRole(GlobalConstants.AdministratorRoleName))
            {
                return(this.Redirect("/"));
            }

            return(this.View(indexViewModel));
        }
Ejemplo n.º 9
0
        public async Task <ActionResult> Index()
        {
            var mainModel    = new FeedbackWithBlog();
            var listFeedback = new List <FeedbackViewModel>();
            var listBlog     = new List <BlogViewModel>();
            var homeModel    = new HomeViewModel();
            var convert      = new HtmlToText();

            var blogs = _applicationDbContext.Blogs.OrderByDescending(d => d.DateCreated).Take(10).ToList();

            foreach (var i in blogs)
            {
                var blogModel = new BlogViewModel();
                blogModel.BlogId      = i.BlogId;
                blogModel.Title       = i.Title;
                blogModel.DateCreated = i.DateCreated;
                listBlog.Add(blogModel);
            }

            var feedbacks = _applicationDbContext.Feedbacks.OrderByDescending(d => d.DateCreated).Take(10).ToList();

            foreach (var i in feedbacks)
            {
                var User     = UserManager.FindByIdAsync(i.UserId);
                var userName = User.Result.NameExtension;

                var model = new FeedbackViewModel()
                {
                    DateCreated = i.DateCreated,
                    Message     = i.Message,
                    UserName    = userName
                };

                listFeedback.Add(model);
            }

            IQueryable <Report> reports = _applicationDbContext.Reports
                                          .OrderByDescending(d => d.DateCreated)
                                          .Take(10);
            var reportList = new List <IndexReportViewModel>();

            foreach (var report in reports)
            {
                var reportModel = new IndexReportViewModel();
                reportModel.ReportId = report.ReportId;
                var User        = UserManager.FindByIdAsync(report.UserId);
                var ReportOwner = User.Result.NameExtension;
                reportModel.DisplayName = ReportOwner;

                string myString     = convert.Convert(report.ReportText).Substring(0, 90);
                int    index        = myString.LastIndexOf(' ');
                string outputString = myString.Substring(0, index);

                reportModel.ReportText  = outputString;
                reportModel.DateCreated = report.DateCreated;

                reportList.Add(reportModel);
            }

            IQueryable <Question> questions = _applicationDbContext.Questions
                                              .OrderByDescending(d => d.DateAsked)
                                              .Take(10);

            var questionList = new List <IndexQuestionViewModel>();

            foreach (var question in questions)
            {
                var questionModel = new IndexQuestionViewModel();
                questionModel.QuestionId = question.QuestionId;
                var User        = UserManager.FindByIdAsync(question.UserId);
                var ReportOwner = User.Result.NameExtension;
                questionModel.DisplayName = ReportOwner;

                questionModel.QuestionText  = question.QuestionText;
                questionModel.DateAsked     = question.DateAsked;
                questionModel.QuestionTitle = question.Title;

                questionList.Add(questionModel);
            }

            ViewBag.Questions = questionList;

            ViewBag.Complaints = reportList;

            mainModel.Posts        = listBlog;
            mainModel.Testimonials = listFeedback;
            return(View(mainModel));
        }