diff --git a/EstateReportingAPI.BusinessLogic/ReportingManager.cs b/EstateReportingAPI.BusinessLogic/ReportingManager.cs index 173af30..84ee446 100644 --- a/EstateReportingAPI.BusinessLogic/ReportingManager.cs +++ b/EstateReportingAPI.BusinessLogic/ReportingManager.cs @@ -368,8 +368,8 @@ public async Task> GetTodaysFailedSales(TransactionQueries.T using ResolvedDbContext? resolvedContext = this.Resolver.Resolve(EstateManagementDatabaseName, request.EstateId.ToString()); await using EstateManagementContext context = resolvedContext.Context; - var todaysSalesQuery = (from t in context.TodayTransactions where t.IsAuthorised == false && t.TransactionType == "Sale" && t.ResponseCode == request.ResponseCode select t.TransactionAmount); - var comparisonSalesQuery = (from t in context.TransactionHistory where t.IsAuthorised == false && t.TransactionType == "Sale" && t.TransactionDate == request.ComparisonDate && t.TransactionTime <= DateTime.Now.TimeOfDay && t.ResponseCode == request.ResponseCode select t.TransactionAmount); + IQueryable todaysSalesQuery = this.BuildTodaysFailedSalesQuery(context, request.ResponseCode); + IQueryable comparisonSalesQuery = this.BuildComparisonFailedSalesQuery(context, request.ComparisonDate, request.ResponseCode); var todaysSalesQueryResult = await ExecuteQuerySafeToList(todaysSalesQuery, cancellationToken, "Error retrieving todays failed sales"); if (todaysSalesQueryResult.IsFailed) @@ -1357,15 +1357,30 @@ private IQueryable BuildTodaySalesQuery(EstateManagementContex return from t in context.TodayTransactions where t.IsAuthorised && t.TransactionType == "Sale" && t.TransactionDate == DateTime.Now.Date && t.TransactionTime <= DateTime.Now.TimeOfDay select t; } + private IQueryable BuildTodaysFailedSalesQuery(EstateManagementContext context, + String responseCode) { + return from t in context.TodayTransactions + where t.IsAuthorised == false && t.TransactionType == "Sale" && t.ResponseCode == responseCode + select t.TransactionAmount; + } + private IQueryable BuildComparisonSalesQuery(EstateManagementContext context, - DateTime comparisonDate) { + DateTime comparisonDate) { return from t in context.TransactionHistory where t.IsAuthorised && t.TransactionType == "Sale" && t.TransactionDate == comparisonDate && t.TransactionTime <= DateTime.Now.TimeOfDay select t; } + private IQueryable BuildComparisonFailedSalesQuery(EstateManagementContext context, + DateTime comparisonDate, + String responseCode) { + return from t in context.TransactionHistory + where t.IsAuthorised == false && t.TransactionType == "Sale" && t.TransactionDate == comparisonDate && t.TransactionTime <= DateTime.Now.TimeOfDay && t.ResponseCode == responseCode + select t.TransactionAmount; + } + private static async Task>> LoadProductsAsync(EstateManagementContext context, - List contractIds, - CancellationToken cancellationToken, - string stepName) { + List contractIds, + CancellationToken cancellationToken, + string stepName) { var query = context.ContractProducts.Where(cp => contractIds.Contains(cp.ContractId)).Select(cp => new ContractProductData { ContractProductId = cp.ContractProductId, ContractProductReportingId = cp.ContractProductReportingId,