public async Task <IActionResult> Post([FromBody] TwitterProfileApi profile) { _logger.Log("Adding profile to list"); if (profile == null) { _logger.Error("No profile recieved"); _logger.Separator(); return(BadRequest("Sum ting wong")); } if (profile.Name == null) { _logger.Error("No profilename"); _logger.Separator(); return(BadRequest("Name not given")); } if (await _twitterService.DoesTwitterUserExist(profile) == false) { _logger.Error("Profile doesn't match a twitter profile"); _logger.Separator(); return(NotFound("Twitter user does not exist")); } if (_twitterService.ProfileTimeLineHasTweets(profile) == false) { _logger.Error("Profile doesn't have any tweets"); _logger.Separator(); return(BadRequest("Twitter user does not have any tweets.")); } TwitterProfile prolife = null; try { profile.Name = await _twitterService.GetTwitterUserName(profile); prolife = _repository.Add(profile); _logger.Log($"Profile {profile.Name} added to database"); } catch (Exception e) { if (prolife != null) { _repository.Remove(prolife); } _logger.Error("Something went wrong adding to db"); _logger.Error(e.Message); _logger.Separator(); return(BadRequest()); } _logger.Separator(); return(Ok(prolife)); }
public async Task <IActionResult> CheckTwitterHandle([FromBody] TwitterProfileApi handle) { if (handle == null) { return(BadRequest("No handle given")); } if (string.IsNullOrWhiteSpace(handle.Name)) { return(BadRequest("Handle is empty")); } var result = (await _twitterService.DoesTwitterUserExist(handle)); if (result) { return(Ok("Twitterhandle found")); } else { return(NotFound($"Twitterhandle not found")); } }