Group by issue in responses

This commit is contained in:
Vijay Uppu 2024-01-22 12:23:51 -05:00
parent 09fcae68a4
commit 59f547d49d

View File

@ -82,7 +82,7 @@ namespace DamageAssesment.Api.Responses.Providers
} }
listSurveyResponse = listSurveyResponse listSurveyResponse = listSurveyResponse
.OrderByDescending(obj => obj.Id) .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 .Select(group => group.FirstOrDefault()) // or .FirstOrDefault() if you want to handle empty groups
.ToList(); .ToList();
if (listSurveyResponse.Any()) 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(); surveyResonses = await surveyResponseDbContext.SurveyResponses.Where(x => x.SurveyId == surveyId && x.EmployeeId == employeeid).ToListAsync();
employee = await employeeServiceProvider.getEmployeeAsync(employeeid, token); 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 answers = await answerServiceProvider.getAnswersAsync(token);
var questions = await questionServiceProvider.getQuestionsAsync(null, token); var questions = await questionServiceProvider.getQuestionsAsync(null, token);
var surveyQuestions = from q in questions where q.SurveyId == surveyId select q; 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 }; _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 answers = await answerServiceProvider.getAnswersAsync(token);
var questions = await questionServiceProvider.getQuestionsAsync(null, token); var questions = await questionServiceProvider.getQuestionsAsync(null, token);
var surveyQuestions = from q in questions where q.SurveyId == surveyId select q; 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 }; _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 surveyResponses = await surveyResponseDbContext.Responses.Where(x => x.SurveyId == survey.Id).ToListAsync();
// var employees = await employeeServiceProvider.getEmployeesAsync(); // var employees = await employeeServiceProvider.getEmployeesAsync();
var answers = await answerServiceProvider.getAnswersAsync(token); var answers = await answerServiceProvider.getAnswersAsync(token);