コード例 #1
0
        // GET: Tweets
        public async Task <IActionResult> Index()
        {
            var model = new TweetHomePageViewModel();

            var userId = PrincipalExtensions.FindFirstValue(this.User, ClaimTypes.NameIdentifier);

            var tweets = await Queryable.Where <Tweet>(_context.Tweet, t => t.UserId == userId)
                         .AsNoTracking()
                         .ToListAsync();

            var twitterUser = _context.TwitterUsers
                              .SingleOrDefault(t => t.UserID == userId);

            if (twitterUser == null)
            {
                return(RedirectToAction("Join", new { id = userId }));
            }

            model.User           = twitterUser;
            model.User.UserImage = "https://graph.facebook.com/" + _userManager.FindByIdAsync(userId).Result.FbProfile + "/?fields=picture&type=large";
            model.User.UserName  = _userManager.FindByIdAsync(twitterUser.UserID).Result.UserName;


            foreach (var tweet in tweets)
            {
                tweet.UserImage = "https://graph.facebook.com/" + _userManager.FindByIdAsync(userId).Result.FbProfile + "/?fields=picture&type=large";
                tweet.UserName  = _userManager.FindByIdAsync(tweet.UserId).Result.UserName;
            }
            model.Tweets = tweets;

            return(View(model));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,Body")] Tweet tweet)
        {
            var userId = PrincipalExtensions.FindFirstValue(this.User, ClaimTypes.NameIdentifier);

            tweet.UserId      = userId;
            tweet.TweetUserID = _context.TwitterUsers.SingleOrDefault(u => u.UserID == userId).ID;
            tweet.DateTime    = DateTime.Now;


            if (ModelState.IsValid)
            {
                _context.Add(tweet);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(tweet));
        }