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);