Ejemplo n.º 1
0
        public List <ArtistGenreDownloadModel> Convert(List <string> genres, ResolutionContext resolutionContext)
        {
            var mappedGenres = new List <ArtistGenreDownloadModel>();

            foreach (var genre in genres)
            {
                var formattedGenre = GenreFormattingHelper.CreateNewGenre(genre, genre.Replace(" ", ""));

                mappedGenres.Add(new ArtistGenreDownloadModel
                {
                    Name = formattedGenre.Name,
                    Code = formattedGenre.Code
                });
            }

            return(mappedGenres);
        }
Ejemplo n.º 2
0
        private static async Task <List <ArtistGenre> > CreateArtistGenres(
            FullArtist fullArtist,
            IRepositoryManager repositoryManager)
        {
            List <ArtistGenre> artistGenres   = new List <ArtistGenre>();
            HashSet <string>   strippedGenres = fullArtist.Genres.Select(g => g.Replace(" ", "")).ToHashSet();
            var existingGenres = await repositoryManager.GenreRepository.GetManyByCodeAsync(strippedGenres);

            var existingGenreCodes = existingGenres.Select(g => g.Code).ToHashSet();

            foreach (var genre in fullArtist.Genres)
            {
                var strippedGenre = genre.Replace(" ", "");

                var existingGenre = existingGenreCodes.Contains(strippedGenre) ?
                                    existingGenres.Where(g => g.Code == strippedGenre).FirstOrDefault() : null;

                if (existingGenre != null)
                {
                    artistGenres.Add(new ArtistGenre
                    {
                        GenreId = existingGenre.Id
                    });
                }
                else
                {
                    var newGenre = GenreFormattingHelper.CreateNewGenre(genre, strippedGenre);

                    artistGenres.Add(new ArtistGenre
                    {
                        Genre = newGenre
                    });
                }
            }

            return(artistGenres);
        }