コード例 #1
0
        public List <FavoriteLiveSongList> GenerateFavoriteLiveSongList(IQueryable <ISong> songs)
        {
            var songService            = new SongService(Ioc.GetInstance <ISongRepository>());
            var favoriteVersionService = new FavoriteVersionService(Ioc.GetInstance <IFavoriteVersionRepository>());

            List <FavoriteLiveSongList> songLists = new List <FavoriteLiveSongList>();

            foreach (var song in songs)
            {
                var versions = favoriteVersionService.GetAllFavoriteVersions().Where(s => s.SongId == song.SongId).GroupBy(g => g.SetSongId).ToList();

                //If there aren't any favorites chosen for that song then just add the song to be displayed and continue
                if (versions == null || versions.Count() <= 0)
                {
                    var fave = GetAnalysisPart((Song)song);
                    if (fave != null)
                    {
                        songLists.Add(fave);
                    }
                    else
                    {
                        songLists.Add(new FavoriteLiveSongList(SetSong.FromSong((Song)song)));
                    }

                    continue;
                }

                //If there is only 1 favorite version then just use the first one in the collection
                if (versions.Count() == 1)
                {
                    var version   = versions[0].First();
                    var setSongId = version.SetSongId.Value;
                    var setSong   = (SetSong)setSongService.GetSetSong(setSongId);
                    var show      = GetShowFromSetSong(setSongId);

                    var fave = GetAnalysisPart(setSong);
                    if (fave != null)
                    {
                        fave.FavoriteLiveShows.Add(show);
                    }
                    else
                    {
                        fave = new FavoriteLiveSongList(setSong, show);
                    }

                    songLists.Add(fave);
                }
                //There is a lot to check
                else
                {
                    int count = 0;

                    Guid?setSongId = null;

                    FavoriteLiveSongList songList = new FavoriteLiveSongList();

                    foreach (var version in versions)
                    {
                        //If this version has more votes then it needs to be added
                        if (version.Count() >= count)
                        {
                            if (version.Count() > count && count > 0)
                            {
                                //If its not the first time in the loop and this version is the most voted on then clear whatever is in there
                                songList.ClearShows();
                            }

                            //Change the count so that next time it will be right
                            count = version.Count();

                            setSongId = version.First().SetSongId;
                            var setSong = (SetSong)setSongService.GetSetSong(setSongId.Value);
                            var show    = GetShowFromSetSong(setSongId.Value);
                            songList.AddFavorite(setSong, show);
                        }
                    }

                    var fave = GetAnalysisPart(setSongId);

                    if (fave != null)
                    {
                        songList.HighestRating     = fave.HighestRating;
                        songList.HighestRatedShows = fave.HighestRatedShows;
                    }

                    songLists.Add(songList);
                }
            }

            return(songLists);
        }
コード例 #2
0
        public static List <FavoriteSetSong> GenerateFavoriteVersionListByAlbum(string album)
        {
            var songService            = new SongService(Ioc.GetInstance <ISongRepository>());
            var setSongService         = new SetSongService(Ioc.GetInstance <ISetSongRepository>());
            var favoriteVersionService = new FavoriteVersionService(Ioc.GetInstance <IFavoriteVersionRepository>());
            var showService            = new ShowService(Ioc.GetInstance <IShowRepository>());
            var setService             = new SetService(Ioc.GetInstance <ISetRepository>());

            FavoriteVersionSongList songList = new FavoriteVersionSongList();

            foreach (var song in songService.GetSongsByAlbum(album))
            {
                var versions = favoriteVersionService.GetAllFavoriteVersions().Where(s => s.SongId == song.SongId).GroupBy(g => g.SetSongId).ToList();

                if (versions == null || versions.Count() <= 0)
                {
                    songList.AddFavoriteSongPair(null, SetSong.FromSong((Song)song), null);
                    continue;
                }

                if (versions.Count() == 1)
                {
                    var version = versions[0].First();

                    var setSong = setSongService.GetSetSong(version.SetSongId.Value);
                    var set     = setService.GetSet(setSong.SetId.Value);
                    var show    = showService.GetShow(set.ShowId.Value);

                    songList.AddFavoriteSongPair((FavoriteVersion)version, (SetSong)setSong, (Show)show);
                }
                else
                {
                    int count = 0;

                    Guid?           setSongId = null;
                    FavoriteVersion fave      = null;
                    SetSong         setSong   = null;
                    IShow           show      = null;

                    foreach (var version in versions)
                    {
                        if (version.Count() > count)
                        {
                            fave      = (FavoriteVersion)version.First();
                            setSongId = version.First().SetSongId;
                        }
                    }

                    if (setSongId != null)
                    {
                        setSong = (SetSong)setSongService.GetSetSong(setSongId.Value);
                        var set = setService.GetSet(setSong.SetId.Value);
                        show = showService.GetShow(set.ShowId.Value);
                    }

                    songList.AddFavoriteSongPair(fave, setSong ?? SetSong.FromSong((Song)song), (Show)show);
                }
            }

            return(songList.SongList);
        }