public async Task <CartReport> GetReport(ReportGetOptions options)
        {
            try
            {
                StringBuilder sql = new StringBuilder();

                _logger.LogInformation("Try to create get cart report sql query");

                sql.AppendLine($@"
                    select 
                        coalesce(sum({"\"Price\""} * {"\"Count\""}), 0) as Summary
                    from {"\"Cart\""}
                    where OrderId is null
                ");

                if (options.DateFrom.HasValue)
                {
                    sql.AppendLine($"and ({"\"DateCreated\""} >= @DateFrom)");
                }
                if (options.DateTo.HasValue)
                {
                    sql.AppendLine($"and ({"\"DateCreated\""} <= @DateTo)");
                }
                _logger.LogInformation($"Sql query successfully created:\n{sql.ToString()}");

                _logger.LogInformation("Try to execute sql get cart report query");
                var result = await QueryFirstOrDefaultAsync <CartReport>(sql.ToString(), options);

                _logger.LogInformation("Sql get cart report query successfully executed");
                return(result);
            }
            catch (Exception exception)
            {
                _logger.LogError(exception.Message);
                throw exception;
            }
        }
Ejemplo n.º 2
0
 public Task <CartReport> GetCartReport(ReportGetOptions options)
 {
     return(_cartReportdao.GetReport(options));
 }