public void AddOrUpdate(IAutoBookDefaultParameters autoBookDefaultParameters)
        {
            var entity = _dbContext.Query <AutoBookDefaultParametersEntity>()
                         .Include(e => e.AgBreak_AgAvals)
                         .Include(e => e.AgBreak_AgPredictions)
                         .Include(e => e.AgBreak_AgRegionalBreaks)
                         .Include(e => e.AgCampaign_AgCampaignSalesAreas).ThenInclude(e => e.AgDayParts).ThenInclude(e => e.AgDayPartLengths)
                         .Include(e => e.AgCampaign_AgCampaignSalesAreas).ThenInclude(e => e.AgDayParts).ThenInclude(e => e.AgTimeSlices)
                         .Include(e => e.AgCampaign_AgCampaignSalesAreas).ThenInclude(e => e.AgLengths).ThenInclude(e => e.AgMultiParts)
                         .Include(e => e.AgCampaign_AgCampaignSalesAreas).ThenInclude(e => e.AgParts)
                         .Include(e => e.AgCampaign_AgCampaignSalesAreas).ThenInclude(e => e.AgPartsLengths)
                         .Include(e => e.AgCampaign_AgCampaignSalesAreas).ThenInclude(e => e.AgStrikeWeights).ThenInclude(e => e.AgStrikeWeightLengths)
                         .Include(e => e.AgCampaign_AgProgrammeList).ThenInclude(e => e.CategoryOrProgramme)
                         .Include(e => e.AgCampaign_AgProgrammeList).ThenInclude(e => e.TimeBands)
                         .Include(e => e.AgHfssDemos)
                         .FirstOrDefault();

            if (entity == null)
            {
                entity = _mapper.Map <AutoBookDefaultParametersEntity>(autoBookDefaultParameters);

                _dbContext.Add(entity, post => post.MapTo(autoBookDefaultParameters), _mapper);
            }
            else
            {
                _mapper.Map(autoBookDefaultParameters, entity);

                _dbContext.Update(entity, post => post.MapTo(autoBookDefaultParameters), _mapper);
            }

            _cachedModel = autoBookDefaultParameters;
        }
Example #2
0
        public void Add(Schedule item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            var isNew = true;

            if (item.Id > 0)
            {
                var entity = GetEntityById(item.Id);
                if (entity != null)
                {
                    _ = _mapper.Map(item, entity, opts => opts.UseEntityCache(_salesAreaByNameCache));
                    UpdateScheduleBreaks(item, entity);
                    UpdateScheduleProgrammes(item, entity);
                    _ = _dbContext.Update(entity,
                                          post => post.MapTo(item, opts => opts.UseEntityCache(_salesAreaByIdCache)), _mapper);
                    isNew = false;
                }
            }

            if (isNew)
            {
                var entity = _mapper.Map <ScheduleEntity>(item, opts => opts.UseEntityCache(_salesAreaByNameCache));
                UpdateScheduleBreaks(item, entity, true);
                UpdateScheduleProgrammes(item, entity, true);
                _ = _dbContext.Add(entity, post => post.MapTo(item, opts => opts.UseEntityCache(_salesAreaByIdCache)),
                                   _mapper);
            }
        }
Example #3
0
        /// <summary>
        /// Add or Update method
        /// </summary>
        /// <param name="rsSettings"></param>
        public void Update(RSSettings rsSettings)
        {
            if (rsSettings == null)
            {
                throw new ArgumentNullException(nameof(rsSettings));
            }

            var entity = RSSettingsQuery
                         .FirstOrDefault(x => x.Id == rsSettings.Id);

            if (entity == null)
            {
                _ = _dbContext.Add(
                    _mapper.Map <RSSettingsEntity>(rsSettings,
                                                   opts => opts.UseEntityCache(_salesAreaByNameCache)),
                    post => post.MapTo(
                        rsSettings,
                        opts => opts.UseEntityCache(_salesAreaByIdCache)),
                    _mapper);
            }
            else
            {
                _ = _mapper.Map(rsSettings, entity, opts => opts.UseEntityCache(_salesAreaByNameCache));
                _ = _dbContext.Update(entity, post => post.MapTo(rsSettings, opts => opts.UseEntityCache(_salesAreaByIdCache)), _mapper);
            }
        }
