Conflict resolved in Questions, Surveys
This commit is contained in:
parent
fe1614fee3
commit
099055d088
@ -4,18 +4,10 @@ namespace DamageAssesment.Api.Employees.Models
|
||||
{
|
||||
public class Employee
|
||||
{
|
||||
[Key]
|
||||
public string Id { get; set; }
|
||||
|
||||
[StringLength(50)]
|
||||
public string Name { get; set; }
|
||||
|
||||
public DateTime BirthDate { get; set; }
|
||||
|
||||
[StringLength(50)]
|
||||
public string OfficePhoneNumber { get; set; }
|
||||
|
||||
[StringLength(50)]
|
||||
public string Email { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
public string? PreferredLanguage { get; set; } = "en";
|
||||
|
@ -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
|
||||
|
@ -2,13 +2,25 @@
|
||||
|
||||
namespace DamageAssesment.Api.Surveys.Db
|
||||
{
|
||||
public class SurveysDbContext:DbContext
|
||||
public class SurveysDbContext : DbContext
|
||||
{
|
||||
public DbSet<Db.Survey> Surveys { get; set; }
|
||||
public DbSet<Db.SurveyTranslation> SurveysTranslation { get; set; }
|
||||
public SurveysDbContext(DbContextOptions options) : base(options)
|
||||
{
|
||||
|
||||
}
|
||||
public DbSet<Db.Survey> Surveys { get; set; }
|
||||
public DbSet<Db.SurveyTranslation> SurveysTranslation { get; set; }
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.Entity<Survey>()
|
||||
.Property(item => item.Id)
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
modelBuilder.Entity<SurveyTranslation>()
|
||||
.Property(item => item.Id)
|
||||
.ValueGeneratedOnAdd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,6 @@ namespace DamageAssesment.Api.Surveys.Providers
|
||||
|
||||
if (surveys != null)
|
||||
{
|
||||
|
||||
if (string.IsNullOrEmpty(Language))
|
||||
{
|
||||
surveysList = from s in surveys
|
||||
@ -184,17 +183,20 @@ namespace DamageAssesment.Api.Surveys.Providers
|
||||
{
|
||||
var surveys = await surveyDbContext.Surveys.ToListAsync();
|
||||
|
||||
int Id = surveys.Count + 1;
|
||||
surveyDbContext.Surveys.Add(new Db.Survey { Id = Id, IsEnabled = survey.IsEnabled, StartDate = survey.StartDate, EndDate = survey.EndDate, CreatedDate = DateTime.Now });
|
||||
var surveyTranslations = await surveyDbContext.SurveysTranslation.ToListAsync();
|
||||
int count = surveyTranslations.Count;
|
||||
Db.Survey _survey = new Db.Survey { IsEnabled = survey.IsEnabled, StartDate = survey.StartDate, EndDate = survey.EndDate, CreatedDate = DateTime.Now };
|
||||
|
||||
surveyDbContext.Surveys.Add(_survey);
|
||||
await surveyDbContext.SaveChangesAsync();
|
||||
|
||||
//var surveyTranslations = await surveyDbContext.SurveysTranslation.ToListAsync();
|
||||
|
||||
foreach (var title in survey.Titles)
|
||||
{
|
||||
count++;
|
||||
surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { Id = count, SurveyId = Id, Language = title.Language, Title = title.Title });
|
||||
surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation {SurveyId = _survey.Id, Language = title.Language, Title = title.Title });
|
||||
}
|
||||
await surveyDbContext.SaveChangesAsync();
|
||||
return (true, survey, "Successful");
|
||||
survey.Id = _survey.Id;
|
||||
return (true,survey, "Successful");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user