Пример #1
0
        public ActionResult Index()
        {
            var _user = SessionSet <User> .Get("login");

            List <TweetDto> list = new List <TweetDto>();

            list.Clear();
            if (_user != null)
            {
                var mymodel = (from uf in _repo.Query <UserFriends>()
                               join
                               t in _repo.Query <Tweet>() on uf.FriendId equals t.UserId
                               where (uf.UserId == _user.Id ||
                                      t.UserId == _user.Id) && t.IsDeleted == false
                               select new TweetDto()
                {
                    Id = t.Id,
                    Body = t.Body,
                    UserName = uf.Friend.UserName
                }).Distinct().ToList();               //liste halinde commentlist ini görüntüle!
                foreach (TweetDto model in mymodel)
                {
                    list.Add(model);
                }

                list = mymodel.OrderByDescending(x => x.CreateDate).ToList();


                return(View(list));
            }
            else
            {
                return(RedirectToAction("Login", "Login"));
            }
        }
Пример #2
0
        //BaseRepository<Like> _repo = new BaseRepository<Like>();

        public ActionResult Index()
        {
            var _user = SessionSet <User> .Get("login");

            if (_user != null)
            {
                using (BaseRepository <Post> _repo = new BaseRepository <Post>())
                {
                    var mymodel = (from u in _repo.Query <User>()
                                   join
                                   p in _repo.Query <Post>() on u.Id equals p.UserId
                                   where (u.Id == _user.Id) && p.IsDeleted == false
                                   orderby p.CreateDate descending
                                   select new PostDto()
                    {
                        Id = p.Id,
                        Body = p.Body,
                        UserName = u.UserName,
                    }).Distinct().ToList();
                    mymodel.Reverse();
                    return(View(mymodel));
                }
            }
            else
            {
                return(RedirectToAction("Login", "Login"));
            }
        }
Пример #3
0
        public ActionResult AddFriend(int id)
        {
            var user = SessionSet <User> .Get("Login");

            RelationShip rs = new RelationShip()
            {
                User1ID      = user.ID,
                User2ID      = id,
                CreatedDate  = DateTime.Now,
                ActionUserID = user.ID,
                StatusID     = 1
            };

            _br.AddModel(rs);
            Notification notify = new Notification()
            {
                UserID      = user.ID,
                ActionID    = 1,
                PostUserID  = id,
                IsShow      = true,
                NotifyText  = user.Name + " wants to add you as a friend.",
                CreatedDate = DateTime.Now
            };

            _db.Notifications.Add(notify);
            _db.SaveChanges();

            return(RedirectToAction("Home", "Home"));
        }
Пример #4
0
        public ActionResult ConnectWithYourself()
        {
            var _user = SessionSet <User> .Get("login");

            int FriendId = SessionSet <User> .Get("login").Id;

            int myId = _user.Id;

            UserFriends uf0 = new UserFriends();

            uf0.UserId     = myId;
            uf0.FriendId   = FriendId;
            uf0.CreateDate = DateTime.Now;

            var result = postRepo.Query <UserFriends>().Where(k => (k.UserId == uf0.UserId) && (k.FriendId == uf0.FriendId)).FirstOrDefault();

            if (result == null)
            {
                db.UserFriends.Add(uf0);
                db.SaveChanges();
            }


            return(RedirectToAction("Index", "Home"));
        }
Пример #5
0
        public ActionResult ReTweet(int id)
        {
            var user = SessionSet <User> .Get("Login").ID;

            Tweet tweet  = _br.Query <Tweet>().Where(k => k.ID == id).FirstOrDefault();
            var   rtList = _db.Retweets.ToList();
            var   result = _br.Query <Retweet>().Where(k => k.TweetID == id && k.UserID == user).Any();

            if (!result)
            {
                Retweet rt = new Retweet()
                {
                    UserID      = user,
                    TweetID     = id,
                    CreatedDate = DateTime.Now
                };
                _db.Retweets.Add(rt);
                _db.SaveChanges();
            }
            else
            {
                var retwDel = rtList.Where(k => k.TweetID == id && k.UserID == user).FirstOrDefault();
                _db.Retweets.Remove(retwDel);
                _db.SaveChanges();
            }



            return(RedirectToAction("Home", "Home"));
        }
Пример #6
0
        public ActionResult SubmitList(int id)
        {
            var _user = SessionSet <User> .Get("login");

            var friend = _repo.Query <Submit>().FirstOrDefault(k => k.Id == id);

            List <SubmitDto> list = new List <SubmitDto>();

            list.Clear();
            if (_user != null)
            {
                var mymodel = (from t in _repo.Query <Comment>()

                               where (t.ParentId == friend.Id) && t.IsDeleted == false
                               select new SubmitDto()
                {
                    Id = t.Id,
                    Body = t.Body,
                    UserName = t.User.UserName
                }).ToList();
                mymodel.Reverse();
                foreach (SubmitDto model in mymodel)
                {
                    list.Add(model);
                }



                return(View(list));
            }
            return(View());
        }
