コード例 #1
0
        public async Task <int?> DetachVolumes(AttachSRERequestModel model)
        {
            var arcsVolumes = this.context.ArcVolumes
                              .Where(i => i.Volume.Number >= model.MinRange &&
                                     i.Volume.Number <= model.MaxRange &&
                                     i.Volume.SeriesId == model.SeriesId &&
                                     i.ArcId == model.ParentId)
                              .ToList();

            if (arcsVolumes.Count == 0)
            {
                throw new ArgumentOutOfRangeException();
            }

            if (model.ParentTypeName == nameof(Arc))
            {
                var arc = this.context.Arcs
                          .Include(a => a.ArcsVolumes)
                          .FirstOrDefault(a => a.Id == model.ParentId);

                foreach (var av in arcsVolumes)
                {
                    arc.ArcsVolumes.Remove(av);
                }

                await this.context.SaveChangesAsync();

                return(arcsVolumes.Count);
            }

            return(null);
        }
コード例 #2
0
        public async Task <ActionResult <int> > AttachVolumesToArc(AttachSRERequestModel model)
        {
            if (!this.ModelState.IsValid || model.MinRange > model.MaxRange)
            {
                return(this.BadRequest("Invalid model."));
            }

            try
            {
                var result = await this.volumeAttachmentService.AttachVolumes(model);

                this.cache.RemoveArcDetails(model.ParentId);
                this.cache.RemoveAllVolumeDetails(this.cacheKeyHolder);

                return(result);
            }
            catch (ArgumentOutOfRangeException)
            {
                return(this.BadRequest("Incorrect volume range or series given."));
            }
            catch (ArgumentNullException)
            {
                return(this.NotFound($"Arc with given id {model.ParentId} does not exist."));
            }
        }
コード例 #3
0
        public async Task <ActionResult <int> > DetachIssuesFromSeriesRelatedEntity(AttachSRERequestModel model)
        {
            if (!this.ModelState.IsValid || model.MinRange > model.MaxRange)
            {
                return(this.BadRequest("Invalid model."));
            }

            try
            {
                var result = await this.issueDetachmentService.DetachIssues(model);

                if (model.ParentTypeName == "Arc")
                {
                    this.cache.RemoveArcDetails(model.ParentId);
                }
                else if (model.ParentTypeName == "Volume")
                {
                    this.cache.RemoveVolumeDetails(model.ParentId);
                }

                this.cache.RemoveAllIssueDetails(this.cacheKeyHolder);

                return(result);
            }
            catch (ArgumentOutOfRangeException)
            {
                return(this.BadRequest("Incorrect issue range or series given."));
            }
            catch (ArgumentNullException)
            {
                return(this.NotFound($"{model.ParentTypeName} with given id {model.ParentId} does not exist."));
            }
        }
コード例 #4
0
        public async Task <int?> AttachIssues(AttachSRERequestModel model)
        {
            var issues = this.dbContext.Issues
                         .Where(i => i.Number >= model.MinRange &&
                                i.Number <= model.MaxRange &&
                                i.SeriesId == model.SeriesId)
                         .ToList();

            if (issues.Count == 0)
            {
                throw new ArgumentOutOfRangeException();
            }

            if (model.ParentTypeName == nameof(Arc))
            {
                var arc = this.dbContext.Arcs
                          .Include(a => a.Issues)
                          .FirstOrDefault(a => a.Id == model.ParentId);

                if (arc == null)
                {
                    throw new ArgumentNullException($"Arc with given id {model.ParentId} does not exist.");
                }

                foreach (var issue in issues)
                {
                    arc.Issues.Add(issue);
                }

                await this.dbContext.SaveChangesAsync();

                return(issues.Count);
            }
            else if (model.ParentTypeName == nameof(Volume))
            {
                var volume = this.dbContext.Volumes
                             .Include(v => v.Issues)
                             .FirstOrDefault(v => v.Id == model.ParentId);

                if (volume == null)
                {
                    throw new ArgumentNullException($"Volume with given id {model.ParentId} does not exist.");
                }

                foreach (var issue in issues)
                {
                    volume.Issues.Add(issue);
                }

                await this.dbContext.SaveChangesAsync();

                return(issues.Count);
            }

            return(null);
        }
コード例 #5
0
        public async Task <ActionResult <int> > DetachVolumesFromArc(AttachSRERequestModel model)
        {
            if (!this.ModelState.IsValid || model.MinRange > model.MaxRange)
            {
                return(this.BadRequest("Invalid model."));
            }

            try
            {
                var result = await this.volumeDetachmentService.DetachVolumes(model);

                this.cache.RemoveArcDetails(model.ParentId);
                this.cache.RemoveAllVolumeDetails(this.cacheKeyHolder);

                return(result);
            }
            catch (ArgumentOutOfRangeException)
            {
                return(this.NotFound("Incorrect volume range, series or arc given."));
            }
        }
コード例 #6
0
        public async Task <int?> AttachArcs(AttachSRERequestModel model)
        {
            var arcs = this.context.Arcs
                       .ToList()
                       .Where(i => i.Number >= model.MinRange &&
                              i.Number <= model.MaxRange &&
                              i.SeriesId == model.SeriesId)
                       .ToList();

            if (arcs.Count() == 0)
            {
                throw new ArgumentOutOfRangeException("Incorrect arc range given.");
            }

            if (model.ParentTypeName == nameof(Volume))
            {
                var volume = this.context.Volumes
                             .FirstOrDefault(v => v.Id == model.ParentId);

                if (volume == null)
                {
                    throw new ArgumentNullException($"Volume with given id {model.ParentId} does not exist.");
                }

                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);
        }