コード例 #1
0
        public ActionResult Tweet(CreateTweetBindingModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return Json(this.ModelState);
            }

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

            var tweet = new Tweet()
            {
                Content = model.Content,
                UserId = user.Id,
                TweetDate = DateTime.Now
            };

            this.Data.Tweets.Add(tweet);

            this.Data.SaveChanges();

            TwitterHub hub = new TwitterHub();

            //hub.InformFollowers(user.Followers.Select(u => u.Id).ToList(), tweet.Id);

            return RedirectToAction("Index", "Home");
        }
コード例 #2
0
        public ActionResult Tweet(CreateTweetBindingModel 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 user = this.Data.Users.Find(this.User.Identity.GetUserId());

            var tweet = new Tweet()
            {
                Content = model.Content,
                UserId = user.Id,
                TweetDate = DateTime.Now
            };

            this.Data.Tweets.Add(tweet);

            this.Data.SaveChanges();

            TwitterHub hub = new TwitterHub();

            hub.InformFollowers(user.Followers.Select(u => u.UserName).ToList(), tweet.Id);

            return PartialView("_FullTweetPartial", Mapper.Map<TweetViewModel>(tweet));
        }