Esempio n. 1
0
        private void ValidateParameters(Song inputSong)
        {
            if (string.IsNullOrEmpty(inputSong.Title))
                throw new ArgumentNullException(Utils.GetMemberName(() => inputSong.Title));

            if (string.IsNullOrEmpty(inputSong.Author))
                throw new ArgumentNullException(Utils.GetMemberName(() => inputSong.Author));

            if (string.IsNullOrEmpty(inputSong.AlbumName))
                throw new ArgumentNullException(Utils.GetMemberName(() => inputSong.AlbumName));

            if (!inputSong.PublishDate.HasValue)
                throw new ArgumentNullException(Utils.GetMemberName(() => inputSong.PublishDate));
        }
Esempio n. 2
0
        public int Create(Song inputSong)
        {
            ValidateParameters(inputSong);

            var id = SequenceQuery.Instance.GetSongId();

            OracleDataLayer.Instance.DmlAction(_createSongStatement,
                new KeyValuePair<string, object>(IdText, id),
                new KeyValuePair<string, object>(TitleText, inputSong.Title),
                new KeyValuePair<string, object>(AuthorText, inputSong.Author),
                new KeyValuePair<string, object>(PublishDateText, inputSong.PublishDate),
                new KeyValuePair<string, object>(AlbumNameText, inputSong.AlbumName));

            BuildSongWords(id, inputSong.SongText);

            OracleDataLayer.Instance.Commit();

            return id;
        }
Esempio n. 3
0
        private Song ReadSong(OracleDataReader reader, bool readWords)
        {
            if (!reader.Read())
                return null;

            var song = new Song
                {
                    Id = (int) reader[IdText],
                    Title = (string) reader[TitleText],
                    Author = (string) reader[AuthorText],
                    PublishDate = (DateTime) reader[PublishDateText],
                    AlbumName = (string) reader[AlbumNameText],
                    SongWords = new List<SongWord>()
                };

            if (readWords)
                song.SongWords.AddRange(new SongWordQuery {SongId = song.Id}.Get());

            return song;
        }