コード例 #1
0
 /// <summary>
 /// Lists the users
 /// </summary>
 /// <returns></returns>
 public ActionResult ListAllUsers()
 {
     //Manager classes
     var uim = new UserManager();
     var users = uim.GetAllUsers();
     //List of the users
     var retlist = new List<UserListModel>();
     foreach (var item in users)
     {
         var add = new UserListModel();
         add.User = item;
         add.Rating = uim.GetUserRating(item.UserId);
         retlist.Add(add);
     }
     return View(retlist.OrderByDescending(q => q.Rating).ToList());
 }
コード例 #2
0
        /// <summary>
        /// Shows the page of a user
        /// </summary>
        /// <param name="id">User id</param>
        /// <returns></returns>
        public ActionResult GetUser(int id, int? questionpage, int? answerpage)
        {
            var usermanager = new UserManager();
            var questionmanager = new QuestionManager();
            var answermanager = new AnswerManager();
            var tagmanager = new TagManager();
            var ucm = new UserControllerModel();

            //If the pages are not given, set it to 1
            var actquestionpage = questionpage ?? 1;
            var actanswerpage = answerpage ?? 1;

            //Get the questions for the actual page
            int totalquestions;
            var retrievedQuestions = questionmanager.AllQuestionToOneUserToPagedList(id, actquestionpage, 5, out totalquestions);
            //Convert it to a StaticPagedList for the pager
            var actualQuestions = new StaticPagedList<Question>(retrievedQuestions, actquestionpage, 5, totalquestions);

            //Add it to the model
            ucm.Questions = actualQuestions;

            //Set the actual pagenumbers
            ViewBag.QuestionPage = actquestionpage;
            ViewBag.AnswerPage = actanswerpage;

            //Add the actual user to the model
            ucm.UserProfile = usermanager.GetUserById(id);

            //Get the answered questions by the user for the actual page
            int totalanswers;
            var retrievedAnsweredQuestions = questionmanager.AnsweredQuestionsToPagedList(id, actanswerpage, 5, out totalanswers);
            //Convert it to a StaticPagedList for the pager
            var actualAnsweredQuestions = new StaticPagedList<Question>(retrievedAnsweredQuestions, actanswerpage, 5, totalanswers);

            //Add it to the model
            ViewBag.AnsweredQuestions = actualAnsweredQuestions;

            //Add the reputation of the user to the model
            ucm.UserRating = usermanager.GetUserRating(id);

            //Create a list with the answered questions
            var answeredquestions = new List<GetQuestionModels>();
            foreach (var item in actualAnsweredQuestions)
            {

                var actansweredquestion = new GetQuestionModels();
                //Add the current question to the model
                actansweredquestion.CurrentQuestion = item;
                //Add the answers by the user of the current question to the model
                actansweredquestion.Answers = answermanager.GetAllAnswerToOneQuestionFromOneUser(item.Id, ucm.UserProfile.UserId);
                //Add the vote of current question to the model
                actansweredquestion.Vote = questionmanager.GetVote(item.Id);
                //Add the tags of the current question to the model
                actansweredquestion.QuestionTags = tagmanager.GetAllTagToOneQuestion(item.Id);

                //Create a dictionary for the answers and the votes of them
                actansweredquestion.AnswerVotes = new Dictionary<Answer, int>();

                //Upload the dictionary with the votes
                foreach (var answer in actansweredquestion.Answers)
                {
                    actansweredquestion.AnswerVotes.Add(answer, answermanager.GetVote(answer.Id));
                }

                //Add the author of the question to the model
                actansweredquestion.QuestionUser = usermanager.GetUserById(item.UserId);

                //Sort the answers by the votes of them
                actansweredquestion.Answers = actansweredquestion.Answers.OrderByDescending(d => actansweredquestion.AnswerVotes[d]).ToList();

                //Add this QuestionModel to the list
                answeredquestions.Add(actansweredquestion);
            }

            //Add the list of the questionmodels to the model
            ucm.AnsweredQuesitions = answeredquestions;

            return View(ucm);
        }