Пример #1
0
        public IHttpActionResult Putdetailplaylist(int id, detailplaylist detailplaylist)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != detailplaylist.iddetailPL)
            {
                return(BadRequest());
            }

            db.Entry(detailplaylist).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!detailplaylistExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult Deleteplaylist(Int32 id)
        {
            //playlist playlist = db.playlists.Find(id);
            //if (playlist == null)
            //{
            //    return NotFound();
            //}

            //db.playlists.Remove(playlist);
            //db.SaveChanges();

            //return Ok(playlist);

            playlist       list   = db.playlists.Find(id);
            detailplaylist detail = db.detailplaylists.Where(b => b.idPlaylist == id)
                                    .FirstOrDefault();

            if (list == null)
            {
                return(Ok(400));
            }
            if (detail != null)
            {
                db.detailplaylists.RemoveRange(db.detailplaylists.Where(c => c.idPlaylist == id));
                db.playlists.Remove(list);
                db.SaveChanges();
                return(Ok(200));
            }
            else
            {
                db.playlists.Remove(list);
                db.SaveChanges();
                return(Ok(200));
            }
        }
Пример #3
0
        public IHttpActionResult Getdetailplaylist(int id)
        {
            detailplaylist detailplaylist = db.detailplaylists.Find(id);

            if (detailplaylist == null)
            {
                return(NotFound());
            }

            return(Ok(detailplaylist));
        }
Пример #4
0
        public IHttpActionResult Postdetailplaylist(detailplaylist detailplaylist)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.detailplaylists.Add(detailplaylist);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = detailplaylist.iddetailPL }, detailplaylist));
        }
Пример #5
0
        public IHttpActionResult Deletedetailplaylist(int id)
        {
            detailplaylist detailplaylist = db.detailplaylists.Find(id);

            if (detailplaylist == null)
            {
                return(NotFound());
            }

            db.detailplaylists.Remove(detailplaylist);
            db.SaveChanges();

            return(Ok(detailplaylist));
        }