Merged PR 92: Modified logic to get latest response based on survetid, locationId, ane empl...

Modified logic to get latest response based on survetid, locationId, ane employee id
This commit is contained in:
Uppu, Vijay 2023-12-16 21:00:13 +00:00
commit 2a73324ff7

View File

@ -439,7 +439,6 @@ namespace DamageAssesment.Api.Responses.Providers
var answersList = await answerServiceProvider.getAnswersAsync(token);
if (answersList == null || !answersList.Any())
return null;
//get all the answers for the particular survey
var surveyAnswers = answersList.Join(
surveyResponses,
@ -535,14 +534,14 @@ namespace DamageAssesment.Api.Responses.Providers
surveyResponse.LocationId,
surveyResponse.EmployeeId,
surveyResponse.ClientDevice,
surveyResponse.KeyAnswerResult,
// surveyResponse.KeyAnswerResult,
surveyResponse.Longitute,
surveyResponse.Latitude,
Employee = employee,
answers = from ans in answers
select new
{
ans.QuestionId,
// ans.QuestionId,
ans.Id,
ans.AnswerText,
ans.Comment,
@ -578,6 +577,11 @@ 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.EmployeeId, obj.LocationId })
.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);
@ -594,16 +598,16 @@ namespace DamageAssesment.Api.Responses.Providers
r.LocationId,
r.EmployeeId,
r.ClientDevice,
r.KeyAnswerResult,
// r.KeyAnswerResult,
r.Longitute,
r.Latitude,
Employee = (from e in employees where e.Id == r.EmployeeId select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(),
// Employee = (from e in employees where e.Id == r.EmployeeId select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(),
answers = from ans in answers
where ans.SurveyResponseId == r.Id
select new
{
ans.Id,
ans.QuestionId,
// ans.QuestionId,
ans.AnswerText,
ans.Comment,
Questions = (from q in surveyQuestions where q.Id == ans.QuestionId select new { q.Id, q.QuestionNumber, q.CategoryId, q.Text }).SingleOrDefault(),
@ -646,7 +650,11 @@ namespace DamageAssesment.Api.Responses.Providers
}
}
surveyResonses = surveyResonses
.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();
var answers = await answerServiceProvider.getAnswersAsync(token);
var questions = await questionServiceProvider.getQuestionsAsync(null, token);
var attachments = await attachmentServiceProvider.getAttachmentsAsync(token);
@ -659,16 +667,16 @@ namespace DamageAssesment.Api.Responses.Providers
r.LocationId,
r.EmployeeId,
r.ClientDevice,
r.KeyAnswerResult,
// r.KeyAnswerResult,
r.Longitute,
r.Latitude,
Employee = employeeid != 0 ? _employee : (from e in employees where r.EmployeeId == e.Id select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(),
// Employee = employeeid != 0 ? _employee : (from e in employees where r.EmployeeId == e.Id select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(),
answers = from ans in answers
where ans.SurveyResponseId == r.Id
select new
{
ans.Id,
ans.QuestionId,
// ans.QuestionId,
ans.AnswerText,
ans.Comment,
Questions = (from q in questions where q.Id == ans.QuestionId select new { q.Id, q.QuestionNumber, q.CategoryId, q.Text }).SingleOrDefault(),
@ -907,7 +915,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.EmployeeId, obj.LocationId })
.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;
@ -921,16 +933,16 @@ namespace DamageAssesment.Api.Responses.Providers
r.LocationId,
r.EmployeeId,
r.ClientDevice,
r.KeyAnswerResult,
// r.KeyAnswerResult,
r.Longitute,
r.Latitude,
Employee = (from e in employees where r.EmployeeId == e.Id select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(),
// Employee = (from e in employees where r.EmployeeId == e.Id select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(),
answers = from ans in answers
where ans.SurveyResponseId == r.Id
select new
{
ans.QuestionId,
// ans.QuestionId,
ans.Id,
ans.AnswerText,
ans.Comment,
@ -973,7 +985,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.EmployeeId, obj.LocationId })
.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);
@ -987,10 +1003,10 @@ namespace DamageAssesment.Api.Responses.Providers
r.LocationId,
r.EmployeeId,
r.ClientDevice,
r.KeyAnswerResult,
// r.KeyAnswerResult,
r.Longitute,
r.Latitude,
Employee = (from e in employees where r.EmployeeId == e.Id select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(),
// Employee = (from e in employees where r.EmployeeId == e.Id select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(),
answers = from ans in answers
where ans.SurveyResponseId == r.Id
&& ans.QuestionId == question.Id
@ -998,7 +1014,7 @@ namespace DamageAssesment.Api.Responses.Providers
select new
{
ans.QuestionId,
// ans.QuestionId,
AnswerId = ans.Id,
ans.AnswerText,
ans.Comment,