public ActionResult Edit(EditSongBindingModel model) { if (ModelState.IsValid) { var song = service.FindSongById(model.Id); if (song == null) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } if (song.Uploader.Id != User.Identity.GetUserId() && !User.IsInRole("admin")) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } service.SongModified(song, model); return(RedirectToAction("Index")); } var viewModel = Mapper.Instance.Map <EditSongBindingModel, EditSongViewModel>(model); return(View(viewModel)); }
public async Task <int> EditSongAsync(EditSongBindingModel model) { var song = this.DbContext .Songs .FirstOrDefault(x => x.Id == model.Id); if (song == null) { return(ErrorId); } song.Description = model.Description; song.PhotoURL = model.PhotoURL; song.HighLightVideoURL = model.HighLightVideoURL; song.AdditionalInfoURL = model.AdditionalInfoURL; if (song.HighLightVideoURL.Contains(CommonConstants.OriginalVideoUrlPart)) { song.HighLightVideoURL = ModifyVideoURL_Embeded.ModifyEmbed(song.HighLightVideoURL); } await this.DbContext.SaveChangesAsync(); return(song.Id); }
public void SongModified(Song song, EditSongBindingModel model) { song = Mapper.Instance.Map <EditSongBindingModel, Song>(model, song); song.Genre = this.context.Genres.Find(model.GenreId); context.Entry(song).State = EntityState.Modified; context.SaveChanges(); }
public async Task <IActionResult> EditSong(EditSongBindingModel model) { if (!this.ModelState.IsValid) { SetErrorMessage(CommonConstants.DangerMessage); return(this.EditSong(model.Id)); } int generatedId = await this.songService.EditSongAsync(model); if (generatedId < 1) { return(RedirectToAction(RedirectConstants.IndexSuffix)); } return(Redirect(string.Format(RedirectConstants.AdministratorAreaSongDetailsPage, generatedId))); }
public async Task <IActionResult> DeleteSong(EditSongBindingModel model) { bool isDeleted = await this.songService.DeleteSongAsync(model.Id); return(RedirectToAction(RedirectConstants.IndexSuffix)); }