Пример #7
0
        // GET: Profile
        public ActionResult Index()
        {
            var _user = SessionSet <User> .Get("login");

            if (_user != null)
            {
                using (BaseRepository <Submit> _repo = new BaseRepository <Submit>())
                {
                    var mymodel = (from u in _repo.Query <User>()
                                   join
                                   t in _repo.Query <Submit>() on u.Id equals t.UserId
                                   where u.Id == _user.Id && t.IsDeleted == false
                                   orderby t.CreateDate descending
                                   select new SubmitDto()
                    {
                        Id = t.Id,
                        Body = t.Body,
                        UserName = u.UserName,
                    }).Distinct().ToList();
                    mymodel.Reverse();
                    return(View(mymodel));
                }
            }
            else
            {
                return(RedirectToAction("StartPage", "Home"));
            }
        }
Пример #8
0
        public ActionResult PostLike(int id)
        {
            var user = SessionSet <User> .Get("Login");

            var postUserID = _br.Query <Post>().Where(k => k.ID == id).FirstOrDefault().UserID;

            if (!_brLike.Query <Like>().Where(k => k.PostID == id && k.LikeUserID == user.ID).Any())
            {
                Like addLike = new Like()
                {
                    LikeUserID = user.ID,
                    PostID     = id
                };
                _brLike.AddModel(addLike);
                Notification notify = new Notification()
                {
                    UserID      = user.ID,
                    ActionID    = 2,
                    PostUserID  = postUserID,
                    IsShow      = true,
                    NotifyText  = user.Name + " liked your post.",
                    CreatedDate = DateTime.Now
                };
                _db.Notifications.Add(notify);
                _db.SaveChanges();
            }
            else
            {
                var delLike = _brLike.Query <Like>().Where(k => k.PostID == id && k.LikeUserID == user.ID).FirstOrDefault();
                _db.Entry(delLike).State = EntityState.Deleted;
                _db.SaveChanges();
            }

            return(RedirectToAction("Home", "Home"));
        }
Пример #9
0
        public ActionResult Search(string username)
        {
            var _user = SessionSet <User> .Get("login");

            var user_name = loginRepo.Query <Tweet>().FirstOrDefault(k => k.UserName == username).UserName;

            List <TweetDto> list = new List <TweetDto>();

            list.Clear();
            if (_user != null)
            {
                var mymodel = (from t in loginRepo.Query <Tweet>()

                               where (t.UserName == user_name) && t.IsDeleted == false
                               select new TweetDto()
                {
                    Id = t.Id,
                    Body = t.Body,
                    UserName = t.UserName
                }).Distinct().ToList();               //liste halinde commentlist ini görüntüle!
                foreach (TweetDto model in mymodel)
                {
                    list.Add(model);
                }

                list = mymodel.OrderByDescending(x => x.CreateDate).ToList();


                return(View(list));
            }
            else
            {
                return(RedirectToAction("Login", "Login"));
            }
        }
Пример #10
0
        public ActionResult CommentList(int id)
        {
            var _user = SessionSet <User> .Get("login");

            var friend = loginRepo.Query <Tweet>().FirstOrDefault(k => k.Id == id);
            // Tweet tweet = new Tweet();
            List <TweetDto> list = new List <TweetDto>();

            list.Clear();
            if (_user != null)
            {
                var mymodel = (from t in loginRepo.Query <Comment>()

                               where (t.ParentId == friend.Id) && t.IsDeleted == false
                               select new TweetDto()
                {
                    Id = t.Id,
                    Body = t.Body,
                    UserName = t.User.UserName
                }).ToList();
                mymodel.Reverse();
                foreach (TweetDto model in mymodel)
                {
                    list.Add(model);
                }

                //list = mymodel.OrderByDescending(x => x.CreateDate).ToList();


                return(View(list));
            }
            return(View());
        }
