public JokeBindingModel GetTestJokeBM(JokeCategory category) { var jokeBM = new JokeBindingModel() { Content = "This is a valid joke with minimum 10 characters... ups *20 characters", Category = category }; return(jokeBM); }
private async Task GetSimpleJokeAndMakePun(IDialogContext context, JokeCategory category) { var jokeSearch = jokeSearcher.GetJokeByCategory(category); await SendTypingMessageAndWaitOperation(context, jokeSearch); jokeFinded = jokeSearch.Result; await MakeJoke(context); }
public JokeCategory EnsureCategory(string name) { var category = this.categories.All().FirstOrDefault(x => x.Name == name); if (category != null) { return category; } category = new JokeCategory { Name = name }; this.categories.Add(category); this.categories.Save(); return category; }
public Joke Create(JokeCreateModel model, JokeCategory category) { var joke = new Joke { Category = category, CreatedById = model.CreatedById, Content = model.Content, }; this.jokes.Add(joke); this.jokes.Save(); return(joke); }
public JokeCategory EnsureCategory(string name) { var category = this.categories.All().FirstOrDefault(x => x.Name == name); if (category != null) { return(category); } category = new JokeCategory { Name = name }; this.categories.Add(category); this.categories.Save(); return(category); }
public async Task <Joke> FindRandomJokeByCategory(JokeCategory jokeCategory) { if (!JokeListExists()) { await LoadJokeListAsync(); } var findedJokes = _jokes.Where(j => j.Category.Equals(jokeCategory)) .ToList(); if (findedJokes.Any()) { return(findedJokes.ElementAt(RandomElementPosition(findedJokes.Count()))); } return(new Joke()); }
static void Main() { // TODO: Add DI container an AutoMapper var db = new ApplicationDbContext(); var dbRopository = new DbRepository <JokeCategory>(db); var categoryesService = new CategoriesService(dbRopository); // AngleSharp configurations IConfiguration configuration = Configuration.Default.WithDefaultLoader(); IBrowsingContext browsingContex = BrowsingContext.New(configuration); long countOfAddedJokes = 0; for (int i = 1; i < 65000; i++) { string url = $"http://vicove.com/vic-{i}"; IDocument document = browsingContex.OpenAsync(url).Result; string jokeContent = document.QuerySelector("#content_box .post-content p").TextContent.Trim(); string categoryName = document.QuerySelector("#content_box .thecategory a").TextContent.Trim(); bool isValidJoke = !string.IsNullOrWhiteSpace(jokeContent); bool isValidCategory = !string.IsNullOrWhiteSpace(categoryName); if (isValidJoke && isValidCategory) { countOfAddedJokes++; JokeCategory category = categoryesService.EnsureCategory(categoryName); Joke joke = new Joke { Content = jokeContent, Category = category }; db.Jokes.Add(joke); db.SaveChanges(); if (countOfAddedJokes % 100 == 0) { Console.WriteLine($"Added {countOfAddedJokes} jokes"); } } } Console.WriteLine(); Console.WriteLine($"--- DONE => {countOfAddedJokes} joke added"); }
public JokeCategory EnsureCategory(string name) { if (string.IsNullOrEmpty(name) || name.Length < 4) { throw new ArgumentException("Category could not pass validation"); } var category = this.categories.All().FirstOrDefault(x => x.Name == name); if (category != null) { return(category); } category = new JokeCategory { Name = name }; this.categories.Add(category); this.categories.Save(); return(category); }
public async Task <Joke> FindByCategoryAsync(JokeCategory jokeCategory) => await _jokeAdministrator.FindRandomJokeByCategory(jokeCategory);
public GifLinks(string link, string category = "") { linkUrl = link; jokeCategory = !string.IsNullOrEmpty(category) ? category.ToEnumWWithThisDescription <JokeCategory>() : JokeCategory.Undefined; }
public async Task <Joke> GetJokeByCategory(JokeCategory category) => await GetJoke($"{ApiUrl}?category={category.ToString()}");