Example #1
0
        /// <inheritdoc />
        protected override async Task EditRelations(Episode resource, Episode changed, bool resetOld)
        {
            await Validate(changed);

            if (changed.Tracks != null || resetOld)
            {
                await _tracks.DeleteAll(x => x.EpisodeID == resource.ID);

                resource.Tracks = changed.Tracks;
                await _ValidateTracks(resource);
            }

            if (changed.ExternalIDs != null || resetOld)
            {
                await Database.Entry(resource).Collection(x => x.ExternalIDs).LoadAsync();

                resource.ExternalIDs = changed.ExternalIDs;
            }
        }
Example #2
0
        public async Task <bool> Seed()
        {
            var rng          = new Random();
            var listaGeneros = new List <string> ()
            {
                "pop", "mpb", "classical", "rock"
            };

            _ = await _trackRepository.DeleteAll();

            foreach (var genero in listaGeneros)
            {
                var recommendations = GetRecommendations(null, new List <string> ()
                {
                    genero
                }, null, null, null, null, 50, string.Empty);
                foreach (var item in recommendations.Tracks)
                {
                    var name       = item.Name;
                    var artistName = item.Artists.First().Name;
                    var genre      = await _genreRepository.GetByNameAsync(genero);

                    var oTrack = new Track()
                    {
                        Name         = item.Name,
                        NameOfArtist = item.Artists.First().Name,
                        IdGenre      = genre.Id,
                        Price        = rng.Next(1, 60)
                    };

                    try {
                        _ = _trackRepository.Create(oTrack);
                    } catch (System.Exception) {
                        continue;
                    }
                }
            }

            return(true);
        }