public async void DeleteExistingEpisode() { // Given using (var db = new AmstramgramContext(_options, _dbLogger.Object)) { var episode102 = new Episode { Id = 102, Title = "Episode102" }; await db.Episodes.AddAsync(episode102); await db.SaveChangesAsync(); } // When _episodeRepository.Delete(102); var saved = await _episodeRepository.SaveChangesAsync(); // Then Assert.True(saved); using (var db = new AmstramgramContext(_options, _dbLogger.Object)) { var deletedEpisode = await db.Episodes.FindAsync(102); Assert.Null(deletedEpisode); } }
public ActionResult Delete(int _episodeId) { var episode = _episodeRepository.GetById(_episodeId); _episodeRepository.Delete(episode); return(RedirectToAction("Find")); }
public IHttpActionResult Delete(Episode episode) { if (_episodeRepository.Delete(episode)) { return(StatusCode(HttpStatusCode.NoContent)); } string message = $"Unable to delete Episode ID {episode.Id}"; return(BadRequest(message)); }
public static void Delete(int id) { if (id <= 0) { throw new MediaManagerException($"Erreur : {nameof(id)} <= 0", ExceptionReturnType.Error); } try { using (var context = new MediaManagerContext()) using (var repository = new EpisodeRepository(context)) { repository.Delete(id); context.SaveChanges(); } } catch (Exception ex) { throw new MediaManagerException($"Erreur : {ex.Message}", ExceptionReturnType.Error); } }