Conflict resolved in Questions, Surveys

This commit is contained in:
Reginald Cherenfant Jasmin
2023-08-25 17:51:07 -04:00
parent fe1614fee3
commit 099055d088
5 changed files with 33 additions and 26 deletions

View File

@ -709,16 +709,16 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
}
async Task<bool> ProcessAnswers(QuestionRequest questionRequest, int surveyResponseId)
bool ProcessAnswers(QuestionRequest questionRequest, int surveyResponseId)
{
if (questionRequest != null)
{
var answer = await answerServiceProvider.PostAnswersAsync(new Answer { Id = 0, QuestionId = questionRequest.QuestionId, AnswerText = questionRequest.AnswerText, Comment = questionRequest.Comment, SurveyResponseId = surveyResponseId });
var answer = answerServiceProvider.PostAnswersAsync(new Answer {QuestionId = questionRequest.QuestionId, AnswerText = questionRequest.AnswerText, Comment = questionRequest.Comment, SurveyResponseId = surveyResponseId });
if (answer != null)
{
List<AnswerInfo> listAnswerInfo = new List<AnswerInfo>();
listAnswerInfo.Add(new AnswerInfo { AnswerId = answer.Id, postedFiles = questionRequest.PostedFiles });
var attachments = await attachmentServiceProvider.PostAttachmentsAsync(new AttachmentInfo { ResponseId = surveyResponseId, Answers = listAnswerInfo });
var attachments = attachmentServiceProvider.PostAttachmentsAsync(new AttachmentInfo { ResponseId = surveyResponseId, Answers = listAnswerInfo });
string message = $"Answer for question {questionRequest.QuestionId} saved to the database";
logger?.LogInformation(message);
@ -757,18 +757,19 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
//var tasks = answers.Answers.Select(x => ProcessAnswers(x,surveyResponse.SurveyResponseID));
foreach (QuestionRequest ans in answers.Answers)
{
ProcessAnswers(ans, surveyResponse.Id);
//var stopwatch = new Stopwatch();
//stopwatch.Start();
var task = Task.Run(() => ProcessAnswers(ans, surveyResponse.Id));
// var task = Task.Run(() => ProcessAnswers(ans, surveyResponse.Id));
//var task = await ProcessAnswers(ans, surveyResponse.Id);
answerTasks.Add(task);
//answerTasks.Add(task);
//stopwatch.Stop();
//answerTasks.Add(ProcessAnswers(ans, surveyResponse.Id));
}
await Task.WhenAll(answerTasks);
//await Task.WhenAll(answerTasks);
return (true, surveyResponse, null);
}
else