public void Update(Music model) { if (model == null || model.Artist == null || model.Genre == null) { throw new ElementUpdateException <Music>(model, "Element incomplete."); } EntityModel.Music oldMusic = _context.Musics.Find(model.ID); EntityModel.Artist artist = _mapper.Map <Artist, EntityModel.Artist>(model.Artist); EntityModel.Genre genre = _mapper.Map <Genre, EntityModel.Genre>(model.Genre); if (oldMusic == null) { throw new ElementUpdateException <Music>(model, "Element to update doesn't exist."); } oldMusic.Name = model.Name; //oldMusic.Artist = artist; oldMusic.ArtistID = (int)artist.ID; //oldMusic.Genre = genre; oldMusic.GenreID = (int)genre.ID; try { _context.Musics.Update(oldMusic); _context.SaveChanges(); } catch (DbUpdateException ex) { throw new ElementUpdateException <Music>(model, "Element to update doesn't exist.", ex); } }
public void Update(Genre model) { EntityModel.Genre oldGender = _context.Genres.Find(model.ID); if (oldGender == null) { throw new ElementUpdateException <Genre>(model, "Element to update doesn't exist"); } oldGender.Name = model.Name; try { _context.Genres.Update(oldGender); _context.SaveChanges(); } catch (DbUpdateException ex) { throw new ElementUpdateException <Genre>(model, "Unable to update", ex); } }