예제 #1
0
        public async Task <IHttpActionResult> PutPLAYLIST(int id, PLAYLIST pLAYLIST)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != pLAYLIST.ID)
            {
                return(BadRequest());
            }

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PLAYLISTExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #2
0
        public async Task <IHttpActionResult> DeletePLAYLIST(int id)
        {
            PLAYLIST pLAYLIST = await db.PLAYLISTS.FindAsync(id);

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

            db.PLAYLISTS.Remove(pLAYLIST);
            await db.SaveChangesAsync();

            return(Ok(pLAYLIST));
        }
예제 #3
0
        internal PlayList(PLAYLIST p)
        {
            ID           = p.ID;
            Title        = p.Title;
            Description  = p.Description;
            Tags         = p.Tags.IsNullorEmpty() ? new string[] { } : p.Tags.Split(new string[] { Consts.ArraySeparator }, StringSplitOptions.RemoveEmptyEntries);
            HeroArtworks = p.HeroArtworks.IsNullorEmpty() ? new string[] { } : p.HeroArtworks.Split(new string[] { Consts.ArraySeparator }, StringSplitOptions.RemoveEmptyEntries);

            var ids = p.IDs.IsNullorEmpty() ? new string[] { } : p.IDs.Split('|', StringSplitOptions.RemoveEmptyEntries);

            SongsID = Array.ConvertAll(ids, (a) =>
            {
                return(int.Parse(a));
            });
        }
예제 #4
0
        public async Task <IHttpActionResult> PostPLAYLIST(object o)
        {
            var      action     = (o as Newtonsoft.Json.Linq.JObject).SelectToken("Action").ToString();
            var      userId     = int.Parse((o as Newtonsoft.Json.Linq.JObject).SelectToken("UserId").ToString());
            var      newName    = (o as Newtonsoft.Json.Linq.JObject).SelectToken("NewPlaylistName").ToString();
            var      playlistId = int.Parse((o as Newtonsoft.Json.Linq.JObject).SelectToken("PlaylistId").ToString());
            PLAYLIST playlist   = null;

            if (action == "rename")
            {
                playlist = Operations.RenamePlaylist(playlistId, newName);
            }
            if (action == "create")
            {
                playlist = Operations.CreatePlaylist(userId, newName);
            }
            return(CreatedAtRoute("DefaultApi", new { id = playlist.ID }, playlist));
        }