public ActionResult Edit(int id) { var service = CreatePlayListService(); var detail = service.GetPlayListById(id); var model = new PlayListEdit { PlayListId = detail.PlayListId, Artist = detail.Artist, Song = detail.Song, Genre = detail.Genre, Youtube = detail.Youtube, }; return(View(model)); }
public bool UpdatePlayList(PlayListEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .PlayLists .Single(e => e.PlayListId == model.PlayListId); entity.Artist = model.Artist; entity.Song = model.Song; entity.Genre = model.Genre; entity.Youtube = model.Youtube; entity.ModifiedUtc = DateTimeOffset.UtcNow; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, PlayListEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.PlayListId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreatePlayListService(); if (service.UpdatePlayList(model)) { TempData["SaveResult"] = "Your PlayList was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your PlayList could not be updated."); return(View(model)); }