Exemplo n.º 1
0
        public ActionResult Login(string loginEmail, string loginPassword, string redirectPage)
        {
            // login with email and password

            User user = UserDB.FindByEmail(loginEmail);

            if (user == null)
            {
                //未注册
                //ViewBag.loginSuccess = -1;
                return(RedirectToAction("Index", "Auth", new { type = 1, status = -1 }));
            }
            else
            {
                if (loginPassword.Equals(user.password))
                {
                    Session["user"] = user;
                    //ViewBag.loginSuccess = 1;
                    // ViewBag.user = user;
                    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(RedirectToAction("Index", redirectPage));
                }
                else
                {
                    //密码错误
                    ViewBag.loginSuccess = 0;
                    return(RedirectToAction("Index", "Auth", new { type = 0, status = 0 }));
                }
            }
        }
Exemplo n.º 2
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());
        }
Exemplo 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());
        }
Exemplo n.º 4
0
 public ActionResult UnFollow(int following_id)
 {
     // userId 指follow对象
     // todo
     if ((User)Session["user"] != null)
     {
         int user_id = ((User)Session["user"]).id;
         FollowDB.Delete(user_id, following_id);
         Notice notice = new Notice(0, user_id, following_id, 0, "unfollow", false, DateTime.Now);
         NoticeDB.Insert(notice);
         return(Json(new { success = 1 }));
     }
     else
     {
         return(Json(new { success = 0 }));
     }
 }
Exemplo n.º 5
0
        // GET: Message
        public ActionResult Index(int type)
        {
            ViewBag.type   = type.ToString();
            ViewBag.active = "Message/Index?type=" + type.ToString();
            if (Session["user"] != null)
            {
                User user = (User)Session["user"];
                ViewBag.user = user;

                ViewBag.followNotice  = NoticeDB.FindAllNoticeByUserIdNType(user.id, "follow");
                ViewBag.likeNotice    = NoticeDB.FindAllNoticeByUserIdNType(user.id, "like");
                ViewBag.commentNotice = NoticeDB.FindAllNoticeByUserIdNType(user.id, "comment");
                ViewBag.replyNotice   = NoticeDB.FindAllNoticeByUserIdNType(user.id, "reply");
            }

            return(View());
        }
Exemplo n.º 6
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 = "用户尚未登录" }));
            }
        }
Exemplo n.º 7
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());
        }
Exemplo n.º 8
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
        }
Exemplo n.º 9
0
 public ActionResult ReadNotice(int notice_id)
 {
     NoticeDB.UpdateIsread(notice_id, true);
     return(Json(new { success = 1 }));
 }
Exemplo 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());
        }