public void btnSubmit_Click(object sender, EventArgs e) { SongService service = new SongService(Ioc.GetInstance<ISongRepository>()); bool success = false; double length = 0; short? order = null; short? jamType = null; if (Validated(out length, out order, out jamType)) { Song song = new Song() { SongId = Guid.NewGuid(), SongName = txtSongName.Text.Trim(), SpecialAppearances = txtSpecialAppearances.Text.Trim(), Album = txtAlbum.Text.Trim(), Order = order, Length = length, JamStyle = jamType, Cover = chkCover.Checked, Notes = txtNotes.Text.Trim(), Abbreviation = txtAbbreviation.Text.Trim() }; service.SaveCommit(song, out success); } if (success) { phSuccess.Visible = true; phError.Visible = false; } else { phError.Visible = true; phSuccess.Visible = false; } }
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; }