Exemplo n.º 1
0
        public void Delete(int id)
        {
            var entity = GetEntity(id);

            if (entity != null)
            {
                _dbContext.RemoveRange(entity);
            }
        }
Exemplo n.º 2
0
        public void DeleteBySalesAreaName(string salesAreaName)
        {
            var salesAreaDemographics = _dbContext.Query <Entities.Tenant.SalesAreas.SalesAreaDemographic>()
                                        .Where(x => x.SalesArea.Name == salesAreaName)
                                        .ToArray();

            if (salesAreaDemographics.Any())
            {
                _dbContext.RemoveRange(salesAreaDemographics);
            }
        }
Exemplo n.º 3
0
        public void DeleteByShortName(string shortName)
        {
            var existingSalesAreas = _dbContext.Query <Entities.Tenant.SalesAreas.SalesArea>()
                                     .Where(x => x.ShortName == shortName)
                                     .ToArray();

            if (existingSalesAreas.Any())
            {
                _dbContext.RemoveRange(existingSalesAreas);
            }
        }
Exemplo n.º 4
0
        public void DeleteByCombination(string salesArea, string demographic, DateTime?startDate, DateTime?endDate)
        {
            var where = new List <Expression <Func <Entities.Tenant.Universe, bool> > >();
            if (!string.IsNullOrEmpty(salesArea))
            {
                where.Add(x => x.SalesArea.Name == salesArea);
            }

            if (!string.IsNullOrEmpty(demographic))
            {
                where.Add(x => x.Demographic == demographic);
            }

            if (startDate != null && endDate != null)
            {
                where.Add(x => (x.StartDate >= startDate && x.StartDate <= endDate) &&
                          (x.EndDate >= startDate && x.EndDate <= endDate));
            }

            if (where.Any())
            {
                var entities = _dbContext.Query <Entities.Tenant.Universe>().Where(where.AggregateAnd()).ToArray();
                _dbContext.RemoveRange(entities);
            }
        }
Exemplo n.º 5
0
        public void Delete(int eventTypeid)
        {
            var items = _dbContext.Query <EmailAuditEventSettingsEntity>()
                        .Where(x => x.EventTypeId == eventTypeid)
                        .ToArray();

            _dbContext.RemoveRange(items);
        }
Exemplo n.º 6
0
        public void Delete(IEnumerable <Guid> ids)
        {
            var breaks = _dbContext.Query <BreakEntity>()
                         .Where(x => ids.Contains(x.Id))
                         .ToArray();

            _dbContext.RemoveRange(breaks);
        }
Exemplo n.º 7
0
        public void Delete(string salesArea)
        {
            var items = _dbContext.Query <RSSettingsEntity>()
                        .Where(x => x.SalesArea.Name == salesArea)
                        .ToArray();

            _dbContext.RemoveRange(items);
        }
Exemplo n.º 8
0
        public void Remove(IEnumerable <int> ids)
        {
            var entities = PassQuery
                           .Where(p => ids.Contains(p.Id))
                           .ToArray();

            _dbContext.RemoveRange(entities);
        }
Exemplo n.º 9
0
 public void Add(MetadataModel metadata)
 {
     _dbContext.RemoveRange(_dbContext.Query <MetadataCategory>().ToArray());
     if (metadata.Any())
     {
         _dbContext.AddRange(_mapper.Map <IEnumerable <MetadataCategory> >(metadata).ToArray());
     }
 }
Exemplo n.º 10
0
        public void DeleteRangeByGroupId(IEnumerable <int> ids)
        {
            var bookingPositionGroups = _dbContext.Query <BookingPositionGroupEntity>().Where(x => ids.Contains(x.GroupId)).ToArray();

            if (bookingPositionGroups.Any())
            {
                _dbContext.RemoveRange(bookingPositionGroups);
            }
        }
Exemplo n.º 11
0
        public void Delete(IEnumerable <int> ids)
        {
            var entities = _dbContext
                           .Query <Entities.Tenant.AutopilotRule>()
                           .Where(x => ids.Contains(x.Id))
                           .ToArray();

            _dbContext.RemoveRange(entities);
        }
