Beispiel #1
0
        public async Task <IActionResult> Create([FromBody] PlaylistNameBM playlistNameModel)
        {
            //validate the name of the playlist
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            MyUser user = _helper.GetAuthUser(this.HttpContext, true);

            if (user == null)
            {
                return(Unauthorized());
            }

            //TODO : there must be a limit for the number of playlists that an user may have.
            //Temporary hack:
            if (user.Playlists.Count() == 20)
            {
                return(BadRequest("Too many playlists."));
            }

            //create new playlist, add it to user's playlists, save context async:
            Playlist playlist = new Playlist(playlistNameModel.playlistName, user);

            user.Playlists.Add(playlist);
            await _context.SaveChangesAsync();

            PlaylistBasicVM playlistVM = new PlaylistBasicVM(playlist);

            return(Ok(playlistVM));
        }
Beispiel #2
0
        public async Task <IActionResult> Edit([FromBody] PlaylistNameBM newName, string playlistIdString)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            Playlist playlist = _helper.GetUserPlaylistById(this.HttpContext, playlistIdString);

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

            //change playlist's name, save context:
            playlist.Name = newName.playlistName;
            await _context.SaveChangesAsync();

            PlaylistBasicVM playlistVM = new PlaylistBasicVM(playlist);

            return(Ok(playlistVM));
        }