Beispiel #1
0
        public Setlist GenerateSets(IEnumerable<Song> masterSongList, SetlistDetail setlistDetail, int bandId, User currentUser)
        {
            if (masterSongList == null) return null;

            var songs = masterSongList.ToArray();
            var numSets = setlistDetail.NumSets;
            var numSetSongs = setlistDetail.NumSongs;

            var setlist = new Setlist
            {
                Band = _bandRepository.Get(bandId),
                Name = setlistDetail.Name,
                DateCreate = DateTime.Now,
                DateUpdate = DateTime.Now,
                UserCreate = currentUser,
                UserUpdate = currentUser,
                SetSongs = new Collection<SetSong>()
            };

            IEnumerable<SetSong> setSongs;

            var numChanges = GetNumberInstrumentChanges(songs);

            switch (numChanges)
            {
                case 0:
                {
                    var keyGenereTempo = new KeyGenreTempo();
                    setSongs = keyGenereTempo.Generate(numSets, numSetSongs, songs);
                    break;
                }
                    
                default:
                {
                    var instrumentSinger = new InstrumentSinger();
                    setSongs = instrumentSinger.Generate(numSets, numSetSongs, songs);
                    break;
                }
            }

            if (setSongs == null) return setlist;

            foreach (var setSong in setSongs)
            {
                setSong.Setlist = setlist;
                setlist.SetSongs.Add(setSong);
            }

            return setlist;
        }
        private static IEnumerable<SetSongDetail> GetSetSongList(Setlist setlist)
        {
            return setlist.SetSongs
                .OrderBy(x => x.SetNumber)
                .ThenBy(x => x.Sequence)
                .Select(x =>
            {
                var songMemberInstrumentList = GetSongMemberInstrumentDetails(x.Song.SongMemberInstruments);

                return new SetSongDetail
                {
                    SetNumber = x.SetNumber,
                    Id = x.Song.Id,
                    Title = x.Song.Title,
                    KeyId = x.Song.Key.Id,
                    KeyDetail = GetSongKeyDetail(x.Song.Key),
                    SingerId = (x.Song.Singer != null) ? x.Song.Singer.Id : 0,
                    Composer = x.Song.Composer,
                    GenreId = x.Song.Genre.Id,
                    TempoId = x.Song.Tempo.Id,
                    NeverClose = x.Song.NeverClose,
                    NeverOpen = x.Song.NeverOpen,
                    Disabled = x.Song.IsDisabled,
                    SongMemberInstrumentDetails = songMemberInstrumentList
                };
            }).ToArray();
        }
        private IEnumerable<SetSongDetail> GetSpareList(Setlist setlist)
        {
            var setSongIds = setlist.SetSongs.Select(x => x.Song.Id);
            var allAListSongs = _songRepository.GetAList(setlist.Band.Id);

            return allAListSongs
                .Where(x => !setSongIds.Contains(x.Id))
                .Select(x =>
            {
                var songMemberInstrumentList = GetSongMemberInstrumentDetails(x.SongMemberInstruments);
                return new SetSongDetail
                {
                    SetNumber = 0,
                    Id = x.Id,
                    Title = x.Title,
                    KeyId = x.Key.Id,
                    KeyDetail = GetSongKeyDetail(x.Key),
                    SingerId = (x.Singer != null) ? x.Singer.Id : 0,
                    Composer = x.Composer,
                    GenreId = x.Genre.Id,
                    TempoId = x.Tempo.Id,
                    NeverClose = x.NeverClose,
                    NeverOpen = x.NeverOpen,
                    Disabled = x.IsDisabled,
                    SongMemberInstrumentDetails = songMemberInstrumentList
                };
            }).ToArray();
        }