public async Task <ActionResult> Remove(string name) { GenreViewModelMapper mapper = new GenreViewModelMapper(); GenreDetail existingGenre = await _genreRepo.GetAsync(name); GenreItemViewModel model = mapper.MapToViewModel(existingGenre); return(View(model)); }
public async Task <ActionResult> Remove(GenreItemViewModel model) { GenreViewModelMapper mapper = new GenreViewModelMapper(); try { await _genreRepo.DeleteAsync(model.Name); this.SetBootstrapPageAlert("Success", $"Deleted genre '{model.Name}' from the database", BootstrapAlertType.success); return(RedirectToAction(nameof(Index))); }catch (Exception e) { _logger.LogError(e, "Error deleting genre"); ModelState.AddModelError(nameof(model.Name), "Error deleting genre from the database"); GenreDetail existingGenre = await _genreRepo.GetAsync(model.Name); model = mapper.MapToViewModel(existingGenre); } return(View(model)); }