/// <summary> /// Fills the <see cref="SavedPodcast"/> with the corresponding modifications and parameters. /// </summary> /// <param name="dto"></param> /// <returns></returns> private SavedPodcast FillSavedPodcastFromDto(SavedPodcastDto dto) { if (dto == null) { throw new EntityNotFoundException(); } var modifications = dto.Modifications.Select(x => x.ToModification()); dto.SavedPodcast.Modifications = modifications.ToList(); return(dto.SavedPodcast); }
/// <summary> /// Persists the <paramref name="toPersist"/> in the database. This creates or updates the entity. Note that all modifications/parameters are recreated in the db as well (increasing their Ids). /// </summary> /// <param name="toPersist"></param> /// <returns></returns> public override SavedPodcast Persist(SavedPodcast toPersist) { RemoveOldSavedPodcastDtosIfOverMaximum(); var dto = Context.Podcasts.Find(toPersist.Id); if (dto == null) { dto = new SavedPodcastDto(toPersist); Context.Podcasts.Add(dto); } if (dto.Modifications != null) { Context.RemoveRange(dto.Modifications); Context.RemoveRange(dto.Modifications.SelectMany(x => x.Parameters)); } dto.Modifications = toPersist.Modifications.Select(x => new ModificationDto(x)).ToList(); Context.SaveChanges(); toPersist.Id = dto.Id; return(toPersist); }