public void btnSubmit_Click(object sender, EventArgs e) { FavoriteVersionService faveService = new FavoriteVersionService(Ioc.GetInstance<IFavoriteVersionRepository>()); Guid userId = new Guid(Membership.GetUser(User.Identity.Name).ProviderUserKey.ToString()); if (string.IsNullOrEmpty(ddlFavoriteChoice.SelectedValue)) return; Guid setSongId = new Guid(ddlFavoriteChoice.SelectedValue.Split('^')[0]); Guid songId = new Guid(ddlFavoriteChoice.SelectedValue.Split('^')[1]); var fave = faveService.GetFavoriteVersionByUserIdAndSongId(userId, songId); bool success = false; if (fave != null) { using (IUnitOfWork uow = UnitOfWork.Begin()) { fave.SetSongId = setSongId; fave.UpdatedDate = DateTime.Now; uow.Commit(); success = true; } } else { FavoriteVersion faveVersion = new FavoriteVersion { FavoriteVersionId = Guid.NewGuid(), SetSongId = setSongId, SongId = songId, UserId = userId }; faveService.SaveCommit(faveVersion, out success); } if (success) { var scriptHelper = new ScriptHelper("SuccessAlert", "alertDiv", "Congratulations you have added a favorite version"); Page.RegisterStartupScript(scriptHelper.ScriptName, scriptHelper.GetSuccessScript()); btnChooseAlbum_Click(null, null); } else { var scriptHelper = new ScriptHelper("ErrorAlert", "alertDiv", "Sorry an error has occurred saving your favorite version"); Page.RegisterStartupScript(scriptHelper.ScriptName, scriptHelper.GetFatalScript()); } }
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; }