コード例 #1
0
        public static void ValidateProgrammes(this IProgrammeRepository repository, IReadOnlyCollection <string> externalRefs)
        {
            if (repository is null)
            {
                throw new ArgumentNullException(nameof(repository));
            }

            var sanitizedExternalRefs = externalRefs.ToList().Distinct(StringComparer.CurrentCultureIgnoreCase).Trim().ToList();
            var existingProgrammes    = repository.FindByExternal(sanitizedExternalRefs);
            var invalidExternalRefs   = sanitizedExternalRefs.Except(existingProgrammes.Select(s => s.ExternalReference), StringComparer.CurrentCultureIgnoreCase).ToList();

            if (invalidExternalRefs.Any())
            {
                throw new DataSyncException(DataSyncErrorCode.ExternalReferenceNotFound, "Invalid Programme: " + string.Join(",", invalidExternalRefs.ToList()));
            }
        }
コード例 #2
0
ファイル: CampaignsController.cs プロジェクト: Morebis-GIT/CI
        private void FillProgrammeNames(CampaignModel campaign)
        {
            var programmeRestrictionViewModels = campaign.ProgrammeRestrictions
                                                 .Where(pr => pr.IsCategoryOrProgramme == "P" && pr.CategoryOrProgrammeName is null);

            var categoryOrProgrammes = programmeRestrictionViewModels.SelectMany(x => x.CategoryOrProgramme)
                                       .Distinct()
                                       .ToList();

            var programmes = _programmeRepository.FindByExternal(categoryOrProgrammes);

            foreach (var programmeRestriction in programmeRestrictionViewModels)
            {
                var categoryOrProgramme = programmeRestriction.CategoryOrProgramme;

                programmeRestriction.CategoryOrProgrammeName = categoryOrProgramme.Select(cop =>
                {
                    var programme = programmes.FirstOrDefault(p => p.ExternalReference == cop);
                    return(programme != null ? programme.ProgrammeName : cop);
                }).ToList();
            }
        }