Esempio n. 1
0
        // POST: {username}/Users/Follow
        public ActionResult Follow(string followUserId)
        {
            var currentUserId = this.User.Identity.GetUserId();
            var currentUser = this.Data.Users.GetAll().FirstOrDefault(u => u.Id == currentUserId);
            var followUser = this.Data.Users.GetAll().FirstOrDefault(u => u.Id == followUserId);

            if (currentUser == null || followUser == null)
            {
                return this.RedirectToAction("Following");
            }

            followUser.Following.Add(currentUser);

            var notification = new Notification()
                {
                    Content = string.Format("You have been followed by {0}", currentUser.UserName),
                    Date = DateTime.Now,
                    ReceiverId = followUserId,
                    NotificationType = NotificationType.NewFollower
                };

            this.Data.Notifications.Add(notification);
            this.Data.SaveChanges();

            TwitterHub hub = new TwitterHub();

            hub.Notification(followUserId);

            return this.RedirectToAction("Following");
        }
        public ActionResult ReTweet(int tweetId)
        {
            var userId = this.User.Identity.GetUserId();
            var user = this.Data.Users.GetAll().FirstOrDefault(u => u.Id == userId);
            var tweet = this.Data.Tweets.GetAll().FirstOrDefault(t => t.Id == tweetId);

            if (user == null && tweet == null)
            {
                return this.HttpNotFound();
            }

            tweet.RetweetedBy.Add(user);

            var notification = new Notification()
                {
                    Content = string.Format("Your tweet was retweeted by {0}", user.UserName),
                    Date = DateTime.Now,
                    ReceiverId = tweet.AuthorId,
                    NotificationType = NotificationType.Retweet
                };

            this.Data.Notifications.Add(notification);
            this.Data.SaveChanges();

            TwitterHub hub = new TwitterHub();

            hub.Notification(tweet.Author.Id);

            return this.Redirect("/" + user.UserName);
        }