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); }
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); }
private void TranslateSongDTOToSongBDO( Song song, SongBDO songBDO) { songBDO.SongID = song.SongID; songBDO.Name = song.SongName; songBDO.RowVersion = song.RowVersion; }
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)); } }
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); }
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); }