Esempio n. 1
0
        /// <summary>
        /// Shows the page of a tag
        /// </summary>
        /// <param name="id">Tag id</param>
        /// <param name="page">Page number</param>
        /// <returns></returns>
        public ActionResult Tag(int id, int? page)
        {
            var actpage = page ?? 1;
            var qman = new QuestionManager();
            var tman = new TagManager();
            int total;
            var allresult = qman.AllQuestionToOneTagToPagedList(id,actpage,10,out total);
            ViewBag.OnePageOfProducts = new StaticPagedList<Question>(allresult, actpage, 10, total);
            ViewBag.Page = actpage;
            ViewBag.Tag = tman.GetTagById(id);
            ViewBag.MorePage = total - allresult.Count();

            return View();
        }
Esempio n. 2
0
        /// <summary>
        /// Listázza az egy kérdéshez kapcsolódó egyéb kérdéseket
        /// </summary>
        /// <param name="questionid">Kérdés ID</param>
        /// <returns></returns>
        public List<Question> GetRelatedQuestions(int questionid)
        {
            using (var db = new SoAContext())
            {

                var tman = new TagManager();

                //Lekérdezzük a kérdéshez tartozó tag-eket
                var tags = HttpContext.Current.Cache.GetFromCache("QuestionTags" + questionid, () => tman.GetAllTagToOneQuestion(questionid).Select(x => x.Id).ToList());

                //Vesszük azon kérdéseket, amelyek ezek közül valamelyiket tartalmazzák, közüllük pedig a legfrissebb 10-et kiválasztjuk
                var releateds = HttpContext.Current.Cache.GetFromCache("ReleatedQuestions" + questionid, () => db.Questions.Where(q => q.QuestionHasTags.Any(qht => tags.Contains(qht.TagId)) && q.Id != questionid).OrderByDescending(d => d.Date).Take(10).ToList());
                return releateds;
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Lists the tags
 /// </summary>
 /// <returns></returns>
 public ActionResult ListAllTags()
 {
     //Manager classes
     var tim = new TagManager();
     var qim = new QuestionManager();
     var tags = tim.GetAllTag();
     //We list the tags
     var retlist = new List<TagListModel>();
     foreach (var item in tags)
     {
         var add = new TagListModel();
         add.Tag = item;
         int count;
         qim.AllQuestionToOneTagToPagedList(item.Id, 1, 1, out count);
         add.Questions = count;
         retlist.Add(add);
     }
     return View(retlist.OrderByDescending(q => q.Questions).ToList());
 }
Esempio n. 4
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);
        }
Esempio n. 5
0
 /// <summary>
 /// Lists the tags to the home page
 /// </summary>
 /// <returns></returns>
 public ActionResult GetTags()
 {
     var tim = new TagManager();
     return PartialView("_GetTags", tim.GetAllTag());
 }
Esempio n. 6
0
        public ActionResult GetQuestion(int id)
        {
            //Manager objects
            var manager = new QuestionManager();
            var ansman = new AnswerManager();
            var usman = new UserManager();
            var tagman = new TagManager();

            var actQues = manager.GetQuestion(id);
            var model = new GetQuestionModels();
            model.CurrentQuestion = actQues;

            //We gets the answers which belong to this question
            model.Answers = ansman.GetAllAnswerToOneQuestion(id);
            //We gets the vote of the question
            model.Vote = manager.GetVote(model.CurrentQuestion.Id);
            //We lists the tags of the question
            model.QuestionTags = tagman.GetAllTagToOneQuestion(id);

            //We gets the votes of the answers
            Dictionary<Answer, int> ansvotes = new Dictionary<Answer, int>();
            Dictionary<Answer, UserProfile> answeruser = new Dictionary<Answer, UserProfile>();
            foreach (var item in model.Answers)
            {
                int vote = ansman.GetVote(item.Id);
                UserProfile userprof = usman.GetUserById(item.UserId);
                answeruser.Add(item, userprof);
                ansvotes.Add(item, vote);
            }
            //We creates the viewmodel
            model.AnswerVotes = ansvotes;
            model.AnswerUser = answeruser;
            model.QuestionUser = usman.GetUserById(model.CurrentQuestion.UserId);
            model.Answers = model.Answers.OrderByDescending(d => model.AnswerVotes[d]).ToList();
            return View(model);
        }
Esempio n. 7
0
        /// <summary>
        /// Function to list the tags
        /// </summary>
        /// <param name="prefix">Prefix</param>
        /// <returns></returns>
        public ActionResult FindTags(string prefix)
        {
            var manager = new TagManager();
            var tagList = manager.GetAllTag();

            //We create a list with the name of tags
            var tagName = new List<string>();
            foreach (var tag in tagList)
            {
                tagName.Add(tag.Name);
            }

            //We create a list with the tags and a temporary id for them
            var allTags = new List<KeyValuePair<int, string>>();
            int i = 1;
            foreach (var name in tagName)
            {
                allTags.Add(new KeyValuePair<int, string>(i, name));
                i++;
            }

            //We select the tags which contains the typed prefix
            var result = (from l in allTags
                      where l.Value.StartsWith(prefix, StringComparison.InvariantCultureIgnoreCase)
                      orderby l.Value
                      select l).ToList();

            return Json(result, JsonRequestBehavior.AllowGet);
        }