Пример #11
0
        public ActionResult GetPost()
        {
            var userID = SessionSet <User> .Get("Login").ID;

            List <PostDto> postList  = new List <PostDto>();
            var            FriendsID = _br.Query <RelationShip>().Where(k => (k.User1ID == userID || k.User2ID == userID) && k.StatusID == 2).ToList();
            List <User>    myFriends = new List <User>();

            foreach (var item in FriendsID)
            {
                User friends = new User();;
                if (item.User1ID == userID)
                {
                    friends = _br.Query <User>().Where(k => k.ID == item.User2ID).FirstOrDefault();
                }
                else
                {
                    friends = _br.Query <User>().Where(k => k.ID == item.User1ID).FirstOrDefault();
                }

                myFriends.Add(friends);
            }

            foreach (var item in myFriends)
            {
                var FriendPostList = _br.Query <Post>().Where(k => k.UserID == item.ID).ToList();
                foreach (var item2 in FriendPostList)
                {
                    PostDto post = new PostDto()
                    {
                        ID          = item2.ID,
                        PostText    = item2.PostText,
                        CreatedDate = item2.CreatedDate,
                        UserName    = item.Name,
                        UserID      = item.ID
                    };
                    postList.Add(post);
                }
            }

            var UserPostList = _br.Query <Post>().Where(k => k.UserID == userID).ToList();

            foreach (var item in UserPostList)
            {
                var     user = _br.Query <User>().Where(k => k.ID == userID).FirstOrDefault();
                PostDto post = new PostDto()
                {
                    ID          = item.ID,
                    PostText    = item.PostText,
                    CreatedDate = item.CreatedDate,
                    UserName    = user.Name,
                    UserID      = userID
                };
                postList.Add(post);
            }
            var orderList = postList.OrderByDescending(k => k.CreatedDate).ToList();

            return(View(orderList));
        }
Пример #12
0
        public ActionResult AddPost(Post newPost)
        {
            newPost.UserId = SessionSet <User> .Get("login").Id;

            newPost.ParentId = 0;

            postRepo.Add(newPost);
            return(RedirectToAction("Index", "Home"));
        }
Пример #13
0
        public ActionResult AddTweet(Tweet newTweet)
        {
            newTweet.UserId = SessionSet <User> .Get("login").Id;

            newTweet.ParentId = 0;

            loginRepo.Add(newTweet);
            return(RedirectToAction("Index", "Home"));
        }
Пример #14
0
        public ActionResult AddTweet(Tweet tweet)
        {
            var user = SessionSet <User> .Get("Login");

            tweet.UserID      = user.ID;
            tweet.ParentID    = 0;
            tweet.CreatedDate = DateTime.Now;
            _br.AddModel(tweet);
            return(RedirectToAction("Home", "Home"));
        }
Пример #15
0
        public ActionResult AddPost(Post post)
        {
            var userID = SessionSet <User> .Get("Login").ID;

            post.CreatedDate = DateTime.Now;
            post.UserID      = userID;
            _br.AddModel(post);

            return(RedirectToAction("Home", "Home"));
        }
Пример #16
0
        public ActionResult Delete(int id)
        {
            var userID = SessionSet <User> .Get("Login").ID;

            var confirm = _br.Query <RelationShip>().Where(k => k.User1ID == id && k.User2ID == userID && k.StatusID == 1).FirstOrDefault();

            _db.Entry(confirm).State = EntityState.Deleted;
            _db.SaveChanges();
            return(RedirectToAction("Home", "Home"));
        }
Пример #17
0
        public ActionResult RemoveFriend(int id)
        {
            var userID = SessionSet <User> .Get("Login").ID;

            var remove = _br.Query <RelationShip>().Where(k => (k.User1ID == id && k.User2ID == userID) || (k.User1ID == userID && k.User2ID == id) && k.StatusID == 2).FirstOrDefault();

            _db.Entry(remove).State = EntityState.Deleted;
            _db.SaveChanges();
            return(RedirectToAction("GetFriendns"));
        }
Пример #18
0
        public ActionResult AddSubmit(Submit newSubmit)
        {
            newSubmit.UserId = SessionSet <User> .Get("login").Id;

            newSubmit.UserName = SessionSet <User> .Get("login").UserName;

            newSubmit.ParentId = 0;

            loginRepo.Add(newSubmit);
            return(RedirectToAction("Index", "Home"));
        }
Пример #19
0
        public ActionResult Home()
        {
            var user = SessionSet <User> .Get("Login");

            if (user.ID != null)
            {
                return(View());
            }
            else
            {
                return(RedirectToAction("Login", "User"));
            }
        }
Пример #20
0
        public ActionResult Home()
        {
            var userID = SessionSet <User> .Get("Login").ID;

            if (userID != null)
            {
                return(View());
            }
            else
            {
                return(RedirectToAction("Start", "Home"));
            }
        }
Пример #21
0
        public ActionResult Liked(Like likeTweet)
        {
            var id = SessionSet <Comment> .Get("get").Id;

            var friend = uRepo.Query <Tweet>().FirstOrDefault(k => k.Id == id);

            likeTweet.UserId = SessionSet <User> .Get("login").Id;

            likeTweet.ParentId = friend.Id;

            _repo.Add(likeTweet);
            return(RedirectToAction("Index", "Home"));
        }