Example #4
0
 public void Add(AutoBookTaskReport item)
 {
     if (item != null)
     {
         _dbContext.Add(_mapper.Map <SqlAutoBookTaskReports.AutoBookTaskReport>(item));
     }
 }
        public void Insert(Guid scenarioId, string fileId, Stream stream, bool compress)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            byte[] content;
            if (compress)
            {
                using (var compressedStream = CompressGzip(stream))
                {
                    content = StreamToByteArray(compressedStream);
                }
            }
            else
            {
                content = StreamToByteArray(stream);
            }

            _dbContext.Add(new ResultsFile
            {
                ScenarioId   = scenarioId,
                FileId       = fileId,
                IsCompressed = compress,
                FileContent  = content
            });
        }
 public void Add(PipelineAuditEvent item)
 {
     if (item != null)
     {
         _dbContext.Add(_mapper.Map <SqlPipelineEvents.PipelineAuditEvent>(item));
     }
 }
Example #7
0
        public void Add(RunType runType)
        {
            if (runType is null)
            {
                throw new ArgumentNullException(nameof(runType));
            }

            _dbContext.Add(_mapper.Map <RunTypeEntity>(runType), post => post.MapTo(runType), _mapper);
        }
Example #8
0
        public void Add(Sponsorship sponsorship)
        {
            var entity =
                _mapper.Map <SponsorshipEntity>(sponsorship, opts => opts.UseEntityCache(_salesAreaByNameCache));

            _ = _dbContext.Add(entity,
                               post =>
                               post.MapTo(sponsorship,
                                          opts => opts.UseEntityCache(_salesAreaByIdCache)), _mapper);
        }
Example #9
0
 public void Add(Pass pass)
 {
     _ = _dbContext.Add(
         _mapper.Map <PassEntity>(
             pass,
             opt => opt.UseEntityCache(_salesAreaByNameCache)),
         post => post.MapTo(
             pass,
             opt => opt.UseEntityCache(_salesAreaByIdCache)),
         _mapper);
 }
Example #10
0
        public void Add(Scenario scenario)
        {
            var entity = _mapper.Map <ScenarioEntity>(scenario);

            ApplyPassesOrder(entity.PassReferences);

            _dbContext.Add(
                entity,
                post => post.MapTo(scenario),
                _mapper);
        }
Example #11
0
        public void Add(Channel channel)
        {
            var entity = _dbContext.Find <Entities.Tenant.Channel>(channel.Id);

            if (entity == null)
            {
                _dbContext.Add(_mapper.Map <Entities.Tenant.Channel>(channel), post => post.MapTo(channel), _mapper);
            }
            else
            {
                _mapper.Map(channel, entity);
                _dbContext.Update(entity, post => post.MapTo(channel), _mapper);
            }
        }
Example #12
0
        public void Add(ClearanceCode item)
        {
            var entity = _dbContext.Find <Entities.Tenant.ClearanceCode>(
                (item ?? throw new ArgumentNullException(nameof(item))).Id);

            if (entity == null)
            {
                _dbContext.Add(_mapper.Map <Entities.Tenant.ClearanceCode>(item), post => post.MapTo(item), _mapper);
            }
            else
            {
                _mapper.Map(item, entity);
                _dbContext.Update(entity, post => post.MapTo(item), _mapper);
            }
        }
Example #13
0
        public void Add(Run run)
        {
            var entity = _mapper.Map <Entities.Tenant.Runs.Run>(
                run,
                opt => opt.UseEntityCache(_salesAreaByNameCache));

            ApplyScenariosOrder(entity.Scenarios);

            _ = _dbContext.Add(
                entity,
                post =>
                post.MapTo(
                    run,
                    opt => opt.UseEntityCache(_salesAreaByIdCache)),
                _mapper);
        }
        public void Add(ScenarioResult scenarioResult)
        {
            var entity = GetQueryWithAllIncludes()
                         .FirstOrDefault(x => x.ScenarioId == scenarioResult.Id);

            if (entity == null)
            {
                _dbContext.Add(_mapper.Map <ScenarioResultEntity>(scenarioResult),
                               post => post.MapTo(scenarioResult), _mapper);
            }
            else
            {
                _mapper.Map(scenarioResult, entity);
                _dbContext.Update(entity, post => post.MapTo(scenarioResult), _mapper);
            }
        }
