Exemple #1
0
        public void CalcularHash()
        {
            var stringHash = $"{UserId}";

            if (Albums != null && Albums.Any())
            {
                foreach (var album in Albums.OrderBy(x => x.AlbumId))
                {
                    stringHash += $"{album.AlbumId}{album.AlbumTitle}";

                    if (album.Photos != null && album.Photos.Any())
                    {
                        var fotosHash = album.Photos.OrderBy(x => x.PhotoId).Select(x => $"{x.PhotoId}{x.Title}{x.Url}{x.ThumbnailUrl}");
                        stringHash += string.Join(string.Empty, fotosHash);
                    }
                }
            }

            var bytes = Encoding.UTF8.GetBytes(stringHash);

            using var crypto = new SHA256CryptoServiceProvider();
            var hash        = crypto.ComputeHash(bytes);
            var bytesString = hash.Select(x => x.ToString("x2"));

            Hash = string.Join(string.Empty, bytesString);
        }
        private void BuildLibraryTree()
        {
            try
            {
                buildLocalMusicAlbumArtistModels();
                buildLocalPlaylistModels();
                buildLocalThumbnailModels();

                foreach (var album in Albums)
                {
                    album.LibraryViewModel = this;
                }

                foreach (var playlist in Playlists)
                {
                    playlist.LibraryViewModel = this;
                }

                Albums = new ObservableCollection <LocalAlbumModel>(Albums.OrderBy(a => a.Title).ToList());

                RaisePropertyChanged(nameof(hasPlaylistReverse));
                RaisePropertyChanged(nameof(hasPlaylist));
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }
        }
        public void SortAlbums(string selected)
        {
            switch (selected)
            {
            case "A-Z":
                Albums = new ObservableCollection <LocalAlbumModel>(Albums.OrderBy(a => a.Title).ToList());
                break;

            case "Z-A":
                Albums = new ObservableCollection <LocalAlbumModel>(Albums.OrderByDescending(a => a.Title).ToList());
                break;

            case "Artist":
                Albums = new ObservableCollection <LocalAlbumModel>(Albums.OrderBy(a => a.AlbumArtist).ToList());
                break;
            }
        }
        public void DoAddNew()
        {
            int nextId = Albums.OrderBy(a => a.ID).Last().ID + 1;
            // TODO: if using repo:
            // JsonRepository<Album> repo = new JsonRepository<Album>();
            // int nextId2 = repo.GetNextId();

            Album newAlbum = new Album(nextId)
            {
                Title = "(new)"
            };

            Albums.Add(newAlbum);
            SelectedAlbum = newAlbum;
            _isNew        = true;
            IsEditMode    = true;
            RefreshActionGuards();
        }
Exemple #5
0
        //============================================
        #region DataLogic
        #region audio
        public SmartCollection <AlbumItem> OrderAlbums(OrderType orderType, OrderListing orderListing)
        {
            if (Albums == null)
            {
                return(null);
            }

            if (orderType == OrderType.ByArtist)
            {
                if (orderListing == OrderListing.Ascending)
                {
                    return(Albums.OrderBy(x => x.Artist).ToObservable());
                }
                else if (orderListing == OrderListing.Descending)
                {
                    return(Albums.OrderByDescending(x => x.Artist).ToObservable());
                }
            }
            else if (orderType == OrderType.ByDate)
            {
                if (orderListing == OrderListing.Ascending)
                {
                    return(Albums.OrderBy(x => x.Year).ToObservable());
                }
                else if (orderListing == OrderListing.Descending)
                {
                    return(Albums.OrderByDescending(x => x.Year).ToObservable());
                }
            }
            else if (orderType == OrderType.ByAlbum)
            {
                if (orderListing == OrderListing.Ascending)
                {
                    return(Albums.OrderBy(x => x.Name).ToObservable());
                }
                else if (orderListing == OrderListing.Descending)
                {
                    return(Albums.OrderByDescending(x => x.Name).ToObservable());
                }
            }

            return(null);
        }
Exemple #6
0
 /// <summary>
 /// Changes Album ListView sort order.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void AlbumsSortByDate(object sender, ref string lastAlbumsHeaderClicked, ref ListSortDirection lastAlbumsDirection)
 {
     if (_lastAlbumSortOrder == AlbumSortOrder.ByDate)
     {
         SortListView(sender, ref lastAlbumsHeaderClicked, ref lastAlbumsDirection, "Title");
         _lastAlbumSortOrder = AlbumSortOrder.ByTitleAsc;
         Albums = Albums.OrderBy(i => i.Title).ToList();
     }
     else if (_lastAlbumSortOrder == AlbumSortOrder.ByTitleAsc)
     {
         SortListView(sender, ref lastAlbumsHeaderClicked, ref lastAlbumsDirection, "Title");
         _lastAlbumSortOrder = AlbumSortOrder.ByTitleDesc;
         Albums = Albums.OrderByDescending(i => i.Title).ToList();
     }
     else
     {
         SortListView(sender, ref lastAlbumsHeaderClicked, ref lastAlbumsDirection, "Date");
         _lastAlbumSortOrder = AlbumSortOrder.ByDate;
         Albums = Albums.OrderBy(i => i.Date).ToList();
     }
     OnPropertyChanged("LastAlbumSortOrderText");
 }
