public ActionResult AddSong(SongViewModel viewModel) { if (ModelState.IsValid) { if (_db.Songs.FirstOrDefault(I => I.Title == viewModel.Title) == null) { var song = new Song(); song.Title = viewModel.Title; song.Writer = viewModel.Writer; song.Genre = viewModel.Genre; song.Tone = viewModel.Tone; song.Rhythm = viewModel.Rhythm; song.Body = viewModel.Body; song.CreatedBy = User.Identity.Name; _db.AddSong(song); _db.Save(); return RedirectToAction("index", "home"); } else { ViewBag.Message = "Bản nhạc này đã có rồi."; } } return View(viewModel); }
void ISongDataSource.AddSong(Song song) { Songs.Add(song); }