Esempio n. 1
0
 //按照时间排序
 public List<TopicInfo> orderByQTime(List<TopicInfo> info)
 {
     TopicInfo temp;
     for (int i = 0; i < info.Count(); i++)
     {
         for (int j = info.Count() - 1; j > i; j--)
         {
             if (info[j].question.QTime.ToOADate() > info[j - 1].question.QTime.ToOADate())
             {
                 temp = new TopicInfo();
                 temp = info[j];
                 info[j] = info[j - 1];
                 info[j - 1] = temp;
             }
         }
     }
     return info;
 }
Esempio n. 2
0
 //按照评价数排序
 public List<TopicInfo> orderByAUpvoteNum(List<TopicInfo> info)
 {
     TopicInfo temp;
     for (int i = 0; i < info.Count(); i++)
     {
         for (int j = info.Count() - 1; j > i; j--)
         {
             if (info[j].hotAnswer.AUpvoteNum > info[j - 1].hotAnswer.AUpvoteNum)
             {
                 temp = new TopicInfo();
                 temp = info[j];
                 info[j] = info[j - 1];
                 info[j - 1] = temp;
             }
         }
     }
     return info;
 }
Esempio n. 3
0
        //首页新鲜事包括:他关注的话题下 点赞最多的回答
        public IndexModel loadIndex(int id)
        {
            IndexModel im = new IndexModel();
            im.myUser = new User();
            im.myUser = db.Users.Find(id);
            im.info = new List<TopicInfo>();
            IEnumerable<FollowTopic> f = db.FollowTopics.Where(d => d.FTUserID == id);
            for (var i = 0; i < f.Count(); i++)
            {
                //关注话题下的热门问题
                List<TopicInfo> temp = getStarQuestion(id, f.ToList()[i].FollowingTID);
                //取前3个放入im.info
                for (var j = 0; j < 3 && j < temp.Count(); j++)
                {
                    TopicInfo ti = new TopicInfo();
                    ti = temp[j];
                    im.info.Add(ti);
                }
            }
            //新登录用户,自动推荐几个话题
            if (im.info.Count() == 0)
            {
                //话题
                List<TopicInfo> temp = getStarQuestion(id, 5);//未归类话题
                temp = orderByAUpvoteNum(temp);
                //取前3个放入im.info
                for (var j = 0; j < 3 && j < temp.Count(); j++)
                {
                    TopicInfo ti = new TopicInfo();
                    ti = temp[j];
                    im.info.Add(ti);
                }

            }
            im.info = orderByQTime(im.info);
            im.ua = getUserActivity(id);
            im.ua = orderByTime(im.ua);
            return im;
        }
Esempio n. 4
0
        //获得某个话题的精华回答
        //参数:登陆用户id, 话题topicId
        public List<TopicInfo> getStarQuestion(int id, int topicID)
        {
            TopicStarModel tm = new TopicStarModel();
            tm.myUser = db.Users.Find(id);
            tm.topic = new TopicPreNext();
            tm.topic.topic = db.Topics.Find(topicID);
            tm.topic.fatherTopic = db.Topics.Find(tm.topic.topic.TFatherID);
            tm.topic.childTopic = db.Topics.Where(t => t.TFatherID == id).ToList();

            List<TopicQuestion> info = new List<TopicQuestion>();
            info.Add(getBestAnswerByTopic(tm.topic.topic));
            //for (int i = 0; i < tm.topic.childTopic.Count(); i++)
               // {
            //    info.Add(getBestAnswerByTopic(tm.topic.childTopic[i]));
               // }
            tm.question = new List<TopicInfo>();
            for (int i = 0; i < info.Count(); i++)
            {
                for (var j = 0; j < info[i].question.Count(); j++)
                {
                    if (info[i].HotAnswer[j].AUpvoteNum > 1)
                    {
                        TopicInfo tq = new TopicInfo();
                        tq.topic = info[i].topic;
                        tq.question = info[i].question[j];
                        tq.hotUser = info[i].HotUser[j];
                        tq.hotAnswer = info[i].HotAnswer[j];
                        tq.timeSpan = getTimeSpan(info[i].question[j].QTime);
                        tm.question.Add(tq);
                    }
                }
            }
            return tm.question;
        }
