예제 #1
0
 public HttpResponseMessage CreatePlaylist([FromBody] PlaylistModel playlistModel)
 {
     using (var db = new OnlineMusicEntities())
     {
         var playlist = new Playlist();
         playlistModel.UpdateEntity(playlist);
         playlist.CreatedDate = DateTime.Now;
         playlist.Photo       = GoogleDriveServices.DEFAULT_PLAYLIST;
         db.Playlists.Add(playlist);
         db.SaveChanges();
         db.Entry(playlist).Reference(pl => pl.User).Load();
         playlistModel = dto.GetPlaylistQuery(db, a => a.Id == playlist.Id).FirstOrDefault();
         return(Request.CreateResponse(HttpStatusCode.Created, playlistModel));
     }
 }
예제 #2
0
        public HttpResponseMessage UpdatePlaylist([FromBody] PlaylistModel playlistModel)
        {
            using (var db = new OnlineMusicEntities())
            {
                var playlist = (from a in db.Playlists
                                where a.Id == playlistModel.Id
                                select a).FirstOrDefault();
                if (playlist == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Không tìm thấy playlist id=" + playlistModel.Id));
                }

                playlistModel.UpdateEntity(playlist);
                db.SaveChanges();
                playlistModel = dto.GetPlaylistQuery(db, pl => pl.Id == playlist.Id).FirstOrDefault();
                return(Request.CreateResponse(HttpStatusCode.OK, playlistModel));
            }
        }