Exemple #7
0
        private void RefreshAlbums()
        {
            foreach (Song song in Songs)
            {
                Album existingAlbum = Albums.Where(x => x.Title == song.Album).FirstOrDefault();

                if (existingAlbum == null)
                {
                    App.Current.Dispatcher.Invoke((Action) delegate // <--- HERE
                    {
                        Albums.Add(new Album()
                        {
                            Title    = song.Album,
                            Artist   = song.Artist,
                            CoverArt = DataService.GetAlbumImage(song.Path)
                        });
                    });
                }
            }

            Albums.OrderBy(s => s.Title.StartsWith("A ", StringComparison.OrdinalIgnoreCase) || s.Title.StartsWith("The ", StringComparison.OrdinalIgnoreCase) ? s.Title.Substring(s.Title.IndexOf(" ") + 1) : s.Title);
        }
Exemple #8
0
        static void Main(string[] args)
        {
            Init();// this method fills the arrays above with data

            /*
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░
             *  ░░███████░░░░░░░░░░███▒▒▒▒▒▒▒▒███░░░░░░
             *  ░░█▒▒▒▒▒▒█░░░░░░░███▒▒▒▒▒▒▒▒▒▒▒▒███░░░░
             *  ░░░█▒▒▒▒▒▒█░░░░██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░░
             *  ░░░░█▒▒▒▒▒█░░░██▒▒▒▒▄██▄▒▒▒▒▄██▄▒▒▒███░
             *  ░░░░░█▒▒▒█░░░█▒▒▒▒▒▒████▒▒▒▒████▒▒▒▒▒██
             *  ░░░█████████████▒▒▒▒▀██▀▒▒▒▒▀██▀▒▒▒▒▒██
             *  ░░░█▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒██
             *  ░██▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒██▒▒▒▒▒▒▒▒▒██▒▒▒▒██
             *  ██▒▒▒███████████▒▒▒▒▒██▒▒▒▒▒▒▒██▒▒▒▒▒██
             *  █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒███████▒▒▒▒▒▒▒██
             *  ██▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░
             *  ░█▒▒▒███████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░░░
             *  ░██▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█░░░░░
             *  ░░████████████░░░████████████████░░░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░▄█████▄░▄███████▄░▄███████▄░██████▄░░
             *  ░░██▒▒▒▒█░███▒▒▒███░███▒▒▒███░██▒▒▒██░░
             *  ░░██▒▒▒▒▒░██▒▒▒▒▒██░██▒▒▒▒▒██░██▒▒▒██░░
             *  ░░██▒▒▒▀█░███▒▒▒███░███▒▒▒███░██▒▒▒██░░
             *  ░░▀█████▀░▀███████▀░▀███████▀░██████▀░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░▄█████░██▒▒▒▒██▀░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░██▀▒▒▒░██▒▒▒██░░░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░██▒▒▒▒░█████▀░░░░░░░
             *  ░░░░██▒▒▒▒░██▄▒▄██░██▄▒▒▒░██▒▒▒██░░░░░░
             *  ░░░░▀█████░▀█████▀░▀█████░██▒▒▒▒██▄░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             */

            //1 - how many Songs start with the letter 'a' (case insensitive)
            Console.WriteLine("Songs start with the letter 'a'");
            var songsWithA = Songs
                             .Where(x => x.Name.StartsWith("a"))
                             .ToList();

            Console.WriteLine(string.Join(" ", songsWithA));
            Console.WriteLine("-----------------------------------------");

            //2 - how many artists end with letter 'a' (case insensitive)
            Console.WriteLine("Artists end with letter 'a'");
            var artistEnd = Artists
                            .Where(x => x.FullName.EndsWith("a"))
                            .ToList();

            foreach (var item in artistEnd)
            {
                Console.WriteLine(item.FullName);
            }
            Console.WriteLine("-----------------------------------------");

            //3 - whats the name of the song with longest duration
            Console.WriteLine("Longest Song by Duration:");
            var longestSong = Songs
                              .OrderByDescending(x => x.Duration)
                              .First();

            Console.WriteLine(longestSong.Name);
            Console.WriteLine("-----------------------------------------");

            //4 - whats the total Duration of all Songs
            Console.WriteLine("Total Duration of all Songs:");
            var totalDuration = Songs
                                .Sum(x => x.Duration);

            Console.WriteLine($"{totalDuration} seconds");
            Console.WriteLine("-----------------------------------------");

            //5 - how many albums have Songs longer than 300 seconds
            Console.WriteLine("Albums with Songs longer than 300 seconds");
            var albums300 = Albums
                            .Where(x => x.Songs.Any(y => y.Duration > 300));

            foreach (var item in albums300)
            {
                Console.WriteLine(item.Name);
            }
            Console.WriteLine("-----------------------------------------");

            //6 - print the names of the artists(separated with "--"), that have more than one album of PopRock genre
            Console.WriteLine("Artists with more than one album of PopRock Genre:");
            var popRock = Artists
                          .Select(x => new { NameOfArtist = x.FullName, AlbumsOfArtist = x.Albums.Where(y => y.Genre == Genre.PopRock).Count() })
                          .Where(k => k.AlbumsOfArtist > 1);

            foreach (var item in popRock)
            {
                Console.Write(item.NameOfArtist + "--");
            }
            Console.WriteLine();
            Console.WriteLine("-----------------------------------------");

            //7 - print the name of the album that has highest Average duration of a song
            Console.WriteLine("Albums with highest Average duration of a song:");
            var durationAvg = Albums
                              .Select(x => new { NameOfAlbum = x.Name, AvgDuration = x.Songs.Average(y => y.Duration) })
                              .OrderByDescending(w => w.AvgDuration)
                              .First();

            Console.WriteLine($"Name: {durationAvg.NameOfAlbum}, Highest Average duration: {durationAvg.AvgDuration}");
            Console.WriteLine("-----------------------------------------");

            //8 - how many characters has the song that has the shortest Duration
            Console.WriteLine("Characters of the shortest duration song:");
            var shortestDuration = Songs
                                   .OrderByDescending(x => x.Duration)
                                   .Reverse()
                                   .First();

            Console.WriteLine($"Name: {shortestDuration.Name}, Characters: {shortestDuration.Name.Length}, Duration: {shortestDuration.Duration}");
            Console.WriteLine("-----------------------------------------");

            //9 - print the name and the genre of the album that has most songs
            Console.WriteLine("Album with most songs:");
            var mostSongsAlbum = Albums
                                 .Select(x => new { SongCount = x.Songs.Count, NameOfAlbum = x.Name, GenreOfAlbum = x.Genre })
                                 .OrderByDescending(w => w.SongCount)
                                 .First();

            Console.WriteLine($"Name: {mostSongsAlbum.NameOfAlbum}, Song Count: {mostSongsAlbum.SongCount}, Genre: {mostSongsAlbum.GenreOfAlbum}");
            Console.WriteLine("-----------------------------------------");

            //10 - print the name of the artist that has most songs
            Console.WriteLine("Artist with most songs:");
            var artistMostSongs = Artists
                                  .Select(x => new { NameOfArtist = x.FullName, SongsOfArtist = x.Albums.Sum(y => y.Songs.Count) })
                                  .OrderByDescending(a => a.SongsOfArtist)
                                  .First();

            Console.WriteLine($"Artist: {artistMostSongs.NameOfArtist}, Songs Count: {artistMostSongs.SongsOfArtist}");
            Console.WriteLine("-----------------------------------------");

            //11 - print the type of the artist(SoloArtist/Band) that has most albums published before year 2000
            Console.WriteLine("Artist that has most albums published before year 2000:");
            var artist2000 = Artists
                             .Select(x => new { NameOfArtist = x.FullName, AlbumsCount = x.Albums.Select(y => y.Year < 2000).Count() })
                             .OrderByDescending(a => a.AlbumsCount)
                             .First();

            Console.WriteLine($"Artist: {artist2000.NameOfArtist}");
            Console.WriteLine("-----------------------------------------");

            //12 - print the average song duration, of the album that has most songs
            Console.WriteLine("Average song duration of the album that has most songs:");
            var albumAverageDuration = Albums
                                       .Select(x => new { NameOfAlbum = x.Name, MostSongs = x.Songs.Count(), AverageDuration = x.Songs.Average(d => d.Duration) })
                                       .OrderByDescending(o => o.MostSongs)
                                       .First();

            Console.WriteLine($"Album Name: {albumAverageDuration.NameOfAlbum}, Songs Count: {albumAverageDuration.MostSongs}, Average Duration: {albumAverageDuration.AverageDuration} seconds");
            Console.WriteLine("-----------------------------------------");

            // Bonus:
            //13 - print the longest song duration of the album that has least songs
            Console.WriteLine("Longest song duration of the album that has least songs:");
            var longestSongDuration = Albums
                                      .OrderBy(x => x.Songs.Count)
                                      .Select(s => new { Song = s.Songs.OrderByDescending(s1 => s1.Duration).First(), AlbumName = s.Name, AlbumSongs = s.Songs.Count() })
                                      .First();

            Console.WriteLine($"Song Name: {longestSongDuration.Song.Name}, Song Duration: {longestSongDuration.Song.Duration} seconds, Album Name: {longestSongDuration.AlbumName}, Album Songs: {longestSongDuration.AlbumSongs}");
            Console.WriteLine("-----------------------------------------");

            //14 - print the name of the album that has most songs that contain letter 'a' in the name
            Console.WriteLine("Name of the Album that has most songs that contain letter 'a' in the name:");
            var songsThatContainA = Albums
                                    .Select(x => new { AlbumName = x.Name, ContainA = x.Songs.Where(y => y.Name.Contains("a")).Count() })
                                    .OrderByDescending(x => x.ContainA)
                                    .First();

            Console.WriteLine($"Album Name: {songsThatContainA.AlbumName}, Songs count that contain 'a': {songsThatContainA.ContainA}");
            Console.WriteLine("-----------------------------------------");

            //15 - print the name of the artist that has most songs that end with letter 'd'
            Console.WriteLine("Name of the artist that has most songs that end with letter 'd':");
            var maxSongsWithD   = 0;
            var artistNameWithD = String.Empty;

            foreach (var album in Albums)
            {
                var songsWithD = album.Songs.Where(s => s.Name.EndsWith("d")).Count();
                if (songsWithD > maxSongsWithD)
                {
                    maxSongsWithD   = songsWithD;
                    artistNameWithD = Artists.Where(x => x.Id == album.ArtistId).Select(x => x.FullName).FirstOrDefault();
                }
            }
            Console.WriteLine($"{artistNameWithD} has most songs that ends with 'd'");
            Console.WriteLine("-----------------------------------------");
            Console.ReadLine();
        }
