Ejemplo n.º 1
0
        public ActionResult Index()
        {
            ViewBag.message = true;
            List <WeikeData> weikes = WeikeDB.GetAllWeikeOrderByStar();

            ViewBag.data = weikes;

            List <int> favoriteWeikeId = new List <int>();

            if (Session["user"] != null)
            {
                User user = (User)Session["user"];
                List <FavoriteData> fdList = FavoriteDB.FindFavoriteWeikeByUserId(user.id);
                foreach (FavoriteData fd in fdList)
                {
                    favoriteWeikeId.Add(fd.weike.weike_id);
                }

                ViewBag.followNoticeNum  = NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "follow").Count + NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "unfollow").Count;
                ViewBag.likeNoticeNum    = NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "like").Count + NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "dislike").Count;
                ViewBag.commentNoticeNum = NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "comment").Count;
                ViewBag.replyNoticeNum   = NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "reply").Count;
            }
            ViewBag.favoriteWeikes = favoriteWeikeId;

            //List<WeikeModel> list = new List<WeikeModel>();
            //list.Add(new WeikeModel { title = "Senseless Suffering", subject = "English", author = "Jeremy Bentham", src = "../resource/img/8.jpg", size = "1280x853", description = "The question is not, 'Can they reason ?' nor, 'Can they talk ? ' but rather, 'Can they suffer ? '", star = 0 });
            //list.Add(new WeikeModel { title = "Rabbit Intelligence", subject = "English", author = "Robert Brault", src = "../resource/img/9.jpg", size = "865x1280", description = "If a rabbit defined intelligence the way man does, then the most intelligent animal would be a rabbit, followed by the animal most willing to obey the commands of a rabbit.", star = 44 });
            //list.Add(new WeikeModel { title = "Friendly Terms", subject = "English", author = "Samuel Butler", src = "../resource/img/10.jpg", size = "1280x1280", description = "Man is the only animal that can remain on friendly terms with the victims he intends to eat until he eats them. ", star = 44 });
            //list.Add(new WeikeModel { title = "Murder of Men", subject = "English", author = "Leonardo Da Vinci", src = "../resource/img/11.jpg", size = "1280x1280", description = "The time will come when men such as I will look upon the murder of animals as they now look upon the murder of men. ", star = 44 });
            //list.Add(new WeikeModel { title = "Highest Ethics", subject = "Math", author = "Thomas Edison", src = "../resource/img/1.jpg", size = "1280x853", description = "Non-violence leads to the highest ethics, which is the goal of all evolution. Until we stop harming all other living beings, we are still savages ", star = 44 });
            //ViewBag.data = list;
            return(View());
        }
Ejemplo n.º 2
0
        public ActionResult Favorite(int user_id, int following_id)
        {
            Favorite favorite = new Favorite(user_id, following_id, DateTime.Now);

            FavoriteDB.Insert(favorite);
            return(Json(true));
        }
Ejemplo n.º 3
0
        public ActionResult playground(string type, string keyword)
        {
            List <WeikeData> weikes = new List <WeikeData>();

            ViewBag.message = false;
            ViewBag.type    = type;
            ViewBag.keyword = keyword;
            if (type == "标题")
            {
                weikes          = WeikeDB.FindByTitle(keyword);
                ViewBag.message = true;
            }
            else if (type == "作者")
            {
                weikes          = WeikeDB.FindByAuthor(keyword);
                ViewBag.message = true;
            }
            else if (type == "学科")
            {
                weikes          = WeikeDB.FindBySubject(keyword);
                ViewBag.message = true;
            }
            ViewBag.data = weikes;
            if (Session["user"] != null)
            {
                User user = (User)Session["user"];
                ViewBag.user = user;
                List <FavoriteData>          fdList = FavoriteDB.FindFavoriteWeikeByUserId(user.id);
                Dictionary <WeikeData, bool> weikeDataWithFavorite = new Dictionary <WeikeData, bool>();
                bool hasFavorite = false;
                foreach (WeikeData wdata in weikes)
                {
                    hasFavorite = false;
                    foreach (FavoriteData fdata in fdList)
                    {
                        if (wdata.weike.weike_id == fdata.weike.weike_id)
                        {
                            hasFavorite = true;
                            break;
                        }
                    }
                    weikeDataWithFavorite.Add(wdata, hasFavorite);
                }
                ViewBag.weikeDataWithFavorite = weikeDataWithFavorite;

                ViewBag.followNoticeNum  = NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "follow").Count + NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "unfollow").Count;
                ViewBag.likeNoticeNum    = NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "like").Count + NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "dislike").Count;
                ViewBag.commentNoticeNum = NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "comment").Count;
                ViewBag.replyNoticeNum   = NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "reply").Count;
            }
            return(View());
        }
Ejemplo n.º 4
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 }));
        }
Ejemplo n.º 5
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 = "用户尚未登录" }));
            }
        }
