public async Task <ActionResult> Post(int albumId, [FromBody] CreateUpdateSongDto model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var song = await _songService.AddSongAsync(albumId, model); return(Created($"api/album/{albumId}/song/{song.Id}", null)); }
public async Task <IHttpActionResult> Add([FromBody] SongModel songModel) { if (!ModelState.IsValid) { return(BadRequest("Bad song model format")); } try { var song = mapper.Map <SongDTO>(songModel); await service.AddSongAsync(song); return(Ok("Song was succesfully added")); } catch (Exception e) { return(InternalServerError(e)); } }
public async Task SaveAllAsync() { await SaveAlbumInformationAsync(); var songs = Mapper.Map <Song[]>(Songs); // first, check validity of song data if (Songs.Any(s => !string.IsNullOrEmpty(s.Error))) { var message = Songs.Where(s => s.Error != "") .Select(s => s.TrackNo.ToString()) .Aggregate((t, s) => t + ", " + s); MessageBox.Show($"Errors in songs #{message}"); return; } var i = 0; foreach (var song in songs) { song.AlbumId = Album.Id; if (song.Id == -1) { await _songService.AddSongAsync(song); // update song Id after adding it to database Songs[i++].Id = song.Id; } else { await _songService.UpdateSongAsync(song); } } }