public IHttpActionResult GetByExternalRef([FromUri] string externalRef) { if (!ModelState.IsValid || string.IsNullOrEmpty(externalRef)) { return(this.Error().InvalidParameters()); } var d = _demographicRepository.GetByExternalRef(externalRef); if (d == null) { return(NotFound()); } return(Ok(_mapper.Map <DemographicModel>(d))); }
public static void ValidateDemographics(this IDemographicRepository repository, IReadOnlyCollection <string> demographics) { if (repository is null) { throw new ArgumentNullException(nameof(repository)); } if (repository.GetByExternalRef(demographics?.Where(d => !string.IsNullOrEmpty(d)).ToList()).Distinct().Count() != demographics?.Where(d => !string.IsNullOrEmpty(d)).Distinct().Count()) { throw new DataSyncException(DataSyncErrorCode.DemographicNotFound, "Demographic doesn't exist"); } }
public static Demographic CheckDemographicByExternalRef(this IDemographicRepository repository, string externalRef) { if (repository is null) { throw new ArgumentNullException(nameof(repository)); } var demographic = repository.GetByExternalRef(externalRef); if (demographic == null) { throw new DataSyncException(DataSyncErrorCode.ExternalReferenceNotFound, $"Demographic can't be found for ExternalRef: {externalRef}"); } return(demographic); }
protected override void PrepareRelatedCampaignData(IReadOnlyCollection <Campaign> campaigns) { var productRefs = new HashSet <string>(); var demographicRefs = new HashSet <string>(); foreach (var campaign in campaigns) { productRefs.Add(campaign.Product); demographicRefs.Add(campaign.DemoGraphic); } _products = _productRepository .FindByExternal(productRefs.ToList()) .ToDictionary(r => r.Externalidentifier); _demographics = _demographicRepository .GetByExternalRef(demographicRefs.ToList()) .ToDictionary(r => r.ExternalRef); _clashes = _clashRepository.GetAll() .ToDictionary(r => r.Externalref); }
/// <summary> /// Handles the command recieved with Masstransit /// </summary> /// <param name="command">this is bulk model of demographics that need to be updated in database</param> public override void Handle(IBulkDemographicCreatedOrUpdated command) { var demographicEntities = _mapper.Map<List<Demographic>>(command.Data); var existedDemographics = _demographicsRepository.GetByExternalRef(command.Data.Select(c => c.ExternalRef).ToList()); var demographics = new List<Demographic>(); foreach (var demographic in demographicEntities) { var demographicToUpdate = existedDemographics.FirstOrDefault(c => c.ExternalRef == demographic.ExternalRef); if (demographicToUpdate == null) { demographics.Add(demographic); } else { demographicToUpdate.Update(demographic.Name, demographic.ShortName, demographic.DisplayOrder, demographic.Gameplan); demographics.Add(demographicToUpdate); } } _demographicsRepository.InsertOrUpdate(demographics); _demographicsRepository.SaveChanges(); }