public async Task SetDefaultAsync(string clientId, string country) { IEnumerable <IClientRegulation> clientRegulations = await _clientRegulationRepository.GetByClientIdAsync(clientId); if (clientRegulations.Any()) { throw new ServiceException("Client already have regulations."); } IWelcomeRegulationRule welcomeRegulationRule = null; if (!string.IsNullOrEmpty(country)) { IEnumerable <IWelcomeRegulationRule> welcomeRegulationRules = await _welcomeRegulationRuleRepository.GetByCountryAsync(country); welcomeRegulationRule = welcomeRegulationRules .OrderByDescending(o => o.Priority) .FirstOrDefault(); } if (welcomeRegulationRule == null) { IEnumerable <IWelcomeRegulationRule> welcomeRegulationRules = await _welcomeRegulationRuleRepository.GetDefaultAsync(); welcomeRegulationRule = welcomeRegulationRules .OrderByDescending(o => o.Priority) .FirstOrDefault(); } if (welcomeRegulationRule == null) { throw new ServiceException("No default regulations."); } var defaultClientRegulation = new ClientRegulation { ClientId = clientId, RegulationId = welcomeRegulationRule.RegulationId, Active = welcomeRegulationRule.Active, Kyc = false }; await _clientRegulationRepository.AddAsync(defaultClientRegulation); await PublishOnChangedAsync(defaultClientRegulation.ClientId); _log.Info(nameof(SetDefaultAsync), $"Default regulation '{defaultClientRegulation.RegulationId}' added for client.", defaultClientRegulation.ClientId); }
public Task <IEnumerable <IWelcomeRegulationRule> > GetByCountryAsync(string country) { return(_welcomeRegulationRuleRepository.GetByCountryAsync(country)); }