public async Task <IActionResult> Get([FromQuery] CartGetOptions options) { return(Ok(await _cartService.Get(options))); }
public async Task <IEnumerable <Cart> > Get(CartGetOptions options) { try { StringBuilder sql = new StringBuilder(); _logger.LogInformation("Try to create get carts sql query"); sql.AppendLine($@" select {"\"Id\""}, {"\"OrderId\""}, {"\"ProductId\""}, {"\"Count\""}, {"\"Price\""}, {"\"Name\""} from {"\"Cart\""} "); int conditionIndex = 0; if (options.Id.HasValue) { sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} ({"\"Id\""} = @id)"); } if (options.ProductId.HasValue) { sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} ({"\"ProductId\""} = @ProductId)"); } if (options.OrderId.HasValue) { sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} ({"\"OrderId\""} = @OrderId)"); } if (options.Ordered.HasValue) { sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} ({"\"OrderId\""} is {(options.Ordered.Value ? "not" : string.Empty)} null)"); } if (options.Ids != null) { sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} ({"\"Id\""} = any(@ids))"); } if (options.OrderIds != null) { sql.AppendLine($"{(conditionIndex++ == 0 ? "where" : "and")} ({"\"OrderId\""} = any(@OrderIds))"); } 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 carts query"); var result = await QueryAsync <Cart>(sql.ToString(), options); _logger.LogInformation("Sql get carts query successfully executed"); return(result); } catch (Exception exception) { _logger.LogError(exception.Message); throw exception; } }
public async Task <IEnumerable <Cart> > Get(CartGetOptions options) => await _dao.Get(options);