Esempio n. 1
0
 /// <summary>
 /// Changes Artists ListView sort order.
 /// </summary>
 /// <param name="sender"></param>
 public void SortArtistsView(object sender, ref string lastArtistHeaderClicked, ref ListSortDirection lastArtistDirection)
 {
     SortListView(sender, ref lastArtistHeaderClicked, ref lastArtistDirection, "Name");
     LastArtistDirectionText = lastArtistDirection == ListSortDirection.Ascending ? "A-Z" : "Z-A";
     Artists = (lastArtistDirection == ListSortDirection.Ascending
         ? Artists.OrderBy(i => i.Name)
         : Artists.OrderByDescending(i => i.Name)).ToList();
     OnPropertyChanged("LastArtistDirectionText");
 }
Esempio n. 2
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();
        }