Ejemplo n.º 1
0
        public IHttpActionResult Put(SongDetailAndEdit song)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateSongService();

            if (!service.UpdateSong(song))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Ejemplo n.º 2
0
        public bool UpdateSong(SongDetailAndEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Songs
                    .Single(e => e.SongId == model.SongID && e.OwnerId == _userId);

                entity.Title   = model.Title;
                entity.Length  = model.Length;
                entity.AlbumId = model.AlbumId;
                entity.GenreId = model.GenreId;

                return(ctx.SaveChanges() == 1);
            }
        }