Пример #22
0
        public ActionResult WhoToFollow()
        {
            var myId = SessionSet <User> .Get("Login").ID;

            var notfriends = _db.Database.SqlQuery <int>(
                "SELECT ID FROM Users where ID not IN(SELECT FriendID FROM FriendShips where UserID =   " + myId + ") and ID!=" + myId).ToList();
            List <User> list = new List <User>();

            foreach (int item in notfriends)
            {
                var model = _db.Users.FirstOrDefault(x => x.ID == item);
                list.Add(model);
            }
            return(View(list));
        }
Пример #23
0
        public ActionResult Delete(int id)
        {
            int myId = SessionSet <User> .Get("login").Id;

            var post = postRepo.Query <Post>().FirstOrDefault(k => k.Id == id);

            if (post != null && post.UserId == myId)
            {
                postRepo.Delete(post);

                return(RedirectToAction("Index", "Home"));
            }

            return(RedirectToAction("Index", "Home"));
        }
Пример #24
0
        public ActionResult MyFollowers()
        {
            var myId = SessionSet <User> .Get("Login").ID;

            var following = _db.Database.SqlQuery <string>("select NameLastname from Users Where ID in " +
                                                           "(select f.UserID  from FriendShips f inner join Users u on u.ID=f.UserID  where f.FriendID=" + myId + ")").ToList();
            List <User> list = new List <User>();

            foreach (string item in following)
            {
                var model = _db.Users.FirstOrDefault(x => x.NameLastname == item);
                list.Add(model);
            }
            return(View(list));
        }
Пример #25
0
        public ActionResult Login(User user)
        {
            bool result = Services.LoginService.Login(user);

            if (result)
            {
                User me = SessionSet <User> .Get("User");

                Session["Name"] = me.Name;
                return(RedirectToAction("List", "Layout"));
            }
            else
            {
                return(View());
            }
        }
Пример #26
0
        public ActionResult DeleteTweet(int id)
        {
            var user = SessionSet <User> .Get("Login").ID;


            int delTweetId = Convert.ToInt32(RouteData.Values["id"]);
            var tweet      = _db.Tweets.FirstOrDefault(x => x.ID == delTweetId);

            tweet.ParentID = 0;
            if (tweet != null)
            {
                _br.DeleteModel(tweet.ID);
            }

            return(RedirectToAction("Home", "Home"));
        }
Пример #27
0
        public ActionResult AddComment(string text, int tweetId)
        {
            using (BaseRepository <Comment> _repo = new BaseRepository <Comment>())
            {
                var _user = SessionSet <User> .Get("login");

                Comment cmt = new Comment
                {
                    Body   = text,
                    UserId = _user.Id,

                    ParentId = tweetId
                };
                _repo.Add(cmt);
                return(Json(new { result = true, JsonRequestBehavior.AllowGet }));
            }
        }
Пример #28
0
        public ActionResult GetPeople()
        {
            var userID = SessionSet <User> .Get("Login").ID;

            var         allUser   = _br.Query <User>().Where(k => k.ID != userID).ToList();
            List <User> otherUser = new List <User>();

            foreach (var item in allUser)
            {
                var result = _br.Query <RelationShip>().Where(k => (k.User1ID == userID && k.User2ID == item.ID) || (k.User1ID == item.ID && k.User2ID == userID)).Any();
                if (!result)
                {
                    otherUser.Add(item);
                }
            }
            return(View(otherUser));
        }
Пример #29
0
        public ActionResult FollowerList()
        {
            var _user = SessionSet <User> .Get("login");

            int myId = _user.Id;

            var friends = db.Database.SqlQuery <string>(
                "SELECT UserName FROM Users where Id IN(SELECT UserId FROM UserFriends where FriendId =" + myId + ")").ToList();
            List <User> list = new List <User>();

            foreach (string item in friends)
            {
                var model = db.Users.FirstOrDefault(x => x.UserName == item);
                list.Add(model);
            }
            return(View(list));
        }
Пример #30
0
        public ActionResult AddLike(int tweetId)
        {
            using (BaseRepository <Like> _repo = new BaseRepository <Like>())
            {
                var _user = SessionSet <User> .Get("login");

                var  twId = _repo.Query <Tweet>().FirstOrDefault(x => x.Id == tweetId);
                Like like = new Like
                {
                    Body   = twId.Body,
                    UserId = _user.Id,

                    ParentId = tweetId
                };
                _repo.Add(like);
                return(Json(new { result = true, JsonRequestBehavior.AllowGet }));
            }
        }