public async Task <IEnumerable <Product> > Get(ProductGetOptions options) { try { StringBuilder sql = new StringBuilder(); _logger.LogInformation("Try to create get products sql query"); sql.AppendLine(@" select Id, Count, Price, Name from Product "); int conditionIndex = 0; if (options.Id.HasValue) { sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} (Id = @id)"); } if (options.Ids != null) { sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} (Id in @ids)"); } if (!string.IsNullOrEmpty(options.NormalizedSearch)) { sql.AppendLine($@" {(conditionIndex++ == 0 ? "where" : "and")} (lower(Name) like lower(@NormalizedSearch)) "); } if (!string.IsNullOrEmpty(options.Name)) { sql.AppendLine($@"{(conditionIndex++ == 0 ? "where" : "and")} (Name = @Name)"); } _logger.LogInformation($"Sql query successfully created:\n{sql.ToString()}"); _logger.LogInformation("Try to execute sql get products query"); var result = await QueryAsync <Product>(sql.ToString(), options); _logger.LogInformation("Sql get products query successfully executed"); return(result); } catch (Exception exception) { _logger.LogError(exception.Message); throw exception; } }
public virtual Task <Product> GetAsync(string productId, ProductGetOptions options = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { return(this.GetEntityAsync(productId, options, requestOptions, cancellationToken)); }
public virtual Product Get(string productId, ProductGetOptions options = null, RequestOptions requestOptions = null) { return(this.GetEntity(productId, options, requestOptions)); }
public async Task <IEnumerable <Product> > Get(ProductGetOptions options) => await _dao.Get(options);
public async Task <IActionResult> Get([FromQuery] ProductGetOptions options) { return(Ok(await _service.Get(options))); }