Example #15
0
        public void AddOrUpdate(AutoBookSettings autoBookSettings)
        {
            var currentEntity = GetEntity();

            if (currentEntity == null)
            {
                currentEntity = _mapper.Map <Entities.Tenant.AutoBookApi.AutoBookSettings>(autoBookSettings);
                _dbContext.Add(currentEntity, post => post.MapTo(autoBookSettings), _mapper);
            }
            else
            {
                _mapper.Map(autoBookSettings, currentEntity);
                _dbContext.Update(currentEntity, post => post.MapTo(autoBookSettings), _mapper);
            }

            _cachedAutoBookSettings = currentEntity;
        }
Example #16
0
        public void Add(Clash item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            var entity = ClashQuery()
                         .FirstOrDefault(x => x.Uid == item.Uid);

            if (entity == null)
            {
                _ = _dbContext.Add(_mapper.Map <Entities.Tenant.Clash>(item, opts => opts.UseEntityCache(_salesAreaByNameCache)),
                                   post => post.MapTo(item, opts => opts.UseEntityCache(_salesAreaByIdCache)), _mapper);
            }
            else
            {
                _ = _mapper.Map(item, entity, opts => opts.UseEntityCache(_salesAreaByNameCache));
                _ = _dbContext.Update(entity, post => post.MapTo(item, opts => opts.UseEntityCache(_salesAreaByIdCache)), _mapper);
            }
        }
Example #17
0
        public void Insert(OutputFile outputFile)
        {
            if (outputFile == null)
            {
                throw new ArgumentNullException(nameof(outputFile));
            }

            var entity = _dbContext.Query <Entities.Tenant.OutputFiles.OutputFile>().Include(x => x.Columns)
                         .FirstOrDefault(x => x.FileId == outputFile.FileId);

            if (entity == null)
            {
                _dbContext.Add(_mapper.Map <Entities.Tenant.OutputFiles.OutputFile>(outputFile),
                               post => post.MapTo(outputFile), _mapper);
            }
            else
            {
                _mapper.Map(outputFile, entity);
                _dbContext.Update(entity, post => post.MapTo(outputFile), _mapper);
            }
        }
        public void AddOrUpdate(TenantSettings tenantSettings)
        {
            var currentEntity = _dbContext.Query <TenantSettingsEntity>()
                                .Include(x => x.RunEventSettings)
                                .Include(x => x.Features)
                                .Include(x => x.WebhookSettings)
                                .FirstOrDefault();

            if (currentEntity == null)
            {
                _dbContext.Add(_mapper.Map <TenantSettingsEntity>(tenantSettings),
                               post => post.MapTo(tenantSettings), _mapper);
            }
            else
            {
                _mapper.Map(tenantSettings, currentEntity);
                _dbContext.Update(currentEntity, post => post.MapTo(tenantSettings), _mapper);
            }

            _cachedTenantSettings = tenantSettings;
        }
Example #19
0
        public void Add(Break @break)
        {
            if (string.IsNullOrWhiteSpace(@break.ExternalBreakRef))
            {
                throw new RepositoryException("Unable to create a break without an ExternalBreakRef.");
            }

            var breakEntity = _dbContext.Query <BreakEntity>()
                              .FirstOrDefault(b => b.ExternalBreakRef == @break.ExternalBreakRef);

            if (breakEntity is null)
            {
                breakEntity = _mapper.Map <BreakEntity>(@break, opts => opts.UseEntityCache(_salesAreaByNameCache));
                _           = _dbContext.Add(breakEntity,
                                             post => post.MapTo(@break, opts => opts.UseEntityCache(_salesAreaByIdCache)), _mapper);
            }
            else
            {
                @break.Id = breakEntity.Id;
                _         = _mapper.Map(@break, breakEntity, opts => opts.UseEntityCache(_salesAreaByNameCache));
                _         = _dbContext.Update(breakEntity,
                                              post => post.MapTo(@break, opts => opts.UseEntityCache(_salesAreaByIdCache)), _mapper);
            }
        }
Example #20
0
 public void Add(Domain.Shared.SalesAreas.SalesArea salesArea)
 {
     salesArea.CustomId = _identityGenerator.GetIdentities <SalesAreaNoIdentity>(1).First().Id;
     _dbContext.Add(_mapper.Map <Entities.Tenant.SalesAreas.SalesArea>(salesArea),
                    post => post.MapTo(salesArea), _mapper);
 }
