public async Task <IActionResult> PutProductSong(string id, ProductSong productSong) { if (id != productSong.Code) { return(BadRequest()); } _context.Entry(productSong).State = EntityState.Modified; ChangeLog.AddUpdatedLog(_context, "Songs", productSong); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductSongExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <ProductSong> > PostProductSong(ProductSongDAO productSongDao) { var product = new Product(); product.Title = productSongDao.Title; product.Price = productSongDao.Price; product.ReleaseYear = productSongDao.ReleaseYear; product.Language = productSongDao.Language; product.Type = ProductType.Song; product.FilePath = productSongDao.FilePath; product.PreviewFilePath = productSongDao.PreviewFilePath; _context.Products.Add(product); var song = new ProductSong(); song.Album = productSongDao.Album; song.Country = productSongDao.Country; var songGenere = _context.ProductSongGenres.Single(songGenere => songGenere.Id == productSongDao.GenreId); song.Genre = songGenere; song.Artist = productSongDao.Artist; song.Label = productSongDao.Label; song.Product = product; var songsConsecutive = _context.TableConsecutives.Single(tableConsecutive => tableConsecutive.Table == "Musica"); song.Code = songsConsecutive.GetCurrentCode(); song.InterpretationType = (SongInterpretationType)productSongDao.InterpretationType; _context.ProductSongs.Add(song); ChangeLog.AddCreatedLog(_context, "Songs", song); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (ProductSongExists(song.Code)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetProductSong", new { id = song.Code }, song)); }