public async Task <int?> AttachArcs(AttachSRERequestModel model) { var arcs = this.context.Arcs .Where(i => i.Number >= model.MinRange && i.Number <= model.MaxRange && i.SeriesId == model.SeriesId) .ToList(); if (arcs.Count == 0) { throw new ArgumentOutOfRangeException(); } if (model.ParentTypeName == nameof(Volume)) { var volume = this.context.Volumes .Include(v => v.ArcsVolumes) .FirstOrDefault(v => v.Id == model.ParentId); if (volume == null) { throw new ArgumentNullException(); } foreach (var arc in arcs) { var av = new ArcVolume { Arc = arc, Volume = volume }; volume.ArcsVolumes.Add(av); } await this.context.SaveChangesAsync(); return(arcs.Count); } return(null); }