Exemplo n.º 12
0
        public void DeleteRange(IEnumerable <PipelineAuditEvent> items)
        {
            var ids      = items.Select(a => a.Id);
            var toRemove = _dbContext
                           .Query <SqlPipelineEvents.PipelineAuditEvent>()
                           .Where(x => ids.Contains(x.Id))
                           .ToArray();

            _dbContext.RemoveRange(toRemove);
        }
Exemplo n.º 13
0
        public void DeleteRange(IEnumerable <AutoBookTaskReport> autobookTaskReports)
        {
            var ids      = autobookTaskReports.Select(a => a.Id);
            var toRemove = _dbContext
                           .Query <SqlAutoBookTaskReports.AutoBookTaskReport>()
                           .Where(x => ids.Contains(x.Id))
                           .ToArray();

            _dbContext.RemoveRange(toRemove);
        }
        public void RemoveByScenarioId(Guid scenarioId)
        {
            var entities = _dbContext.Query <ScenarioCampaignFailureEntity>()
                           .Where(s => s.ScenarioId == scenarioId).ToArray();

            if (entities.Any())
            {
                _dbContext.RemoveRange(entities);
            }
        }
Exemplo n.º 15
0
        public void DeleteRange(IEnumerable <Guid> ids)
        {
            var clashes = _dbContext.Query <Entities.Tenant.Clash>()
                          .Where(x => ids.Contains(x.Uid))
                          .ToArray();

            if (clashes.Any())
            {
                _dbContext.RemoveRange(clashes);
            }
        }
Exemplo n.º 16
0
        public void Remove(IEnumerable <Guid> ids)
        {
            var entities = _dbContext.Query <ScenarioEntity>()
                           .Where(e => ids.Contains(e.Id))
                           .ToArray();

            if (entities.Any())
            {
                _dbContext.RemoveRange(entities);
            }
        }
Exemplo n.º 17
0
        public void DeleteRange(IEnumerable <int> ids)
        {
            var totalRatings = _dbContext.Query <TotalRatingEntity>()
                               .Where(x => ids.Contains(x.Id))
                               .ToArray();

            if (totalRatings.Any())
            {
                _dbContext.RemoveRange(totalRatings);
            }
        }
Exemplo n.º 18
0
        public void DeleteRangeByExternalRefs(IEnumerable <string> externalRefs)
        {
            var demographics = _dbContext.Query <Entities.Tenant.Demographic>()
                               .Where(x => externalRefs.Contains(x.ExternalRef))
                               .ToArray();

            if (demographics.Any())
            {
                _dbContext.RemoveRange(demographics);
            }
        }
Exemplo n.º 19
0
        public void DeleteRange(IEnumerable <string> salesAreas)
        {
            var inventoryLocks = _dbContext.Query <Entities.Tenant.InventoryStatuses.InventoryLock>()
                                 .Where(x => salesAreas.Contains(x.SalesArea.Name))
                                 .ToArray();

            if (inventoryLocks.Any())
            {
                _dbContext.RemoveRange(inventoryLocks);
            }
        }
Exemplo n.º 20
0
        public void DeleteRange(IEnumerable <Guid> ids)
        {
            var entities = _dbContext.Query <Entities.Tenant.Programmes.Programme>()
                           .Where(e => ids.Contains(e.Id))
                           .ToArray();

            if (entities.Any())
            {
                _dbContext.RemoveRange(entities);
            }
        }
Exemplo n.º 21
0
        public void Delete(string salesArea)
        {
            var items = _dbContext.Query <ISRSettingsEntity>()
                        .Where(x => x.SalesArea.Name == salesArea)
                        .ToArray();

            if (items.Any() == false)
            {
                throw new InvalidOperationException("Sequence contains no elements");
            }

            _dbContext.RemoveRange(items);
        }
