public void Create(string title, IEnumerable <TutorialSource> tutorialSources, int exerciceId) { if (_tutorialRepository.All().Any(s => s.Title.Equals(title))) { throw new ExistingTitleException(); } Exercice exo = _exerciceRepository.FindBy(exerciceId); if (exo == null) { throw new ExerciceNotFoundException(); } Tutorial tuto = new Tutorial() { Title = title, Exercice = exo, ExerciceId = exerciceId }; _tutorialRepository.Save(tuto); foreach (var tutorialSource in tutorialSources) { tutorialSource.TutorialId = tuto.Id; tutorialSource.Tutorial = tuto; _sourceRepository.Save(tutorialSource); } }
public void Update(int id, string title, int position, IEnumerable <ExerciceSource> sources) { var exo = _exerciceRepository.FindBy(id); if (exo == null) { throw new BadIdException(); } exo.Title = title; exo.Position = position; _exerciceRepository.Save(exo); exo.Sources.Clear(); foreach (var exerciceSource in sources) { exo.Sources.Add(exerciceSource); exerciceSource.ExerciceId = exo.Id; exerciceSource.Exercice = exo; _sourceRepository.Save(exerciceSource); } }