Ejemplo n.º 1
0
        public IHttpActionResult Delete([FromUri] List <string> externalSpotRef)
        {
            externalSpotRef = externalSpotRef?.Where(name => !string.IsNullOrWhiteSpace(name)).ToList();
            if (externalSpotRef == null || !externalSpotRef.Any())
            {
                ModelState.AddModelError(nameof(externalSpotRef), "External spot references are missing");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var spots = _repository.FindByExternal(externalSpotRef).ToList();

            if (spots.Count == 0)
            {
                return(NotFound());
            }

            var multipartSpots = new Lazy <List <Spot> >(() => _repository.GetAllMultipart().ToList());
            var spotsToDelete  = new List <Guid>();

            foreach (var spot in spots)
            {
                if (!spot.IsMultipartSpot)
                {
                    spotsToDelete.Add(spot.Uid);
                }
                else if (spot.IsTopMultipart())
                {
                    spotsToDelete.AddRange(
                        BreakUtilities.GetLinkedMultipartSpots(spot, multipartSpots.Value, true)
                        .Select(s => s.Uid)
                        );
                }
            }

            _repository.Delete(spotsToDelete.Distinct());

            return(Ok());
        }