Пример #1
0
        public async Task <IActionResult> Index(TwitterAccountViewModel model)
        {
            var timelineViewModel = new TimelineViewModel();
            var userTimeline      = await twitterService.GetUsersTimeline(model.Id);

            Guard.WhenArgument(userTimeline, "User Timeline").IsNull().Throw();

            var twitterAccountTimeline = this.mappingProvider.ProjectTo <TweetApiDto, TweetViewModel>(userTimeline).ToList();
            var userId           = this.userManager.GetUserId(this.HttpContext.User);
            var downloadedTweets = await this.userService.GetAllDownloadTweetsByUser(userId);

            foreach (var tweet in downloadedTweets)
            {
                for (int i = 0; i < twitterAccountTimeline.Count(); i++)
                {
                    if (tweet.Id == twitterAccountTimeline[i].Id)
                    {
                        twitterAccountTimeline[i].IsDownloaded = true;
                    }
                }
            }

            timelineViewModel.Tweets = twitterAccountTimeline;
            timelineViewModel.TwiitterAccountInfo = model;

            return(View(timelineViewModel));
        }
Пример #2
0
        public async Task <IActionResult> DeleteTwitterAccountFromFavorites(TwitterAccountViewModel model)
        {
            var userId = this.userManager.GetUserId(this.HttpContext.User);

            await this.twitterAccountService.DeleteTwitterAccountFromUser(userId, model.Id);

            return(this.RedirectToAction("Index", "Home"));
        }
Пример #3
0
        public async Task <IActionResult> UnfollowTwitterAccount([FromBody] TwitterAccountViewModel model)
        {
            var userId = this.userManager.GetUserId(this.HttpContext.User);

            await this.twitterAccountService.DeleteTwitterAccountFromUser(userId, model.Id);

            return(Json($"{model.Name} successfully unfollowed!"));
        }
Пример #4
0
        public async Task <IActionResult> AddTwitterAccountToFavorites([FromBody] TwitterAccountViewModel model)
        {
            var userId = this.userManager.GetUserId(this.HttpContext.User);

            if (model.BackgroundImage == null)
            {
                model.BackgroundImage = "https://www.smartt.com/sites/default/files/public/twitter_logo_banner_12.jpg";
            }

            var twitterAccountToaAdd = this.mappingProvider.MapTo <TwitterAccountApiDto>(model);

            await this.twitterAccountService.AddTwitterAccountToUser(twitterAccountToaAdd, userId);

            return(Json($"You just followed {model.Name}!"));
        }