Esempio n. 1
0
        public ActionResult WeikeDetail(int weikeId)
        {
            // get comment list
            WeikeData data = WeikeDB.FindByWeikeId(weikeId);

            return(Json(new { weikeData = data }));
        }
Esempio n. 2
0
        public ActionResult WeikeDetailWithComment(int weikeId)
        {
            WeikeData            weikeDetail = WeikeDB.FindByWeikeId(weikeId);
            List <NestedComment> comments    = NestedComment.getAllCommentsByWeikeId(weikeId);
            User user = (User)Session["user"];
            List <FavoriteData> FavoriteWeikeList = FavoriteDB.FindFavoriteWeikeByUserId(user.id);
            bool hasFavorited = false;

            foreach (FavoriteData fw in FavoriteWeikeList)
            {
                if (weikeId == fw.weike.weike_id)
                {
                    hasFavorited = true;
                }
            }
            return(Json(new { weikeData = weikeDetail, comments = comments, hasFavorited = hasFavorited }));
        }
Esempio n. 3
0
        public ActionResult Dislike(int weikeId)
        {
            // todo

            if ((User)Session["user"] != null)
            {
                int user_id = ((User)Session["user"]).id;
                FavoriteDB.Delete(user_id, weikeId);
                WeikeData wd     = WeikeDB.FindByWeikeId(weikeId);
                Notice    notice = new Notice(0, user_id, wd.weike.user_id, weikeId, "dislike", false, DateTime.Now);
                NoticeDB.Insert(notice);
                return(Json(new { success = true }));
            }
            else
            {
                return(Json(new { success = false, message = "用户尚未登录" }));
            }
        }
Esempio n. 4
0
        public ActionResult makeComment(int commentTargetId, string content, int weikeId)
        {
            // todo
            if ((User)Session["user"] != null)
            {
                int    user_id  = ((User)Session["user"]).id;
                string username = ((User)Session["user"]).name;
                if (commentTargetId != 0)
                {
                    Comment parent        = CommentDB.FindCommentById(commentTargetId);
                    int     parent_userId = parent.user_id;
                    if (user_id == parent_userId)
                    {
                        return(Json(new { success = -1 }));
                    }
                    Notice notice = new Notice(0, user_id, parent_userId, weikeId, "reply", false, DateTime.Now);
                    NoticeDB.Insert(notice);
                }
                else
                {
                    int    userId = WeikeDB.FindByWeikeId(weikeId).weike.user_id;
                    Notice notice = new Notice(0, user_id, userId, weikeId, "comment", false, DateTime.Now);
                    NoticeDB.Insert(notice);
                }
                DateTime now        = DateTime.Now;
                Comment  comment    = new Comment(0, user_id, weikeId, now, content, commentTargetId);
                int      comment_id = CommentDB.Insert(comment);
                return(Json(new { success = 1, commentId = comment_id, username = username, time = now }));
            }
            else
            {
                return(Json(new { success = 0 }));
            }

            // id of the new comment
        }
Esempio n. 5
0
        public ActionResult PersonalPageLikes(int userId)
        {
            User user = (User)Session["user"];
            List <FollowData> cuFdList         = FollowDB.FindAllFollowings(userId);
            List <FollowData> fdList           = new List <FollowData>();
            List <User>       commonFollowList = new List <User>();

            if (user == null)
            {
                ViewBag.isCurrentUser = false;
                ViewBag.hasFollow     = false;
            }
            else if (userId == user.id)
            {
                ViewBag.isCurrentUser = true;
                ViewBag.hasFollow     = false;
            }
            else
            {
                fdList            = FollowDB.FindAllFollowings(user.id);
                ViewBag.hasFollow = false;
                foreach (FollowData fd in fdList)
                {
                    if (fd.follow.following_id == userId)
                    {
                        ViewBag.hasFollow = true;
                        break;
                    }
                }
                ViewBag.isCurrentUser = false;

                foreach (FollowData fd in fdList)
                {
                    foreach (FollowData cufd in cuFdList)
                    {
                        if (fd.follow.following_id == cufd.follow.following_id)
                        {
                            commonFollowList.Add(UserDB.FindById(cufd.follow.following_id));
                        }
                    }
                }
            }
            ViewBag.commonFollowList = commonFollowList;
            ViewBag.popularWeikeList = WeikeDB.FindByUserId(userId, 3);

            User infoUser = UserDB.FindById(userId);
            Dictionary <string, string> personalInfo = new Dictionary <string, string>()
            {
                { "id", userId + "" },
                { "name", infoUser.name },
                { "portraitSrc", "../avatars/" + infoUser.avatar },
                { "email", infoUser.email },
                { "des", infoUser.des },
                { "tag", infoUser.tag },
                { "followCount", infoUser.followNum + "" },
                { "likeCount", infoUser.favoriteNum + "" },
                { "weikeCount", infoUser.postNum + "" }
            };

            ViewBag.personalInfo = personalInfo;

            List <FavoriteData> favoriteList      = FavoriteDB.FindFavoriteWeikeByUserId(userId);
            List <WeikeData>    favoriteWeikeList = new List <WeikeData>();

            foreach (FavoriteData fdata in favoriteList)
            {
                favoriteWeikeList.Add(WeikeDB.FindByWeikeId(fdata.weike.weike_id));
            }
            ViewBag.weikeData = favoriteList;


            Dictionary <string, string> follow3 = new Dictionary <string, string>()
            {
                { "id", "100" },
                { "name", "用户名" },
                { "imgSrc", "../resource/img/portrait.jpg" },
                { "email", "*********@qq.com" },
                { "hasFollow", "ture" },
                { "isCurrentUser", "false" }
            };

            ViewBag.active     = "PersonalPage/PersonalPageLikes?userId=" + userId;
            ViewBag.fromAction = "PersonalPageLikes";

            return(View());
        }