private async Task UpdateAnimeAsync(Anime animeToUpdate, MalAnimeUpdateData malAnimeUpdateData) { animeToUpdate.Title = malAnimeUpdateData.Title; animeToUpdate.About = malAnimeUpdateData.About; animeToUpdate.EnglishTitle = malAnimeUpdateData.EnglishTitle; animeToUpdate.KanjiTitle = malAnimeUpdateData.JapaneseTitle; animeToUpdate.Popularity = malAnimeUpdateData.Popularity; animeToUpdate.ImageUrl = malAnimeUpdateData.ImageUrl; animeToUpdate.AiringDate = malAnimeUpdateData.AiringDate ?? animeToUpdate.AiringDate; animeToUpdate.TitleSynonyms = !string.IsNullOrWhiteSpace(malAnimeUpdateData.TitleSynonyms) ? malAnimeUpdateData.TitleSynonyms : animeToUpdate.TitleSynonyms; animeToUpdate.StatusId = JikanParserHelper.GetUpdatedAnimeStatus(animeToUpdate.StatusId, malAnimeUpdateData.Status); animeToUpdate.TypeId = JikanParserHelper.GetUpdatedAnimeType(animeToUpdate.TypeId, malAnimeUpdateData.Type); animeToUpdate.SeasonId = string.IsNullOrEmpty(malAnimeUpdateData.Season) ? await MatchSeasonByDateAsync(malAnimeUpdateData.AiringDate) : await MatchSeasonBySeasonAsync(malAnimeUpdateData.Season); }
private async Task <Anime> InsertAnimeAsync(long malId) { var existingAnime = await _animeRepository.GetAsync(malId); if (existingAnime != null) { return(existingAnime); } var parsedData = await _malApiService.GetAnimeDataAsync(malId); if (parsedData is null) { return(null); } var newAnime = new Anime { Id = Guid.NewGuid(), MalId = malId, Title = parsedData.Title, ImageUrl = parsedData.ImageUrl, About = parsedData.About, AiringDate = parsedData.AiringDate ?? DateTime.MinValue, EnglishTitle = parsedData.EnglishTitle, KanjiTitle = parsedData.JapaneseTitle, Popularity = parsedData.Popularity, TitleSynonyms = !string.IsNullOrWhiteSpace(parsedData.TitleSynonyms) ? parsedData.TitleSynonyms : string.Empty, StatusId = JikanParserHelper.GetUpdatedAnimeStatus(null, parsedData.Status), TypeId = JikanParserHelper.GetUpdatedAnimeType(null, parsedData.Type), SeasonId = string.IsNullOrEmpty(parsedData.Season) ? await MatchSeasonByDateAsync(parsedData.AiringDate) : await MatchSeasonBySeasonAsync(parsedData.Season) }; await _animeRepository.AddAsync(newAnime); Console.WriteLine($"Inserted anime with malId {malId} ({parsedData.Title})"); return(newAnime); }