public List <Joke> GetJokes() { var repo = new JokeRepository(_connection); var jokes = JokesApi.GetJokes(); repo.AddJokes(jokes); return(jokes); }
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)); }
private async Task <DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { if (!_luisRecognizer.IsConfigured) { // LUIS is not configured, we just run the BookingDialog path with an empty BookingDetailsInstance. return(await stepContext.BeginDialogAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text("Luis not Configured") }, cancellationToken)); } var Intent = await LuisApi.SendUserInputToLuis(stepContext.Result.ToString()); switch (Intent) { case "Hello": var HelloMessageText = "Hello there"; var getHelloMessage = MessageFactory.Text(HelloMessageText, HelloMessageText, InputHints.IgnoringInput); await stepContext.Context.SendActivityAsync(getHelloMessage, cancellationToken); break; case "Goodbye": // We haven't implemented the GetWeatherDialog so we just display a TODO message. var ByeMessageText = "Goodbye there"; var getByeMessage = MessageFactory.Text(ByeMessageText, ByeMessageText, InputHints.IgnoringInput); await stepContext.Context.SendActivityAsync(getByeMessage, cancellationToken); break; case "Jokes": var joke = await JokesApi.GetJoke(); var JokeMessageText = "Mmmm well..." + System.Environment.NewLine + joke; var getJokeMessage = MessageFactory.Text(JokeMessageText, JokeMessageText, InputHints.IgnoringInput); await stepContext.Context.SendActivityAsync(getJokeMessage, cancellationToken); break; case "UserLaughs": Random rnd = new Random(); int rndv = rnd.Next(1, 3); if (rndv == 1) { var userLaughText = "Yes, this was funny, I liked it too... 🤣🤣🤣🤣"; var getuserLaughMessage = MessageFactory.Text(userLaughText, userLaughText, InputHints.IgnoringInput); await stepContext.Context.SendActivityAsync(getuserLaughMessage, cancellationToken); break; } else { var userLaughText = "🤣🤣🤣🤣"; var getuserLaughMessage = MessageFactory.Text(userLaughText, userLaughText, InputHints.IgnoringInput); await stepContext.Context.SendActivityAsync(getuserLaughMessage, cancellationToken); break; } case "Recipes": return(await stepContext.BeginDialogAsync(nameof(RecipeDialog), null, cancellationToken)); case "weather": return(await stepContext.BeginDialogAsync(nameof(WeatherDialog), null, cancellationToken)); default: // Catch all for unhandled intents var didntUnderstandMessageText = $"Sorry, I didn't get that. Please try asking in a different way"; var didntUnderstandMessage = MessageFactory.Text(didntUnderstandMessageText, didntUnderstandMessageText, InputHints.IgnoringInput); await stepContext.Context.SendActivityAsync(didntUnderstandMessage, cancellationToken); break; } return(await stepContext.NextAsync(null, cancellationToken)); }
public IActionResult GetJoke() { var api = new JokesApi(); return(Json(api.GetRandomJoke().First())); }