Exemple #9
0
        static void Main(string[] args)
        {
            Init();// this method fills the arrays above with data

            // - print the mass of the earth on July 1895 XD

            /*
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░
             *  ░░███████░░░░░░░░░░███▒▒▒▒▒▒▒▒███░░░░░░
             *  ░░█▒▒▒▒▒▒█░░░░░░░███▒▒▒▒▒▒▒▒▒▒▒▒███░░░░
             *  ░░░█▒▒▒▒▒▒█░░░░██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░░
             *  ░░░░█▒▒▒▒▒█░░░██▒▒▒▒▄██▄▒▒▒▒▄██▄▒▒▒███░
             *  ░░░░░█▒▒▒█░░░█▒▒▒▒▒▒████▒▒▒▒████▒▒▒▒▒██
             *  ░░░█████████████▒▒▒▒▀██▀▒▒▒▒▀██▀▒▒▒▒▒██
             *  ░░░█▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒██
             *  ░██▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒██▒▒▒▒▒▒▒▒▒██▒▒▒▒██
             *  ██▒▒▒███████████▒▒▒▒▒██▒▒▒▒▒▒▒██▒▒▒▒▒██
             *  █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒███████▒▒▒▒▒▒▒██
             *  ██▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░
             *  ░█▒▒▒███████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░░░
             *  ░██▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█░░░░░
             *  ░░████████████░░░████████████████░░░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░▄█████▄░▄███████▄░▄███████▄░██████▄░░
             *  ░░██▒▒▒▒█░███▒▒▒███░███▒▒▒███░██▒▒▒██░░
             *  ░░██▒▒▒▒▒░██▒▒▒▒▒██░██▒▒▒▒▒██░██▒▒▒██░░
             *  ░░██▒▒▒▀█░███▒▒▒███░███▒▒▒███░██▒▒▒██░░
             *  ░░▀█████▀░▀███████▀░▀███████▀░██████▀░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░▄█████░██▒▒▒▒██▀░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░██▀▒▒▒░██▒▒▒██░░░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░██▒▒▒▒░█████▀░░░░░░░
             *  ░░░░██▒▒▒▒░██▄▒▄██░██▄▒▒▒░██▒▒▒██░░░░░░
             *  ░░░░▀█████░▀█████▀░▀█████░██▒▒▒▒██▄░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             */

            // QUERIES!

            // - how many Songs start with the letter 'a' (case insensitive)
            // - how many artists end with letter 'a' (case insensitive)
            // - whats the name of the song with longest duration
            // - whats the total Duration of all Songs
            // - how many albums have Songs longer than 300 seconds
            // - print the names of the artists(separated with "--"), that have more than one album of PopRock genre
            // - print the name of the album that has highest Average duration of a song
            // - how many characters has the song that has the shortest Duration
            // - print the name and the genre of the album that has most songs
            // - print the name of the artist that has most songs
            // - print the type of the artist(SoloArtist/Band) that has most albums published before year 2000
            // - print the average song duration, of the album that has most songs

            // Bonus:
            // - print the longest song duration of the album that has least songs
            // - print the name of the album that has most songs that contain letter 'a' in the name
            // - print the name of the artist that has most songs that end with letter 'd'



            // ************ Don't mind the structure, focus on the lists declared on the beginning of Program.cs ****************

            // 3, 2, 1.... GO! :)



            // - how many Songs start with the letter 'a' (case insensitive)
            int songsStartsWithA = Songs.Select(x => x.Name.ToLower())
                                   .Where(x => x.StartsWith("a"))
                                   .ToList()
                                   .Count();

            Console.WriteLine(songsStartsWithA);

            // - how many artists end with letter 'a' (case insensitive)
            int artistEndWithA = Artists.Select(x => x.FullName.ToLower())
                                 .Where(x => x.EndsWith("a"))
                                 .ToList()
                                 .Count();

            Console.WriteLine(artistEndWithA);

            // - whats the name of the song with longest duration
            Song longestSong = Songs.FirstOrDefault(x => x.Duration == Songs
                                                    .Select(y => y.Duration)
                                                    .Max());

            Console.WriteLine(longestSong.Name);

            // - whats the total Duration of all Songs
            int totalDurationSongs = Songs.Select(x => x.Duration)
                                     .Sum();

            Console.WriteLine(totalDurationSongs);

            // - how many albums have Songs longer than 300 second
            int longerThan300 = Songs.Where(x => x.Duration > 300)
                                .GroupBy(x => x.AlbumId)
                                .ToList()
                                .Count();

            Console.WriteLine(longerThan300);

            // - print the names of the artists(separated with "--"), that have more than one album of PopRock genre

            var PopRockgenre = Artists.Where(x => x.Albums
                                             .Where(y => y.Genre == Genre.PopRock).ToList().Count() > 1)
                               .Select(v => v.FullName)
                               .ToList();

            PopRockgenre.ForEach(q => Console.Write($"{q} -- "));

            //foreach (var item in Artists)
            //{
            //    int popRockAlbums = item.Albums.Where(x => x.Genre == Genre.PopRock).ToList().Count();
            //    if (popRockAlbums > 1)
            //    {
            //        Console.Write($"{item.FullName} -- ");
            //    }
            //}

            // - print the name of the album that has highest Average duration of a song
            Album highestAverageDuration = Albums.OrderBy
                                               (x => x.Songs.Select(y => y.Duration)
                                               .Average())
                                           .ToList()
                                           .LastOrDefault();

            Console.WriteLine();
            Console.WriteLine(highestAverageDuration.Name);


            // - how many characters has the song that has the shortest Duration
            Song manyCharactersShortest = Songs
                                          .OrderByDescending(x => x.Duration)
                                          .ToList()
                                          .LastOrDefault();

            Console.WriteLine(manyCharactersShortest.Name.Count());

            // - print the name and the genre of the album that has most songs
            Album mostSongsAlbum = Albums
                                   .OrderBy(x => x.Songs.Count())
                                   .ToList()
                                   .LastOrDefault();

            Console.WriteLine($"{mostSongsAlbum.Name} {mostSongsAlbum.Genre}");

            // - print the name of the artist that has most songs
            string artistMostoSongs = Artists
                                      .OrderBy(x => x.Albums
                                               .Select(y => y.Songs)
                                               .Count()).Select(z => z.FullName).LastOrDefault();

            Console.WriteLine(artistMostoSongs);

            // - print the type of the artist(SoloArtist/Band) that has most albums published before year 2000
            Genre mostAlbumsBefore2000 = Albums
                                         .Where(x => x.Year < 2000)
                                         .Select(y => y.Genre)
                                         .Max();

            Console.WriteLine(mostAlbumsBefore2000);

            // - print the average song duration, of the album that has most songs
            double AverageSongDurationMax = Albums.Where(x => x.Songs.Count() == Albums
                                                         .Select(y => y.Songs.Count()).Max())
                                            .FirstOrDefault().Songs
                                            .Select(z => z.Duration)
                                            .Average();

            Console.WriteLine(AverageSongDurationMax);


            // Bonus:
            // - print the longest song duration of the album that has least songs
            int LongestSongDuration = Albums.Where(x => x.Songs.Count() == Albums
                                                   .Select(y => y.Songs.Count()).Min())
                                      .FirstOrDefault().Songs
                                      .Select(z => z.Duration)
                                      .Max();

            Console.WriteLine(LongestSongDuration);

            // - print the name of the album that has most songs that contain letter 'a' in the name
            string nameOfTheAlbumWithA = Albums.Where(x => x.Songs
                                                      .Where(y => y.Name.ToLower().Contains('a')).Count() == Albums
                                                      .Select(z => z.Songs
                                                              .Where(q => q.Name.ToLower().Contains('a')).Count())
                                                      .Max()).Select(u => u.Name)
                                         .FirstOrDefault();

            Console.WriteLine(nameOfTheAlbumWithA);

            // - print the name of the artist that has most songs that end with letter 'd'
            string nameOfTheArtistD = Artists.Where(x => x.Albums
                                                    .Select(y => y.Songs
                                                            .Where(z => z.Name.ToLower().EndsWith('d')).Count()).Sum() == Artists
                                                    .Select(q => q.Albums
                                                            .Select(w => w.Songs
                                                                    .Where(e => e.Name.ToLower().EndsWith('d')).Count()).Sum()).Max()).Select(r => r.FullName)
                                      .FirstOrDefault();

            Console.WriteLine(nameOfTheArtistD);


            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Init();// this method fills the arrays above with data

            // - print the mass of the earth on July 1895 XD

            /*
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░
             *  ░░███████░░░░░░░░░░███▒▒▒▒▒▒▒▒███░░░░░░
             *  ░░█▒▒▒▒▒▒█░░░░░░░███▒▒▒▒▒▒▒▒▒▒▒▒███░░░░
             *  ░░░█▒▒▒▒▒▒█░░░░██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░░
             *  ░░░░█▒▒▒▒▒█░░░██▒▒▒▒▄██▄▒▒▒▒▄██▄▒▒▒███░
             *  ░░░░░█▒▒▒█░░░█▒▒▒▒▒▒████▒▒▒▒████▒▒▒▒▒██
             *  ░░░█████████████▒▒▒▒▀██▀▒▒▒▒▀██▀▒▒▒▒▒██
             *  ░░░█▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒██
             *  ░██▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒██▒▒▒▒▒▒▒▒▒██▒▒▒▒██
             *  ██▒▒▒███████████▒▒▒▒▒██▒▒▒▒▒▒▒██▒▒▒▒▒██
             *  █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒███████▒▒▒▒▒▒▒██
             *  ██▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░
             *  ░█▒▒▒███████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░░░
             *  ░██▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█░░░░░
             *  ░░████████████░░░████████████████░░░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░▄█████▄░▄███████▄░▄███████▄░██████▄░░
             *  ░░██▒▒▒▒█░███▒▒▒███░███▒▒▒███░██▒▒▒██░░
             *  ░░██▒▒▒▒▒░██▒▒▒▒▒██░██▒▒▒▒▒██░██▒▒▒██░░
             *  ░░██▒▒▒▀█░███▒▒▒███░███▒▒▒███░██▒▒▒██░░
             *  ░░▀█████▀░▀███████▀░▀███████▀░██████▀░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░▄█████░██▒▒▒▒██▀░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░██▀▒▒▒░██▒▒▒██░░░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░██▒▒▒▒░█████▀░░░░░░░
             *  ░░░░██▒▒▒▒░██▄▒▄██░██▄▒▒▒░██▒▒▒██░░░░░░
             *  ░░░░▀█████░▀█████▀░▀█████░██▒▒▒▒██▄░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             */

            // QUERIES!

            // - how many Songs start with the letter 'a' (case insensitive) /
            // - how many artists end with letter 'a' (case insensitive) /
            // - whats the name of the song with longest duration /
            // - whats the total Duration of all Songs /
            // - how many albums have Songs longer than 300 seconds /
            // - print the names of the artists(separated with "--"), that have more than one album of PopRock genre /
            // - print the name of the album that has highest Average duration of a song /
            // - how many characters has the song that has the shortest Duration /
            // - print the name and the genre of the album that has most songs /
            // - print the name of the artist that has most songs /
            // - print the type of the artist(SoloArtist/Band) that has most albums published before year 2000 /
            // - print the average song duration, of the album that has most songs /

            // Bonus:
            // - print the longest song duration of the album that has least songs /
            // - print the name of the album that has most songs that contain letter 'a' in the name /
            // - print the name of the artist that has most songs that end with letter 'd' /



            // ************ Don't mind the structure, focus on the lists declared on the beginning of Program.cs ****************

            // 3, 2, 1.... GO! :)

            List <Song> songsStartingWithA = Songs.Where(x => x.Name.StartsWith('A')).ToList();

            Console.WriteLine(@"Songs starting with ""a"": {0}", songsStartingWithA.Count);
            songsStartingWithA.ForEach(x => Console.WriteLine(x.Name));

            Console.WriteLine("=======================================");

            List <Artist> artistsEndingWithA = Artists.Where(x => x.FullName.EndsWith('a')).ToList();

            Console.WriteLine(@"Artists ending with ""a"": {0}", artistsEndingWithA.Count);
            artistsEndingWithA.ForEach(x => Console.WriteLine(x.FullName));

            Console.WriteLine("=======================================");

            string songWithLongestDuration = Songs.OrderByDescending(x => x.Duration)
                                             .Take(1)
                                             .Select(x => x.Name)
                                             .ToString();

            Console.WriteLine("The song with the longest duration is: {0}", songWithLongestDuration);

            Console.WriteLine("=======================================");

            int totalSongDuration = Songs.Sum(x => x.Duration);

            Console.WriteLine("The total duration of all the song is {0} minutes.", totalSongDuration / 60);

            Console.WriteLine("=======================================");

            List <Album> albumsWithSongsOver300 = Albums.Where(x => x.Songs.Any(y => y.Duration > 300)).ToList();

            Console.WriteLine("The count of the albums with song duration over 300 seconds is: {0}", albumsWithSongsOver300.Count());

            Console.WriteLine("=======================================");

            List <string> artistsWithPopRockAlbums = Artists.Where(x => x.Albums.Any(y => y.Genre.Equals(Genre.PopRock))).Select(x => x.FullName).ToList();

            foreach (var name in artistsWithPopRockAlbums)
            {
                Console.WriteLine("Artist: {0}", name);
                Console.WriteLine("----------------------------");
            }

            Console.WriteLine("=======================================");

            string albumWithTheHighestAvrDurSong = Albums.OrderByDescending(x => x.Songs.Average(a => a.Duration)).FirstOrDefault().Name;

            Console.WriteLine(albumWithTheHighestAvrDurSong);

            Console.WriteLine("=======================================");

            char[] charsOfSongWithShortestDuration = Songs.OrderBy(x => x.Duration).Select(x => x.Name).FirstOrDefault().ToCharArray();
            Console.WriteLine("The shortest duration song has {0} characters.", charsOfSongWithShortestDuration.Length);

            Console.WriteLine("=======================================");

            var albumWithMostSongs = Albums.OrderByDescending(x => x.Songs.Count).Select(x => new { x.Name, x.Genre }).FirstOrDefault();

            Console.WriteLine("The album with most songs is: Name: {0} | Genre: {1}", albumWithMostSongs.Name, albumWithMostSongs.Genre);

            Console.WriteLine("=======================================");

            string artistWithMostSongs = Artists.OrderByDescending(x => x.Albums.Sum(y => y.Songs.Count)).Select(x => x.FullName).FirstOrDefault();

            Console.WriteLine("The artist with the most songs is: {0}.", artistWithMostSongs);

            Console.WriteLine("=======================================");

            ArtistType typeOfArtistWithMostAlbumsBefore2000 = Artists.OrderByDescending(x => x.Albums.Any(y => y.Year < 2000)).Select(x => x.ArtistType).FirstOrDefault();

            Console.WriteLine("The type of the artist that has the most albums published before the year 2000 is: {0}", typeOfArtistWithMostAlbumsBefore2000);

            Console.WriteLine("=======================================");

            double averageSongDurationOfTheAlbumWithMostSongs = Albums.OrderByDescending(x => x.Songs.Count).Select(x => x.Songs.Average(a => a.Duration)).FirstOrDefault();

            Console.WriteLine("The average song duration of the album with most songs is: {0} minutes.", averageSongDurationOfTheAlbumWithMostSongs / 60);

            Console.WriteLine("=======================================");

            Album albumWIthTheLeastSongs = Albums.OrderBy(x => x.Songs.Count).FirstOrDefault();

            double longestSongOfAlbumWithLeastSongs = albumWIthTheLeastSongs.Songs.OrderByDescending(x => x.Duration).FirstOrDefault().Duration;

            Console.WriteLine("The longest song duration of the album with least songs is: {0} seconds | From the album \"{1}\"", longestSongOfAlbumWithLeastSongs, albumWIthTheLeastSongs.Name);

            Console.WriteLine("=======================================");

            string albumWithTheMostSongsThatContainTheLetterA = Albums.OrderByDescending(x => x.Songs.Where(a => a.Name.Contains('a')).Count()).Select(x => x.Name).FirstOrDefault();

            Console.WriteLine("The name of the album that has most songs that contain the letter 'a' in the name is: {0}", albumWithTheMostSongsThatContainTheLetterA);

            Console.WriteLine("=======================================");

            string nameOfTheArtistWithMostSongsThatEndOnD = Artists.OrderByDescending(x => x.Albums.All(a => a.Songs.Any(z => z.Name.EndsWith('d')))).Select(x => x.FullName).FirstOrDefault();

            Console.WriteLine("The name of the artist that has the most songs ending with the letter 'd' is: \"{0}\"", nameOfTheArtistWithMostSongsThatEndOnD);

            Console.ReadLine();
        }
