public IActionResult UpdateSong(UpdateSongRequest data) { var result = (repository.UpdateSong(data)); { if (result) { return(Ok(new { message = "Successfully Edited" })); } return(Unauthorized("Authorization failed")); } }
public HttpResponseMessage UpdateSong(string id, [FromBody] UpdateSongRequest request) { logger.Info("Updating song"); try { var updatedSong = playlist.Update(id, request); return(this.Request.CreateResponse(HttpStatusCode.OK, updatedSong)); } catch (SongNotFoundException e) { logger.Warn("Could not find song to update"); return(this.Request.CreateResponse(HttpStatusCode.NotFound)); } }
public async Task <bool> UpdateName(int id, [FromBody] UpdateSongRequest request) { var artist = await _authenticatedUser.GetArtistAsync(); var song = await _songCollection.GetSongByIdAsync(id); if ((await song.GetArtistAsync()).Id != artist.Id) { throw new HttpException(HttpStatusCode.Unauthorized); } song.Name = request.Name; song.Duration = request.Durtion; return(await song.SaveAsync()); }
/// <summary> /// Updates a song. /// </summary> /// <param name="songId">The id of the song to update.</param> /// <param name="request">The updates to enact.</param> /// <returns>The updated song</returns> public Song UpdateSong(string songId, UpdateSongRequest request) { Song result; try { result = playlist.Update(songId, request); } catch (SongNotFoundException e) { result = new Song(); } catch (Exception e) { logger.Error(e.ToString()); System.Diagnostics.Trace.Write(e.ToString()); result = new Song(); } return(result); }
public bool UpdateSong(UpdateSongRequest request) { if (request != null) { var song = _db.SongLists.Where(a => a.Id == request.Id).FirstOrDefault(); if (song != null) { song.SongName = string.IsNullOrEmpty(request.Name) ? song.SongName : request.Name; song.Url = string.IsNullOrEmpty(request.Url) ? song.Url : request.Url; song.Artist = string.IsNullOrEmpty(request.Artist) ? song.Artist : request.Artist; song.Album = string.IsNullOrEmpty(request.Album) ? song.Album : request.Album; song.image = string.IsNullOrEmpty(request.Image) ? song.image : request.Image; _db.SaveChanges(); return(true); } return(false); } return(false); }
public void UpdatingSongAddsItGenreToList() { var savedSongId = musicPlaylist.Add(_registerSongRequest); var updateRequest = new UpdateSongRequest("::artist::", "::title::", new List <string>() { "Pop", "Country" }); musicPlaylist.Update(savedSongId, updateRequest); var genres = musicPlaylist.ViewGenres(); genres.Sort(); var expectedGenres = new List <string> { "pop", "country" }; expectedGenres.Sort(); Assert.IsTrue(genres.SequenceEqual(expectedGenres)); }
public void Update(string id, UpdateSongRequest req) { var filter = Builders <Song> .Filter.Eq("Id", id); List <Task> tasks = new List <Task>(); if (req.Audio != null) { var update = Builders <Song> .Update.Set("Audio", req.Audio); tasks.Add(_songs.UpdateOneAsync(filter, update)); } if (req.Name != null) { var update = Builders <Song> .Update.Set("Name", req.Name); tasks.Add(_songs.UpdateOneAsync(filter, update)); } if (req.CategoriesId != null) { var update = Builders <Song> .Update.Set("CategoriesId", req.CategoriesId); tasks.Add(_songs.UpdateOneAsync(filter, update)); } if (req.ArtistId != null) { var update = Builders <Song> .Update.Set("ArtistId", req.ArtistId); tasks.Add(_songs.UpdateOneAsync(filter, update)); } Task.WaitAll(tasks.ToArray()); }
public void Update(string id, UpdateSongRequest req) { _songService.Update(id, req); }
/// <summary> /// Update song by id /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='id'> /// The id of the order /// </param> /// <param name='uptadeRequest'> /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task UpdateSongByIdAsync(this IMusicPlaylistRESTAPI operations, string id, UpdateSongRequest uptadeRequest, CancellationToken cancellationToken = default(CancellationToken)) { await operations.UpdateSongByIdWithHttpMessagesAsync(id, uptadeRequest, null, cancellationToken).ConfigureAwait(false); }
/// <summary> /// Update song by id /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='id'> /// The id of the order /// </param> /// <param name='uptadeRequest'> /// </param> public static void UpdateSongById(this IMusicPlaylistRESTAPI operations, string id, UpdateSongRequest uptadeRequest) { Task.Factory.StartNew(s => ((IMusicPlaylistRESTAPI)s).UpdateSongByIdAsync(id, uptadeRequest), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }