public void Save(Song song) { var album = _db.Album.FirstOrDefault(x => x.Id == song.Album.Id); song.Album = album; if (song.Id > 0) { _db.Song.Attach(song); _db.Entry(song).State = EntityState.Modified; _db.SaveChanges(); return; } _db.Song.Add(song); _db.SaveChanges(); }
public ActionResult AddSong(Song model) { var album = AlbumRepository.Get(model.Album.Id); var folder = Path.Combine("song", album.Name); var songName = SaveAttach(folder, Request.Files["Song"]); if (model.Id <= 0) { var order = SongRepository.Count(model.Album.Id) + 1; model.Order = order; } if (model.Id <= 0 || !string.IsNullOrEmpty(songName)) { model.Mp3FileName = songName; } SongRepository.Save(model); return RedirectToAction("Albums"); }
// -------------------- Song Region -------------------- public ActionResult AddSong(long albumId, long? songId) { var model = new Song(); if (songId.HasValue) { model = SongRepository.Get(songId.Value); } else { model.Album = AlbumRepository.Get(albumId); } return View(model); }