From 59f547d49d00cddb9ddcedad878a4f8351276a7a Mon Sep 17 00:00:00 2001 From: Vijay Uppu <913468@dadeschools.net> Date: Mon, 22 Jan 2024 12:23:51 -0500 Subject: [PATCH] Group by issue in responses --- .../Providers/SurveyResponsesProvider.cs | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/DamageAssesmentApi/DamageAssesment.Api.Responses/Providers/SurveyResponsesProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Responses/Providers/SurveyResponsesProvider.cs index 6ac9720..a16f7e0 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Responses/Providers/SurveyResponsesProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Responses/Providers/SurveyResponsesProvider.cs @@ -82,7 +82,7 @@ namespace DamageAssesment.Api.Responses.Providers } listSurveyResponse = listSurveyResponse .OrderByDescending(obj => obj.Id) - .GroupBy(obj => new { obj.SurveyId, obj.EmployeeId, obj.LocationId }) + .GroupBy(obj => new { obj.SurveyId, obj.LocationId })//obj.EmployeeId, .Select(group => group.FirstOrDefault()) // or .FirstOrDefault() if you want to handle empty groups .ToList(); if (listSurveyResponse.Any()) @@ -582,7 +582,12 @@ namespace DamageAssesment.Api.Responses.Providers surveyResonses = await surveyResponseDbContext.SurveyResponses.Where(x => x.SurveyId == surveyId && x.EmployeeId == employeeid).ToListAsync(); employee = await employeeServiceProvider.getEmployeeAsync(employeeid, token); } - + surveyResonses = surveyResonses + .OrderByDescending(obj => obj.Id) + .GroupBy(obj => new { obj.SurveyId, obj.LocationId })//obj.EmployeeId, + .Select(group => group.FirstOrDefault()) // or .FirstOrDefault() if you want to handle empty groups + .ToList(); + var answers = await answerServiceProvider.getAnswersAsync(token); var questions = await questionServiceProvider.getQuestionsAsync(null, token); var surveyQuestions = from q in questions where q.SurveyId == surveyId select q; @@ -911,7 +916,11 @@ namespace DamageAssesment.Api.Responses.Providers _employee = new { employee.Id, employee.Name, employee.BirthDate, employee.Email, employee.OfficePhoneNumber }; } } - + surveyResonses = surveyResonses + .OrderByDescending(obj => obj.Id) + .GroupBy(obj => new { obj.SurveyId, obj.LocationId }) //obj.EmployeeId, + .Select(group => group.FirstOrDefault()) // or .FirstOrDefault() if you want to handle empty groups + .ToList(); var answers = await answerServiceProvider.getAnswersAsync(token); var questions = await questionServiceProvider.getQuestionsAsync(null, token); var surveyQuestions = from q in questions where q.SurveyId == surveyId select q; @@ -977,7 +986,11 @@ namespace DamageAssesment.Api.Responses.Providers _employee = new { employee.Id, employee.Name, employee.BirthDate, employee.Email, employee.OfficePhoneNumber }; } } - + surveyResponses = surveyResponses + .OrderByDescending(obj => obj.Id) + .GroupBy(obj => new { obj.SurveyId, obj.LocationId })//, obj.EmployeeId + .Select(group => group.FirstOrDefault()) // or .FirstOrDefault() if you want to handle empty groups + .ToList(); //var surveyResponses = await surveyResponseDbContext.Responses.Where(x => x.SurveyId == survey.Id).ToListAsync(); // var employees = await employeeServiceProvider.getEmployeesAsync(); var answers = await answerServiceProvider.getAnswersAsync(token);