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 FilmRepository(context)) { repository.Delete(id); context.SaveChanges(); } } catch (Exception ex) { throw new MediaManagerException($"Erreur : {ex.Message}", ExceptionReturnType.Error); } }
public static void Save(Film element) { if (element == null) { throw new MediaManagerException($"Erreur : {nameof(element)} is null", ExceptionReturnType.Error); } try { using (var context = new MediaManagerContext()) using (var repository = new FilmRepository(context)) { repository.Save(element); context.SaveChanges(); } } catch (Exception ex) { throw new MediaManagerException($"Erreur :{ex.Message}", ExceptionReturnType.Error); } }