예제 #1
0
        public async Task <IEnumerable <UserLocation> > Get(UserLocationGetOptions options)
        {
            try
            {
                StringBuilder queryBuilder   = new StringBuilder(apiUrl);
                int           conditionIndex = 0;
                if (!string.IsNullOrEmpty(options.Search))
                {
                    queryBuilder.Append($"{(conditionIndex++ == 0 ? "?" : "&")}search={options.Search}");
                }

                return(await _apiClient.Get <UserLocation, UserLocationGetOptions>(options, queryBuilder.ToString()));
            }
            catch (Exception exception)
            {
                _logger.LogError(exception.Message);
                throw exception;
            }
        }
        public async Task <IEnumerable <UserLocation> > Get(UserLocationGetOptions options)
        {
            try
            {
                StringBuilder sql = new StringBuilder();

                _logger.LogInformation("Try to create get user locations sql query");

                sql.AppendLine(@"
                    select 
                        Id,
                        IPAddress,
                        Location
                    from UserLocation
                ");

                int conditionIndex = 0;
                if (!string.IsNullOrEmpty(options.NormalizedSearch))
                {
                    sql.AppendLine($@"{(conditionIndex++ == 0 ? "where" : "and")} (lower(IPAddress) like lower(@NormalizedSearch)
                    or lower(Location) like lower(@NormalizedSearch)
                    )");
                }
                _logger.LogInformation($"Sql query successfully created:\n{sql.ToString()}");

                _logger.LogInformation("Try to execute sql get user locations query");
                var result = await QueryAsync <UserLocation>(sql.ToString(), options);

                _logger.LogInformation("Sql get user locations query successfully executed");
                return(result);
            }
            catch (Exception exception)
            {
                _logger.LogError(exception.Message);
                throw exception;
            }
        }
예제 #3
0
 public async Task <IEnumerable <UserLocation> > Get(UserLocationGetOptions options) => await _dao.Get(options);
예제 #4
0
 public async Task <IActionResult> Get([FromQuery] UserLocationGetOptions options)
 {
     return(Ok(await _service.Get(options)));
 }