Exemple #11
0
        static void Main(string[] args)
        {
            Init();// this method fills the arrays above with data

            // - print the mass of the earth on July 1895 XD

            /*
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░
             *  ░░███████░░░░░░░░░░███▒▒▒▒▒▒▒▒███░░░░░░
             *  ░░█▒▒▒▒▒▒█░░░░░░░███▒▒▒▒▒▒▒▒▒▒▒▒███░░░░
             *  ░░░█▒▒▒▒▒▒█░░░░██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░░
             *  ░░░░█▒▒▒▒▒█░░░██▒▒▒▒▄██▄▒▒▒▒▄██▄▒▒▒███░
             *  ░░░░░█▒▒▒█░░░█▒▒▒▒▒▒████▒▒▒▒████▒▒▒▒▒██
             *  ░░░█████████████▒▒▒▒▀██▀▒▒▒▒▀██▀▒▒▒▒▒██
             *  ░░░█▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒██
             *  ░██▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒██▒▒▒▒▒▒▒▒▒██▒▒▒▒██
             *  ██▒▒▒███████████▒▒▒▒▒██▒▒▒▒▒▒▒██▒▒▒▒▒██
             *  █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒███████▒▒▒▒▒▒▒██
             *  ██▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░
             *  ░█▒▒▒███████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░░░
             *  ░██▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█░░░░░
             *  ░░████████████░░░████████████████░░░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░▄█████▄░▄███████▄░▄███████▄░██████▄░░
             *  ░░██▒▒▒▒█░███▒▒▒███░███▒▒▒███░██▒▒▒██░░
             *  ░░██▒▒▒▒▒░██▒▒▒▒▒██░██▒▒▒▒▒██░██▒▒▒██░░
             *  ░░██▒▒▒▀█░███▒▒▒███░███▒▒▒███░██▒▒▒██░░
             *  ░░▀█████▀░▀███████▀░▀███████▀░██████▀░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░▄█████░██▒▒▒▒██▀░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░██▀▒▒▒░██▒▒▒██░░░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░██▒▒▒▒░█████▀░░░░░░░
             *  ░░░░██▒▒▒▒░██▄▒▄██░██▄▒▒▒░██▒▒▒██░░░░░░
             *  ░░░░▀█████░▀█████▀░▀█████░██▒▒▒▒██▄░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             */

            // QUERIES!

            // 1. how many Songs start with the letter 'a' (case insensitive)


            List <Song> songsWithA = Songs.Where(x => x.Name.StartsWith("A"))
                                     .ToList();

            if (songsWithA.Count == 1)
            {
                Console.WriteLine($"{songsWithA.Count} songs start with letter A:");
            }
            else
            {
                Console.WriteLine($"{songsWithA.Count} songs starts with letter A:");
            }

            songsWithA.ForEach(x => Console.WriteLine(x.Name));

            Console.WriteLine("====================================================================================");

            //// 2. how many artists end with letter 'a' (case insensitive)


            List <Artist> artistWithA = Artists.Where(x => x.FullName.EndsWith("a"))
                                        .ToList();

            if (artistWithA.Count == 1)
            {
                Console.WriteLine($"{artistWithA.Count} artist name ends with letter A:");
            }
            else
            {
                Console.WriteLine($"{artistWithA.Count} artists name ends with letter A:");
            }

            artistWithA.ForEach(x => Console.WriteLine(x.FullName));

            Console.WriteLine("====================================================================================");

            // 3. whats the name of the song with longest duration


            List <string> longestSong = Songs.OrderByDescending(x => x.Duration)
                                        .Take(1)
                                        .Select(x => x.Name)
                                        .ToList();

            longestSong.ForEach(x => Console.WriteLine($"The name of the song with longest duration is: {x}."));

            Console.WriteLine("====================================================================================");

            //4. whats the total Duration of all Songs


            int totalDuration = Songs.Sum(x => x.Duration);

            Console.WriteLine($"Total duration of songs is: {totalDuration} seconds.");

            Console.WriteLine("====================================================================================");

            // 5. how many albums have Songs longer than 300 seconds

            var albumWithLongSongs = Songs.Where(x => x.Duration > 300)
                                     .GroupBy(x => x.AlbumId)
                                     .ToList();

            Console.WriteLine($"There are {albumWithLongSongs.Count} albums with songs longer than 300 seconds.");

            Console.WriteLine("====================================================================================");


            // 6. print the names of the artists(separated with "--"), that have more than one album of PopRock genre

            List <Artist> artistWithPR = new List <Artist>();

            Console.WriteLine("Artist that have more than one PopRock album are:");
            foreach (var artist in Artists)
            {
                var popRockAlbum = artist.Albums.Where(x => x.Genre == Genre.PopRock)
                                   .ToList()
                                   .Count();

                if (popRockAlbum > 1)
                {
                    artistWithPR.Add(artist);
                }
            }

            int total = artistWithPR.Count - 1;

            for (int i = 0; i < artistWithPR.Count; i++)
            {
                if (i == total)
                {
                    Console.Write(artistWithPR[i].FullName);
                }
                else
                {
                    Console.Write(artistWithPR[i].FullName + " == ");
                }
            }

            Console.WriteLine("\n====================================================================================");


            // 7. print the name of the album that has highest Average duration of a song

            var albumHighestAve = Albums.OrderByDescending(x => x.Songs.Average(y => y.Duration))
                                  .Select(x => x.Name)
                                  .FirstOrDefault();

            Console.WriteLine($"{albumHighestAve} is the album with the highest average duration of a song.");

            Console.WriteLine("====================================================================================");

            // 8. how many characters has the song that has the shortest Duration


            Song shortestSong = Songs.OrderBy(x => x.Duration)
                                .FirstOrDefault();

            string songName = shortestSong.Name;
            int    count    = 0;

            for (int i = 0; i < songName.Length; i++)
            {
                if (songName[i] != ' ')
                {
                    count++;
                }
            }


            Console.WriteLine($"The shortest song {shortestSong.Name} has {count} characters.");

            Console.WriteLine("====================================================================================");


            // 9. print the name and the genre of the album that has most songs

            var albumWithMostSongs = Albums.OrderByDescending(x => x.Songs.Count())
                                     .FirstOrDefault();

            Console.WriteLine($"The album {albumWithMostSongs.Name} with genre of {albumWithMostSongs.Genre} music has the most songs.");

            Console.WriteLine("====================================================================================");


            // 10. print the name of the artist that has most songs

            var artistMostSongs = Artists.OrderByDescending(x => x.Albums.Sum(y => y.Songs.Count))
                                  .FirstOrDefault();

            Console.WriteLine($"Artist that has the most songs is {artistMostSongs.FullName}.");

            Console.WriteLine("====================================================================================");


            // 11. print the type of the artist(SoloArtist/Band) that has most albums published before year 2000


            var artistBefore2000 = Artists.OrderByDescending(x => x.Albums.Any(y => y.Year < 2000))
                                   .ToList()
                                   .FirstOrDefault();

            Console.WriteLine($"The artist that has most album published before 2000 is from type {artistBefore2000.ArtistType}.");


            Console.WriteLine("====================================================================================");


            // 12. print the average song duration, of the album that has most songs


            //var albumWithMostSongs = Albums.OrderByDescending(x => x.Songs.Count()).FirstOrDefault(); (od 9 zadaca)
            var songAve = albumWithMostSongs.Songs.Average(x => x.Duration);

            Console.WriteLine($"The average song duration of the album with most songs {albumWithMostSongs.Name} is {songAve} seconds.");

            Console.WriteLine("====================================================================================");


            // Bonus:
            // 13. print the longest song duration of the album that has least songs

            var longestSongShortAlbum = Albums.OrderBy(x => x.Songs.Count())
                                        .FirstOrDefault()
                                        .Songs.OrderByDescending(y => y.Duration)
                                        .ToList();

            Console.WriteLine($"Longest song duration of the album that has least songs is the song {longestSongShortAlbum.FirstOrDefault().Name} with duration of {longestSongShortAlbum.FirstOrDefault().Duration} seconds.");

            Console.WriteLine("====================================================================================");


            // 14. print the name of the album that has most songs that contain letter 'a' in the name

            var albumWithMostAs = Albums.OrderByDescending(x => x.Songs.Where(y => y.Name.Contains('a')).Count())
                                  .ToList()
                                  .FirstOrDefault();

            Console.WriteLine($"The album that has most songs that contain the letter 'a' in the name is {albumWithMostAs.Name}.");

            Console.WriteLine("====================================================================================");

            //// 15. print the name of the artist that has most songs that end with letter 'd'

            var artistsWithMostDs = Artists.OrderByDescending(x => x.Albums.Max(y => y.Songs.Count(z => z.Name.EndsWith('d'))))
                                    .ToList()
                                    .FirstOrDefault();

            Console.WriteLine($"The name of the artist that has most songs which end on the letter 'd' is {artistsWithMostDs.FullName}.");



            //var albumsWithMostDs = Albums.OrderByDescending(x => x.Songs.Where(y => y.Name.EndsWith("d")).Count()).ToList().FirstOrDefault();
            //Console.WriteLine(albumsWithMostDs.Name);

            // ************ Don't mind the structure, focus on the lists declared on the beginning of Program.cs ****************

            // 3, 2, 1.... GO! :)



            Console.ReadLine();
        }
 public List <Album> GetAlbums()
 {
     return(Albums.OrderBy(alb => alb.Title).ToList());
 }