Beispiel #1
0
        public ActionResult Retweet(ReTweetBindingModel model)
        {
            if (model == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Missing data"));
            }

            if (!this.ModelState.IsValid)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, JsonConvert.SerializeObject(this.ModelState)));
            }

            var tweet = this.Data.Tweets.Find(model.TweetId);

            if (tweet == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Tweet not found."));
            }

            var user = this.Data.Users.Find(this.User.Identity.GetUserId());

            if (tweet.UserId == user.Id)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "You can't retweet your own tweets."));
            }

            if (user.Tweets.Any(t => t.ReplyToId == tweet.Id))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Retweeting retweet is not possible at the time."));
            }

            this.Data.Tweets.Add(new Tweet()
            {
                Content          = model.Content,
                UserId           = user.Id,
                TweetDate        = DateTime.Now,
                RetweetedTweetId = tweet.Id
            });

            tweet.User.Notifications.Add(new Notification()
            {
                Content     = "retweeted one of your tweets",
                CreatorId   = user.Id,
                RecipientId = tweet.UserId,
                Date        = DateTime.Now,
                Type        = NotificationType.Retweet
            });

            this.Data.SaveChanges();

            TwitterHub hub = new TwitterHub();

            hub.NotificationInform(new List <string>()
            {
                tweet.User.UserName
            });

            return(RedirectToAction("Index", "Home"));
        }
Beispiel #2
0
        public ActionResult ReTweet(int id)
        {
            var bindingModel = new ReTweetBindingModel {
                TweetId = id
            };

            return(this.View("_ReTweetPartial", bindingModel));
        }
Beispiel #3
0
 public ActionResult ReTweet(ReTweetBindingModel model)
 {
     if (model != null && this.ModelState.IsValid)
     {
         var tweet = this.TwitterData.Tweets.Find(model.TweetId);
         tweet.Retweets.Add(new Tweet {
             Content = model.Content, TweetedAt = DateTime.Now
         });
         this.TwitterData.SaveChanges();
         this.TempData[GlobalConstants.TempMessageKey] = "You have successfully retweeted!";
         return(this.RedirectToAction("Home", "Users"));
     }
     this.TempData[GlobalConstants.TempMessageKey] = "Error during retweet";
     return(this.View("_ReTweetPartial", model));
 }
        public ActionResult Retweet(ReTweetBindingModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return Json(this.ModelState);
            }

            var tweet = this.Data.Tweets.Find(model.TweetId);

            if (tweet == null)
            {
                return this.Json("Not found");
            }

            var user = this.Data.Users.Find(this.User.Identity.GetUserId());

            if (tweet.UserId == user.Id)
            {
                throw new Exception("You can't retweet your own tweets");
            }

            if (user.Tweets.Any(t => t.ReplyToId == tweet.Id))
            {
                throw new Exception("You cannot retweet again");
            }

            this.Data.Tweets.Add(new Tweet()
            {
                Content = model.Content,
                UserId = user.Id,
                TweetDate = DateTime.Now,
                RetweetedTweetId = tweet.Id
            });

            tweet.User.Notifications.Add(new Notification()
            {
                Content = "Retweet",
                CreatorId = user.Id,
                RecipientId = tweet.UserId,
                Date = DateTime.Now,
                Type = NotificationType.Retweet
            });

            this.Data.SaveChanges();

            TwitterHub hub = new TwitterHub();

            hub.NotificationInform(new List<string>() { tweet.User.UserName });

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