public Joke GetRandomJoke() { var joke = JokesApi.GetJoke(); var jokeRepo = new JokesRepository(_connectionString); if (!jokeRepo.JokeExists(joke.OriginId)) { jokeRepo.AddJoke(joke); } return(jokeRepo.GetByOriginId(joke.OriginId)); }
public IActionResult Index() { var joke = JokesApi.GetJoke(); var jokeRepo = new JokesRepository(_connectionString); if (!jokeRepo.JokeExists(joke.OriginId)) { jokeRepo.AddJoke(joke); } else { joke = jokeRepo.GetByOriginId(joke.OriginId); } var viewModel = new IndexViewModel { Joke = joke }; viewModel.InteractionStatus = GetStatus(joke.Id); return(View(viewModel)); }