Example #21
0
 public void Add(AutopilotRule item) => _dbContext.Add(_mapper.Map <Entities.Tenant.AutopilotRule>(item), post => post.MapTo(item), _mapper);
Example #22
0
 public KPIPriority Add(KPIPriority model)
 {
     _ = _dbContext.Add(_mapper.Map <KPIPriorityEntity>(model), post => post.MapTo(model), _mapper);
     return(model);
 }
Example #23
0
 public void Add(BookingPositionGroup bookingPositionGroup) =>
 _dbContext.Add(_mapper.Map <BookingPositionGroupEntity>(bookingPositionGroup),
                post => post.MapTo(bookingPositionGroup), _mapper);
Example #24
0
        public void Add(Programme item)
        {
            if (item is null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            var programmeDictionary = _programmeDictionaryCache.Get(item.ExternalReference);

            if (programmeDictionary is null)
            {
                programmeDictionary = _mapper.Map <Entities.Tenant.ProgrammeDictionary>(item);
                _programmeDictionaryCache.Add(programmeDictionary);
            }
            else
            {
                programmeDictionary.Name           = item.ProgrammeName;
                programmeDictionary.Description    = item.Description;
                programmeDictionary.Classification = item.Classification;
            }

            var programme =
                _mapper.Map <Entities.Tenant.Programmes.Programme>(item,
                                                                   opts => opts.UseEntityCache(_salesAreaByNameCache));

            if (programme.Id == Guid.Empty)
            {
                programme.Id = Guid.NewGuid();
            }

            _ = _dbContext.Add(programme, post => post.MapTo(item, opts => opts.UseEntityCache(_salesAreaByIdCache)),
                               _mapper);

            programme.ProgrammeDictionary = programmeDictionary;

            foreach (var cat in item.ProgrammeCategories ?? Enumerable.Empty <string>())
            {
                var category = _programmeCategoryCache.GetOrAdd(cat, key => new ProgrammeCategory {
                    Name = key
                });

                if (programme.ProgrammeCategoryLinks.All(x => !string.Equals(x.ProgrammeCategory.Name, category.Name)))
                {
                    programme.ProgrammeCategoryLinks.Add(new ProgrammeCategoryLink
                    {
                        ProgrammeCategory = category,
                        Programme         = programme
                    });
                }
            }

            if (!(item.Episode is null))
            {
                var episode = programmeDictionary.ProgrammeEpisodes.FirstOrDefault(x => x.Number == item.Episode.Number);

                if (episode is null)
                {
                    episode = new ProgrammeEpisode
                    {
                        Name   = item.Episode.Name,
                        Number = item.Episode.Number,
                    };
                    programmeDictionary.ProgrammeEpisodes.Add(episode);
                }
                else
                {
                    episode.Name = item.Episode.Name;
                }

                programme.Episode = episode;
            }
        }
Example #25
0
 public void Add(Facility facility) => _dbContext.Add(_mapper.Map <FacilityEntity>(facility), post => post.MapTo(facility), _mapper);
Example #26
0
 public void Add(FlexibilityLevel item) => _dbContext.Add(_mapper.Map <Entities.Tenant.FlexibilityLevel>(item),
                                                          post => post.MapTo(item), _mapper);
Example #27
0
 public void Add(CampaignSettings item) =>
 _dbContext.Add(_mapper.Map <CampaignSettingsEntity>(item));
Example #28
0
 public void Add(RuleType item) => _dbContext.Add(_mapper.Map <Entities.Tenant.RuleType>(item),
                                                  post => post.MapTo(item), _mapper);
Example #29
0
 public BusinessType Add(BusinessType model)
 {
     _ = _dbContext.Add(_mapper.Map <BusinessTypeEntity>(model), post => post.MapTo(model), _mapper);
     return(model);
 }
Example #30
0
 public void Add(SmoothConfiguration smoothConfiguration) =>
 _dbContext.Add(_mapper.Map <SmoothConfigurationEntity>(smoothConfiguration, opts => opts.UseEntityCache(_salesAreaByNameCache)),
                post => post.MapTo(smoothConfiguration, opts => opts.UseEntityCache(_salesAreaByIdCache)), _mapper);