Example #1
0
        private FavoriteLiveSongList GetAnalysisPart(Song song)
        {
            var setSongService  = new SetSongService(Ioc.GetInstance <ISetSongRepository>());
            var analysisService = new AnalysisService(Ioc.GetInstance <IAnalysisRepository>());
            var songService     = new SongService(Ioc.GetInstance <ISongRepository>());

            //Get all Analysis for that Song but in groups of SetSong
            var analysis = analysisService.GetAnalysisBySong(song.SongId).GroupBy(x => x.SetSongId);

            double      highestRating = 0;
            double?     rating        = 0;
            List <Guid> setSongIds    = new List <Guid>();

            //If there are no analysis then there is nothing to see here
            if (analysis.Count() == 0)
            {
                return(null);
            }

            var fave = new FavoriteLiveSongList(SetSong.FromSong(song));

            //If there are 1 or more analysis then we need to find out which is the highest ranked
            foreach (var a in analysis)
            {
                rating = a.Average(x => x.Rating);
                var setSongId = a.First().SetSongId;

                if (rating.HasValue && rating.Value > highestRating)
                {
                    highestRating          = rating.Value;
                    fave.HighestRatedShows = new List <Show>();

                    var setSong = (SetSong)setSongService.GetSetSong(setSongId);
                    var show    = GetShowFromSetSong(setSongId);
                    fave.HighestRatedShows.Add(show);
                }
                else if (rating.HasValue && rating.Value == highestRating)
                {
                    var setSong = (SetSong)setSongService.GetSetSong(setSongId);
                    var show    = GetShowFromSetSong(setSongId);

                    fave.HighestRatedShows.Add(show);
                }
            }

            fave.HighestRating = highestRating;

            return(fave);
        }
Example #2
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);
        }
        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);
        }