public ActionResult Create(PlayList playlist) { if (ModelState.IsValid) { playlistRepository.InsertOrUpdate(playlist); playlistRepository.Save(); return RedirectToAction("Index"); } else { return View(); } }
public void InsertOrUpdate(PlayList playlist) { if (playlist.PlayListId == default(int)) { // New entity context.PlayLists.Add(playlist); } else { // Existing entity context.Entry(playlist).State = EntityState.Modified; } }
public ActionResult AddToPlayList(int trackId, string returnUrl) { if (User.Identity.IsAuthenticated) { MusicRoomContext context = new MusicRoomContext(); PlayListRepository playListRepository = new PlayListRepository(); PlayList playList = new PlayList(); foreach (var data in context.Tracks) { if (data.TrackId == trackId) { playList.TrackPath = data.FileName; playList.Author = data.Author; playList.TrackName = data.TrackName; } } playList.UserId = WebSecurity.CurrentUserId; playListRepository.InsertOrUpdate(playList); playListRepository.Save(); } return Redirect(returnUrl); }