Exemplo n.º 22
0
        public void AddOrUpdate(ScenarioCampaignMetric scenarioCampaignMetrics)
        {
            List <ScenarioCampaignMetricEntity> externalEntities = _mapper.Map <List <ScenarioCampaignMetricEntity> >(scenarioCampaignMetrics);

            List <ScenarioCampaignMetricEntity> entities = _dbContext.Query <ScenarioCampaignMetricEntity>()
                                                           .Where(e => e.ScenarioId == scenarioCampaignMetrics.Id)
                                                           .ToList();

            if (!entities.Any())
            {
                _dbContext.BulkInsertEngine.BulkInsert(externalEntities, new BulkInsertOptions()
                {
                    BatchSize = 600000
                });
            }
            else
            {
                var addedEntities   = externalEntities.Where(x => !entities.Contains(x)).ToArray();
                var deletedEntities = entities.Where(x => !externalEntities.Contains(x)).ToArray();

                _dbContext.RemoveRange(deletedEntities);
                _dbContext.AddRange(addedEntities);
            }
        }
Exemplo n.º 23
0
        protected void UpdateProductEntity(Entities.Tenant.Products.Product productEntity, Product productModel)
        {
            PrepareDictionaryCache();
            _mapper.Map(productModel, productEntity);

            var productAdvertiser = productEntity.ProductAdvertisers.FirstOrDefault();

            if (productEntity.ProductAdvertisers.Count == 1 &&
                productAdvertiser.Advertiser.ExternalIdentifier == productModel.AdvertiserIdentifier &&
                productAdvertiser.Advertiser.Name == productModel.AdvertiserName)
            {
                productAdvertiser.StartDate = productModel.AdvertiserLinkStartDate;
                productAdvertiser.EndDate   = productModel.AdvertiserLinkEndDate;
            }
            else
            {
                _dbContext.RemoveRange(productEntity.ProductAdvertisers.ToArray());
                productEntity.ProductAdvertisers.Clear();

                if (!string.IsNullOrWhiteSpace(productModel.AdvertiserIdentifier))
                {
                    if (_dbAdvertisers.TryGetValue(productModel.AdvertiserIdentifier, out var dbAdv))
                    {
                        if (!string.Equals(dbAdv.Name, productModel.AdvertiserName))
                        {
                            dbAdv.Name = productModel.AdvertiserName;
                        }
                    }
                    else
                    {
                        dbAdv = new Advertiser
                        {
                            ExternalIdentifier = productModel.AdvertiserIdentifier,
                            Name      = productModel.AdvertiserName,
                            ShortName = productModel.AdvertiserName
                        };
                        _dbContext.Add(dbAdv);
                        _dbAdvertisers.Add(dbAdv.ExternalIdentifier, dbAdv);
                    }

                    productAdvertiser = new ProductAdvertiser
                    {
                        Product    = productEntity,
                        Advertiser = dbAdv,
                        StartDate  = productModel.AdvertiserLinkStartDate,
                        EndDate    = productModel.AdvertiserLinkEndDate
                    };
                    _dbContext.Add(productAdvertiser);
                    productEntity.ProductAdvertisers.Add(productAdvertiser);
                }
            }

            var productAgency = productEntity.ProductAgencies.FirstOrDefault();

            if (productEntity.ProductAgencies.Count == 1 &&
                productAgency.Agency.ExternalIdentifier == productModel.AgencyIdentifier &&
                productAgency.Agency.Name == productModel.AgencyName)
            {
                productAgency.StartDate = productModel.AgencyStartDate;
                productAgency.EndDate   = productModel.AgencyLinkEndDate;
            }
            else
            {
                _dbContext.RemoveRange(productEntity.ProductAgencies.ToArray());
                productEntity.ProductAgencies.Clear();

                if (!string.IsNullOrWhiteSpace(productModel.AgencyIdentifier))
                {
                    Entities.Tenant.AgencyGroup dbAgencyGroup = null;
                    if (productModel.AgencyGroup != null)
                    {
                        var key = HashCode.Combine(productModel.AgencyGroup.ShortName, productModel.AgencyGroup.Code);
                        if (!_dbAgencyGroups.TryGetValue(key, out dbAgencyGroup))
                        {
                            dbAgencyGroup = _mapper.Map <Entities.Tenant.AgencyGroup>(productModel.AgencyGroup);
                            _dbContext.Add(dbAgencyGroup);
                            _dbAgencyGroups.Add(key, dbAgencyGroup);
                        }
                    }

                    if (_dbAgencies.TryGetValue(productModel.AgencyIdentifier, out var dbAgency))
                    {
                        if (!string.Equals(dbAgency.Name, productModel.AgencyName))
                        {
                            dbAgency.Name = productModel.AgencyName;
                        }
                    }
                    else
                    {
                        dbAgency = new Agency
                        {
                            ExternalIdentifier = productModel.AgencyIdentifier,
                            Name      = productModel.AgencyName,
                            ShortName = productModel.AgencyName
                        };
                        _dbContext.Add(dbAgency);
                        _dbAgencies.Add(dbAgency.ExternalIdentifier, dbAgency);
                    }

                    productAgency = new ProductAgency
                    {
                        Product     = productEntity,
                        Agency      = dbAgency,
                        AgencyGroup = dbAgencyGroup,
                        StartDate   = productModel.AgencyStartDate,
                        EndDate     = productModel.AgencyLinkEndDate
                    };
                    _dbContext.Add(productAgency);
                    productEntity.ProductAgencies.Add(productAgency);
                }
            }

            var productPerson = productEntity.ProductPersons.FirstOrDefault();

            if (productEntity.ProductPersons.Count == 1 &&
                productPerson.Person.ExternalIdentifier == productModel.SalesExecutive?.Identifier &&
                productPerson.Person.Name == productModel.SalesExecutive?.Name)
            {
                productPerson.StartDate = productModel.SalesExecutive.StartDate;
                productPerson.EndDate   = productModel.SalesExecutive.EndDate;
            }
            else
            {
                _dbContext.RemoveRange(productEntity.ProductPersons.ToArray());
                productEntity.ProductPersons.Clear();

                if (!(productModel.SalesExecutive is null))
                {
                    if (_dbPersons.TryGetValue(productModel.SalesExecutive.Identifier, out var dbPerson))
                    {
                        if (!string.Equals(dbPerson.Name, productModel.SalesExecutive.Name))
                        {
                            dbPerson.Name = productModel.SalesExecutive.Name;
                        }
                    }
                    else
                    {
                        dbPerson = _mapper.Map <Person>(productModel.SalesExecutive);
                        _dbContext.Add(dbPerson);
                        _dbPersons.Add(dbPerson.ExternalIdentifier, dbPerson);
                    }

                    productPerson = new ProductPerson
                    {
                        Product   = productEntity,
                        Person    = dbPerson,
                        StartDate = productModel.SalesExecutive.StartDate,
                        EndDate   = productModel.SalesExecutive.EndDate
                    };
                    _dbContext.Add(productPerson);
                    productEntity.ProductPersons.Add(productPerson);
                }
            }
        }
        public void Execute(Guid salesAreaId)
        {
            var salesArea = _dbContext.Find <SalesArea>(salesAreaId);

            if (salesArea is null)
            {
                throw new InvalidOperationException($"SalesArea with id {salesAreaId} was not found");
            }

            (Guid[] notStartedRunIds, int[] notStartedPassIds) = GetNotStartedRunPassIds();

            var breaksToDelete = GatherBreaks(salesArea);

            var clashDiffsToDelete = GatherClashDifferences(salesArea);

            (List <Restriction> restrictionsToDelete,
             List <RestrictionSalesArea> restrictionSalesAreasToDelete) = GatherRestrictions(salesArea);

            var inventoryLocksToDelete = GatherInventoryLocks(salesArea);

            var librarySalesAreaPassPrioritiesToDelete = GatherLibrarySalesAreaPassPriorities(salesArea);

            var isrSettingsToDelete = GatherIsrSettings(salesArea);

            var rsSettingsToDelete = GatherRsSettings(salesArea);

            var breakExclusionsToDelete = GatherBreakExclusions(salesArea, notStartedPassIds);

            var passSalesAreaPrioritiesToDelete = GatherPassSalesAreaPriorities(salesArea, notStartedPassIds);

            (List <PassRatingPoint> passRatingPointsToDelete,
             List <PassRatingPoint> passRatingPointsToUpdate) = GatherPassRatingPoints(salesArea, notStartedPassIds);

            var ratingsPredictionSchedulesToDelete = GatherRatingsPredictionSchedules(salesArea);

            var runSalesAreaPrioritiesToDelete = GatherRunSalesAreaPriorities(salesArea, notStartedRunIds);

            var programmesToDelete = GatherProgrammes(salesArea);

            var salesAreaDemographicsToDelete = GatherSalesAreaDemos(salesArea);

            var schedulesToDelete = GatherSchedules(salesArea);

            var universesToDelete = GatherUniverses(salesArea);

            (List <SponsorshipItem> sponsorshipItemsToDelete,
             List <SponsorshipItem> sponsorshipItemsToUpdate) = GatherSponsorshipItems(salesArea);

            (List <SpotBookingRule> spotBookingRulesToDelete,
             List <SpotBookingRuleSalesArea> spotBookingRuleSalesAreasToDelete) = GatherSpotBookingRules(salesArea);

            var spotsToDelete = GatherSpots(salesArea);

            var totalRatingsToDelete = GatherTotalRatings(salesArea);

            var transaction = _dbContext.Specific.Database.BeginTransaction();

            try
            {
                _dbContext.BulkInsertEngine.BulkDelete(breaksToDelete);
                _dbContext.BulkInsertEngine.BulkDelete(clashDiffsToDelete);
                _dbContext.BulkInsertEngine.BulkDelete(restrictionsToDelete);
                _dbContext.BulkInsertEngine.BulkDelete(restrictionSalesAreasToDelete);
                _dbContext.BulkInsertEngine.BulkDelete(inventoryLocksToDelete);
                _dbContext.BulkInsertEngine.BulkDelete(librarySalesAreaPassPrioritiesToDelete);
                _dbContext.BulkInsertEngine.BulkDelete(isrSettingsToDelete);
                _dbContext.BulkInsertEngine.BulkDelete(rsSettingsToDelete);
                _dbContext.BulkInsertEngine.BulkDelete(breakExclusionsToDelete);
                _dbContext.BulkInsertEngine.BulkDelete(passSalesAreaPrioritiesToDelete);
                _dbContext.RemoveRange(passRatingPointsToDelete.ToArray());
                _dbContext.BulkInsertEngine.BulkDelete(ratingsPredictionSchedulesToDelete);
                _dbContext.BulkInsertEngine.BulkDelete(runSalesAreaPrioritiesToDelete);
                _dbContext.BulkInsertEngine.BulkDelete(programmesToDelete);
                _dbContext.BulkInsertEngine.BulkDelete(salesAreaDemographicsToDelete);
                _dbContext.BulkInsertEngine.BulkDelete(schedulesToDelete);
                _dbContext.BulkInsertEngine.BulkDelete(universesToDelete);
                _dbContext.BulkInsertEngine.BulkDelete(sponsorshipItemsToDelete);
                _dbContext.BulkInsertEngine.BulkDelete(spotBookingRulesToDelete);
                _dbContext.BulkInsertEngine.BulkDelete(spotBookingRuleSalesAreasToDelete);
                _dbContext.BulkInsertEngine.BulkDelete(spotsToDelete);
                _dbContext.BulkInsertEngine.BulkDelete(totalRatingsToDelete);

                _dbContext.BulkInsertEngine.BulkUpdate(passRatingPointsToUpdate);
                _dbContext.BulkInsertEngine.BulkUpdate(sponsorshipItemsToUpdate);

                _dbContext.Remove(salesArea);

                _dbContext.SaveChanges();

                transaction.Commit();
            }
            catch
            {
                transaction.Rollback();
                throw;
            }
            finally
            {
                transaction.Dispose();
            }
        }