Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using ASP_Herkansing.Domain.Abstract;
  7. using ASP_Herkansing.Domain.Entities;
  8. using ASP_Herkansing.HtmlHelpers;
  9. using ASP_Herkansing.Models;
  10.  
  11. namespace ASP_Herkansing.Controllers
  12. {
  13. public class QuizController : Controller
  14. {
  15. private IQuestionsRepository questionsRepository;
  16. //public attributes for testing
  17. public int PageSize = 3;
  18. public int MaxQuestions = 5;
  19.  
  20. public QuizController(IQuestionsRepository questionsRepository)
  21. {
  22. this.questionsRepository = questionsRepository;
  23. }
  24.  
  25. public ViewResult QuizStart(Quiz quiz, string returnUrl, int page = 1)
  26. {
  27. //Assert how many questions are available for picking
  28. int ListLength = questionsRepository.Questions.Count();
  29.  
  30. //Make a list (custom size) to empty the repo in
  31. List<Question> quizQuestions = new List<Question>(ListLength);
  32. quizQuestions.AddRange(questionsRepository.Questions);
  33.  
  34. //Shuffle the questions
  35. quizQuestions.Shuffle();
  36.  
  37. //Feed view shuffled questions in Pagination
  38. QuestionsListViewModel model = new QuestionsListViewModel()
  39. {
  40. Questions = quizQuestions
  41. .Skip((page - 1) * PageSize)
  42. .Take(PageSize)
  43. ,
  44. PagingInfo = new PagingInfo
  45. {
  46. CurrentPage = page,
  47. ItemsPerPage = PageSize,
  48. TotalItems = questionsRepository.Questions.Count()
  49. }
  50. };
  51. return View(model);
  52. }
  53.  
  54. public ViewResult Results(Quiz quiz)
  55. {
  56.  
  57. return View(quiz);
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement