public async Task DeleteAsync(string regulationRuleId) { IWelcomeRegulationRule regulationRule = await _welcomeRegulationRuleRepository.GetAsync(regulationRuleId); if (regulationRule == null) { throw new ServiceException("Regulation rule not found."); } await _welcomeRegulationRuleRepository.DeleteAsync(regulationRuleId); }
public async Task AddAsync(IWelcomeRegulationRule welcomeRegulationRule) { IRegulation result = await _regulationRepository.GetAsync(welcomeRegulationRule.RegulationId); if (result == null) { throw new ServiceException("Regulation not found."); } await _welcomeRegulationRuleRepository.AddAsync(welcomeRegulationRule); }
private static WelcomeRegulationRuleEntity Create(IWelcomeRegulationRule welcomeRegulationRule) => new WelcomeRegulationRuleEntity { RowKey = GetRowKey(), PartitionKey = GetPartitionKey(), Name = welcomeRegulationRule.Name, Countries = welcomeRegulationRule.Countries, RegulationId = welcomeRegulationRule.RegulationId, Active = welcomeRegulationRule.Active, Priority = welcomeRegulationRule.Priority };
public Task UpdateAsync(IWelcomeRegulationRule welcomeRegulationRule) { return(_tableStorage.MergeAsync(GetPartitionKey(), welcomeRegulationRule.Id, entity => { entity.Name = welcomeRegulationRule.Name; entity.Countries = welcomeRegulationRule.Countries; entity.RegulationId = welcomeRegulationRule.RegulationId; entity.Active = welcomeRegulationRule.Active; entity.Priority = welcomeRegulationRule.Priority; return entity; })); }
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 async Task ChangeRegulationAsync(string clientId, string country) { List <IClientRegulation> clientRegulations = (await _clientRegulationRepository.GetByClientIdAsync(clientId)).ToList(); IWelcomeRegulationRule welcomeRegulationRule = (await _welcomeRegulationRuleRepository.GetByCountryAsync(country)) .OrderByDescending(o => o.Priority) .FirstOrDefault(); if (welcomeRegulationRule == null) { IEnumerable <IWelcomeRegulationRule> welcomeRegulationRules = await _welcomeRegulationRuleRepository.GetDefaultAsync(); welcomeRegulationRule = welcomeRegulationRules .OrderByDescending(o => o.Priority) .FirstOrDefault(); } if (welcomeRegulationRule != null && clientRegulations.All(item => item.RegulationId != welcomeRegulationRule.RegulationId)) { foreach (var regulation in clientRegulations.Where(item => item.Kyc == false)) { await _clientRegulationRepository.DeleteAsync(clientId, regulation.RegulationId); } var newRegulation = new ClientRegulation { ClientId = clientId, RegulationId = welcomeRegulationRule.RegulationId, Active = welcomeRegulationRule.Active, Kyc = false }; await _clientRegulationRepository.AddAsync(newRegulation); await PublishOnChangedAsync(clientId); } }
public Task AddAsync(IWelcomeRegulationRule welcomeRegulationRule) { return(_tableStorage.InsertAsync(Create(welcomeRegulationRule))); }