From 09fcae68a49acd4c30447d1b0616c9e196b11128 Mon Sep 17 00:00:00 2001 From: Vijay Uppu <913468@dadeschools.net> Date: Thu, 18 Jan 2024 11:45:51 -0500 Subject: [PATCH] fixed region issue --- .../Providers/SurveyResponsesProvider.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/DamageAssesmentApi/DamageAssesment.Api.Responses/Providers/SurveyResponsesProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Responses/Providers/SurveyResponsesProvider.cs index 333fd37..6ac9720 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Responses/Providers/SurveyResponsesProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Responses/Providers/SurveyResponsesProvider.cs @@ -71,16 +71,20 @@ namespace DamageAssesment.Api.Responses.Providers try { logger?.LogInformation("Querying to get SurveyResponse object from DB"); - IQueryable listSurveyResponse = null; + List listSurveyResponse = null; if (employeeid == 0) { - listSurveyResponse = surveyResponseDbContext.SurveyResponses.Where(s => s.SurveyId == surveyId); + listSurveyResponse = surveyResponseDbContext.SurveyResponses.Where(s => s.SurveyId == surveyId).ToList(); } else { - listSurveyResponse = surveyResponseDbContext.SurveyResponses.Where(s => s.SurveyId == surveyId && s.EmployeeId == employeeid); + listSurveyResponse = surveyResponseDbContext.SurveyResponses.Where(s => s.SurveyId == surveyId && s.EmployeeId == employeeid).ToList(); } - + listSurveyResponse = listSurveyResponse + .OrderByDescending(obj => obj.Id) + .GroupBy(obj => new { obj.SurveyId, obj.EmployeeId, obj.LocationId }) + .Select(group => group.FirstOrDefault()) // or .FirstOrDefault() if you want to handle empty groups + .ToList(); if (listSurveyResponse.Any()) { var answers = await getAnswersByRegionAndSurveyIdAsync(listSurveyResponse); @@ -432,7 +436,7 @@ namespace DamageAssesment.Api.Responses.Providers } //Method to get Answers by region with surveyId as input parameter - private async Task getAnswersByRegionAndSurveyIdAsync(IQueryable surveyResponses) + private async Task getAnswersByRegionAndSurveyIdAsync(List surveyResponses) { try {