예제 #1
0
        private async Task InsertRole(long seiyuuMalId, VoiceActingRole voiceActingRole, IReadOnlyList <Role> seiyuuRoles)
        {
            try
            {
                if (!seiyuuRoles.Any(x => x.AnimeId.Equals(voiceActingRole.Anime.MalId) && x.CharacterId.Equals(voiceActingRole.Character.MalId)))
                {
                    bool isCharacterInDatabase = true;
                    bool isAnimeInDatabase     = true;

                    if (await animeRepository.GetAsync(voiceActingRole.Anime.MalId) == null)
                    {
                        isAnimeInDatabase = await InsertAnime(voiceActingRole);
                    }
                    if (await characterRepository.GetAsync(voiceActingRole.Character.MalId) == null)
                    {
                        isCharacterInDatabase = await InsertCharacter(voiceActingRole);
                    }

                    if (isAnimeInDatabase && isCharacterInDatabase)
                    {
                        roleRepository.Add(new Role()
                        {
                            LanguageId  = 1,                            // Always japanese for now
                            RoleTypeId  = voiceActingRole.Role.Equals("Main") ? 1 : 2,
                            AnimeId     = voiceActingRole.Anime.MalId,
                            CharacterId = voiceActingRole.Character.MalId,
                            SeiyuuId    = seiyuuMalId
                        });
                        await roleRepository.CommitAsync();

                        logger.Log($"Inserted {voiceActingRole.Character.Name} in {voiceActingRole.Anime.Name}");
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Log($"Error during inserting with anime {voiceActingRole.Anime.Name}, character {voiceActingRole.Character.Name}: {ex.Message}");
            }
        }
예제 #2
0
        public async Task HandleAsync(UpdateAnimeMessage updateAnimeMessage)
        {
            var animeToUpdate = await _animeRepository.GetAsync(updateAnimeMessage.MalId);

            if (animeToUpdate == null)
            {
                return;
            }

            var updateData = await _malApiService.GetAnimeDataAsync(updateAnimeMessage.MalId);

            if (updateData == null)
            {
                return;
            }

            await UpdateAnimeAsync(animeToUpdate, updateData);

            await _animeRepository.UpdateAsync(animeToUpdate);
        }
예제 #3
0
        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);
        }
예제 #4
0
        public async Task <AnimeCardDto> GetSingleAsync(long id)
        {
            var entity = await animeRepository.GetAsync(x => x.MalId.Equals(id), animeRepository.IncludeExpression);

            return(mapper.Map <AnimeCardDto>(entity));
        }
        public async Task <AnimeCardDto> HandleAsync(GetAnimeCardInfoQuery query)
        {
            var entity = await _animeRepository.GetAsync(query.MalId);

            return(entity.ToAnimeCardDto());
        }