Esempio n. 5
0
        //topic id
        //话题下的所有问题,动态,时间排序
        public ActionResult newest(int id)
        {
            TopicNewestModel tm = new TopicNewestModel();
            tm.myUser = db.Users.Find(getCookie("id"));
            tm.topic = new TopicPreNext();
            tm.topic.topic = db.Topics.Find(id);
            tm.topic.fatherTopic = db.Topics.Find(tm.topic.topic.TFatherID);
            tm.topic.childTopic = db.Topics.Where(t => t.TFatherID == id).ToList();

            tm.question = new List<TopicInfo>();
            TopicQuestion temp = model.getBestAnswerByTopic(tm.topic.topic);

            for (int i = 0; i < tm.topic.topic.QuestionNum; i++)
            {
                TopicInfo questionInfo = new TopicInfo();
                questionInfo.topic = temp.topic;
                questionInfo.question = temp.question[i];
                questionInfo.hotAnswer = temp.HotAnswer[i];
                questionInfo.hotUser = temp.HotUser[i];
                tm.question.Add(questionInfo);
            }
            List<TopicQuestion> childQuestion = new List<TopicQuestion>();
            for (int i = 0; i < tm.topic.childTopic.Count(); i++)
            {
                temp = model.getBestAnswerByTopic(tm.topic.childTopic[i]);
                for (int j = 0; j < tm.topic.childTopic[i].QuestionNum; j++)
                {
                    TopicInfo questionInfo = new TopicInfo();
                    questionInfo.topic = tm.topic.childTopic[i];
                    questionInfo.question = temp.question[j];
                    questionInfo.hotUser = temp.HotUser[j];
                    questionInfo.hotAnswer = temp.HotAnswer[j];
                    tm.question.Add(questionInfo);
                }
            }
            tm.question = model.orderByQTime(tm.question);

            for (int i = 0; i < tm.question.Count(); i++)
            {
                tm.question[i].timeSpan = model.getTimeSpan(tm.question[i].question.QTime);
            }

            IEnumerable<FollowTopic> IsFocus = db.FollowTopics.Where(a => a.FollowingTID == tm.topic.topic.TID).Where(b => b.FTUserID == tm.myUser.UID);
            if (IsFocus.Count() != 0)
            {
                ViewBag.flag = "focus";
            }
            else
            {
                ViewBag.flag = "nofocus";
            }
            return View(tm);
        }
Esempio n. 6
0
        //topic id
        //话题下的精品回答
        public ActionResult StarQuestion(int id)
        {
            TopicStarModel tm = new TopicStarModel();
            tm.myUser = db.Users.Find(getCookie("id"));
            tm.topic = new TopicPreNext();
            tm.topic.topic = db.Topics.Find(id);
            tm.topic.fatherTopic = db.Topics.Find(tm.topic.topic.TFatherID);
            tm.topic.childTopic = db.Topics.Where(t => t.TFatherID == id).ToList();

            List<TopicQuestion> info = new List<TopicQuestion>();
            info.Add(model.getBestAnswerByTopic(tm.topic.topic));
            for (int i = 0; i < tm.topic.childTopic.Count(); i++)
            {
                info.Add(model.getBestAnswerByTopic(tm.topic.childTopic[i]));
            }

            tm.question = new List<TopicInfo>();
            for (int i = 0; i < info.Count(); i++)
            {
                for (var j = 0; j < info[i].question.Count(); j++)
                {
                    if (info[i].HotAnswer[j].AUpvoteNum > 0)
                    {
                        TopicInfo tq = new TopicInfo();
                        tq.topic = info[i].topic;
                        tq.question = info[i].question[j];
                        tq.hotUser = info[i].HotUser[j];
                        tq.hotAnswer = info[i].HotAnswer[j];
                        tq.timeSpan = model.getTimeSpan(info[i].question[j].QTime);
                        tm.question.Add(tq);
                    }
                }
            }
            tm.question = model.orderByAUpvoteNum(tm.question);

            IEnumerable<FollowTopic> IsFocus = db.FollowTopics.Where(a => a.FollowingTID == tm.topic.topic.TID).Where(b => b.FTUserID == tm.myUser.UID);
            if (IsFocus.Count() != 0)
            {
                ViewBag.flag = "focus";
            }
            else
            {
                ViewBag.flag = "nofocus";
            }
            return View(tm);
        }