Ejemplo n.º 1
0
 public ActionResult Index()
 {
     //如果用户已经注册 直接跳转到首页
     if (getCookie("id") != -1)
     {
         int        id = getCookie("id");
         IndexModel m  = model.loadIndex(id);
         return(View("newIndex", m));
     }
     else
     {
         indexModel index = new indexModel();
         index.topics   = db.Topics.ToList();
         index.question = new List <List <Question> >();
         for (int i = 0; i < index.topics.Count(); i++)
         {
             List <Question> a   = new List <Question>();
             int             tid = index.topics[i].TID;
             a = db.Questions.Where(d => d.QTopicType1 == tid).ToList();
             index.question.Add(a);
         }
         return(View(index));
     }
 }
Ejemplo n.º 2
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;
        }