Ejemplo n.º 6
0
        public ActionResult playground()
        {
            ViewBag.message = true;
            List <WeikeData> weikes = WeikeDB.GetAllWeikeOrderByDate();

            foreach (WeikeData wd in weikes)
            {
                wd.attachment = MyFileDB.FindByWeikeId(wd.weike.weike_id);
            }
            ViewBag.data = weikes;
            if (Session["user"] != null)
            {
                User user = (User)Session["user"];
                ViewBag.user = user;
                List <FavoriteData>          fdList = FavoriteDB.FindFavoriteWeikeByUserId(user.id);
                Dictionary <WeikeData, bool> weikeDataWithFavorite = new Dictionary <WeikeData, bool>();
                bool hasFavorite = false;
                foreach (WeikeData wdata in weikes)
                {
                    hasFavorite = false;
                    foreach (FavoriteData fdata in fdList)
                    {
                        if (wdata.weike.weike_id == fdata.weike.weike_id)
                        {
                            hasFavorite = true;
                            break;
                        }
                    }
                    weikeDataWithFavorite.Add(wdata, hasFavorite);
                }
                ViewBag.weikeDataWithFavorite = weikeDataWithFavorite;

                ViewBag.followNoticeNum  = NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "follow").Count + NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "unfollow").Count;
                ViewBag.likeNoticeNum    = NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "like").Count + NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "dislike").Count;
                ViewBag.commentNoticeNum = NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "comment").Count;
                ViewBag.replyNoticeNum   = NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "reply").Count;
            }
            return(View());
        }
        public bool AddFavorite(int userID, int dishID)
        {
            Response<Favorite> response;
            FavoriteDB favoriteDB = new FavoriteDB();
            bool exists = favoriteDB.Exists(userID, dishID);

            if(!exists)
            {
                Favorite favorite = new Favorite();
                favorite.DishID = dishID;
                favorite.UserID = userID;

                response = favorite.Create();

            }
            else
            {
                //if the favorite does exists
                response = new Response<Favorite>();
            }

            return response.Success;
        }
        public List<Favorite> GetFavoritesByUserID(int userid)
        {
            //Stub
            FavoriteDB favoriteDB = new FavoriteDB();
            List<Favorite> favorites = favoriteDB.GetByUserID(userid);

            return favorites;
        }
        public bool DeleteFavorites(List<Favorite> favorites)
        {
            FavoriteDB favoriteDB = new FavoriteDB();
            //batch delete here.
            Response<Favorite> response = favoriteDB.DeleteBatch(favorites);

            return response.Success;
        }
Ejemplo n.º 10
0
        public ActionResult PersonalPageWeike(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
            {
                ViewBag.followNoticeNum  = NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "follow").Count + NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "unfollow").Count;
                ViewBag.likeNoticeNum    = NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "like").Count + NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "dislike").Count;
                ViewBag.commentNoticeNum = NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "comment").Count;
                ViewBag.replyNoticeNum   = NoticeDB.FindUnReadNoticeByUserIdNType(user.id, "reply").Count;
                if (userId == user.id)
                {
                    ViewBag.isCurrentUser = true;
                    ViewBag.hasFollow     = false;
                }
                else
                {
                    fdList                = FollowDB.FindAllFollowings(user.id);
                    ViewBag.hasFollow     = false;
                    ViewBag.isCurrentUser = false;
                    foreach (FollowData fd in fdList)
                    {
                        if (fd.follow.following_id == userId)
                        {
                            ViewBag.hasFollow = true;
                            break;
                        }
                    }
                }

                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 <WeikeData>             wdList            = WeikeDB.FindByUserId(userId);
            Dictionary <WeikeData, bool> weikeData         = new Dictionary <WeikeData, bool>();
            List <FavoriteData>          FavoriteWeikeList = FavoriteDB.FindFavoriteWeikeByUserId(user.id);
            bool hasFavorited = false;

            foreach (WeikeData weike in wdList)
            {
                hasFavorited = false;
                foreach (FavoriteData fw in FavoriteWeikeList)
                {
                    if (weike.weike.weike_id == fw.weike.weike_id)
                    {
                        hasFavorited = true;
                    }
                }
                weikeData.Add(weike, hasFavorited);
            }
            ViewBag.weikeData  = weikeData;
            ViewBag.active     = "PersonalPage/PersonalPageWeike?userId=" + userId;
            ViewBag.fromAction = "PersonalPageWeike";

            return(View());
        }
Ejemplo n.º 11
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());
        }
Ejemplo n.º 12
0
        public ActionResult MyFavorites(int user_id)
        {
            List <FavoriteData> favorites = FavoriteDB.FindFavoriteWeikeByUserId(user_id);

            return(Json(favorites));
        }
Ejemplo n.º 13
0
 public ActionResult CancelFavorite(int user_id, int following_id)
 {
     FavoriteDB.Delete(user_id, following_id);
     return(Json(true));
 }