Ejemplo n.º 1
0
        public bool UpdateSong(ref Song song,
                               ref string message)
        {
            bool result = true;

            // Name can't be empty
            if (string.IsNullOrEmpty(song.SongName))
            {
                message = "Song name cannot be empty";
                result  = false;
            }
            else
            {
                try
                {
                    var songBDO = new SongBDO();
                    TranslateSongDTOToSongBDO(song,
                                              songBDO);
                    result = songLogic.UpdateSong(
                        ref songBDO, ref message);
                    song.RowVersion = songBDO.RowVersion;
                }
                catch (Exception e)
                {
                    string msg = e.Message;
                    throw new FaultException <SongFault>
                              (new SongFault(msg), msg);
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public Song GetSong(int id)
        {
            SongBDO songBDO = null;

            try
            {
                songBDO = songLogic.GetSong(id);
            }
            catch (Exception e)
            {
                string msg    = e.Message;
                string reason = "GetSong Exception";
                throw new FaultException <SongFault>
                          (new SongFault(msg), reason);
            }
            if (songBDO == null)
            {
                string msg =
                    string.Format("No song found for id {0}",
                                  id);
                string reason = "GetSong Empty";
                throw new FaultException <SongFault>
                          (new SongFault(msg), reason);
            }
            Song song = new Song();

            TranslateSongBDOToSongDTO(songBDO,
                                      song);
            return(song);
        }
Ejemplo n.º 3
0
 private void TranslateSongDTOToSongBDO(
     Song song,
     SongBDO songBDO)
 {
     songBDO.SongID     = song.SongID;
     songBDO.Name       = song.SongName;
     songBDO.RowVersion = song.RowVersion;
 }
Ejemplo n.º 4
0
        public bool UpdateSong(
            ref SongBDO songBDO,
            ref string message)
        {
            var songInDB =
                GetSong(songBDO.SongID);

            // invalid song to update
            if (songInDB == null)
            {
                message = "cannot get song for this ID";
                return(false);
            }
            {
                return(songDAO.UpdateSong(ref songBDO,
                                          ref message));
            }
        }
Ejemplo n.º 5
0
        public SongBDO GetSong(int id)
        {
            SongBDO songBDO = null;

            using (var MBEntities = new MusicBathEntities())
            {
                Song song = (from s in MBEntities.Song
                             where s.SongID == id
                             select s).FirstOrDefault();
                if (song != null)
                {
                    songBDO = new SongBDO()
                    {
                        SongID     = song.SongID,
                        Name       = song.Name,
                        RowVersion = song.RowVersion
                    }
                }
                ;
            }
            return(songBDO);
        }
Ejemplo n.º 6
0
        public bool UpdateSong(
            ref SongBDO songBDO,
            ref string message)
        {
            message = "song updated successfully";
            bool ret = true;

            using (var MBEntities = new MusicBathEntities())
            {
                var  songID   = songBDO.SongID;
                Song songInDB =
                    (from s
                     in MBEntities.Song
                     where s.SongID == songID
                     select s).FirstOrDefault();
                // check songg
                if (songInDB == null)
                {
                    throw new Exception("No song with ID " +
                                        songBDO.SongID);
                }
                MBEntities.Song.Remove(songInDB);
                // update song
                songInDB.Name       = songBDO.Name;
                songInDB.RowVersion = songBDO.RowVersion;
                MBEntities.Song.Attach(songInDB);
                MBEntities.Entry(songInDB).State =
                    System.Data.Entity.EntityState.Modified;
                int num = MBEntities.SaveChanges();
                songBDO.RowVersion = songInDB.RowVersion;
                if (num != 1)
                {
                    ret     = false;
                    message = "no song is updated";
                }
            }
            return(ret);
        }