public ActionResult Edit(int id) { var service = CreateMusicService(); var detail = service.GetMusicById(id); var model = new MusicEdit { MusicId=detail.MusicId, ArtistName = detail.ArtistName, Duration = detail.Duration, DateRelease = detail.DateRelease, GenreOfMusic = detail.GenreOfMusic, TypeOfMusic = detail.TypeOfMusic }; return View(model); }
public ActionResult Edit(int id, MusicEdit model) { if (!ModelState.IsValid) return View(model); if (model.MusicId != id) { ModelState.AddModelError("", "Id Mismatch"); } var service = CreateMusicService(); if (service.UpdateMusic(model)) { TempData["SaveResult"] = "Your Music was updated"; return RedirectToAction("Index"); } ModelState.AddModelError("", "Music could not be updated"); return View(); }
public bool UpdateMusic(MusicEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Musics .Single(e => e.MusicId == model.MusicId && e.OwnerId == _userId); entity.ArtistName = model.ArtistName; entity.Duration = model.Duration; entity.GenreOfMusic = model.GenreOfMusic; entity.TypeOfMusic = model.TypeOfMusic; entity.DateRelease = model.DateRelease; entity.ModifiedUtc = DateTimeOffset.UtcNow; return ctx.SaveChanges() == 1; } }