public IHttpActionResult GetAll() { try { IDal <Song, int> songsDAl = new SongDal(); List <Song> songs = songsDAl.GetAll().ToList(); return(Ok(songs)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult Delete(int key) { try { if (key < 1) { throw new ArgumentException("Key as Guid is Empty."); } IDal <Song, int> songsDAl = new SongDal(); songsDAl.Delete(key); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult Create(Song song) { try { if (!IsSongValid(song)) { throw new ArgumentException("Model is not valid."); } IDal <Song, int> songsDAl = new SongDal(); int songKey = songsDAl.Create(song); return(Ok(songKey)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult GetSongById(int key) { try { if (key < 0) { throw new ArgumentException("Key as Guid is Empty."); } IDal <Song, int> songsDAl = new SongDal(); Song song = songsDAl.GetByID(key); return(Ok(song)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult Update(Song song) { try { if (song == null || song.ID < 1) { throw new ArgumentException("Key as int is Empty."); } IDal <Song, int> songsDAl = new SongDal(); songsDAl.Update(song); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }