public async Task <IActionResult> SetDefault(string clientId, string country) { try { await _clientRegulationService.SetDefaultAsync(clientId, country); } catch (ServiceException exception) { _log.Error(nameof(SetDefault), exception, $"{nameof(clientId)}: {clientId}. {nameof(country)}: {country}. IP: {HttpContext.GetIp()}"); return(BadRequest(ErrorResponse.Create(exception.Message))); } _log.Info(nameof(SetDefault), clientId, $"Default regulations was assigned for client. {nameof(country)}: {country}. IP: {HttpContext.GetIp()}"); return(NoContent()); }
public async Task Handle(ClientRegisteredEvent evt, ICommandSender commandSender) { try { string countryCode = null; if (!string.IsNullOrEmpty(evt.CountryFromPOA)) { _log.Info(nameof(ClientRegisteredEvent), $"Getting country '{evt.CountryFromPOA}' from the message", evt.ClientId); countryCode = evt.CountryFromPOA; } else if (!string.IsNullOrEmpty(evt.Ip)) { _log.Info(nameof(ClientRegisteredEvent), $"Try to get country by IP address '{evt.Ip}'", evt.ClientId); IIpGeolocationData data = await _geoLocationClient.GetAsync(evt.Ip); countryCode = data?.CountryCode; if (string.IsNullOrEmpty(countryCode)) { _log.Warning(nameof(ClientRegisteredEvent), $"Can not find country by IP address '{evt.Ip}'.", context: evt.ClientId); } else { _log.Info(nameof(ClientRegisteredEvent), $"Country '{data.CountryCode}'.", evt.ClientId); } } if (!string.IsNullOrEmpty(countryCode)) { await _clientRegulationService.SetDefaultAsync(evt.ClientId, countryCode); } } catch (ServiceException exception) { _log.Error(nameof(ClientRegisteredEvent), exception, context: evt.ClientId); } }