예제 #1
0
        public async Task <ActionResult> PullTweets([FromBody] PullTweetViewModel model)
        {
            if (ModelState.IsValid)
            {
                var userId = User.Claims.First(x => x.Type == "UserID").Value;
                var user   = await _userRepo.GetUserById(userId);

                APIDetails details = _contextRepo.GetAPIDetails(user);
                var        tweet   = _helper.GetTweets(model, details);
                if (tweet.Any())
                {
                    string filename  = model.Title;
                    bool   fileExist = _contextRepo.FileNameExist(model.Title);
                    if (fileExist)
                    {
                        filename = model.Title + "_" + Guid.NewGuid();
                    }
                    _helper.CreateCsv(tweet, filename);
                    var pullDetails = new PullDetails()
                    {
                        User     = user,
                        Title    = model.Title,
                        Keyword  = model.Keyword,
                        FileName = filename,
                        Quantity = model.Quantity,
                        Date     = DateTime.UtcNow
                    };
                    _contextRepo.Create(pullDetails);

                    return(Ok());
                }
                return(Ok("tweet is null"));
            }
            return(BadRequest());
        }