fixed multiple question saving issue

This commit is contained in:
Vijay Uppu 2023-11-15 09:06:20 -05:00
parent 2c7d4e6138
commit dbabc10e7c

View File

@ -254,6 +254,7 @@ namespace DamageAssesment.Api.Questions.Providers
var dbquestiontranslation = mapper.Map<List<Models.QuestionsTranslation>, List<Db.QuestionsTranslation>>(Question.Questions); var dbquestiontranslation = mapper.Map<List<Models.QuestionsTranslation>, List<Db.QuestionsTranslation>>(Question.Questions);
dbquestion.QuestionTypeId = questionDbContext.QuestionTypes.Where(a => a.TypeText == Question.TypeText).Select(a => a.Id).FirstOrDefault(); dbquestion.QuestionTypeId = questionDbContext.QuestionTypes.Where(a => a.TypeText == Question.TypeText).Select(a => a.Id).FirstOrDefault();
questionDbContext.Questions.Add(dbquestion); questionDbContext.Questions.Add(dbquestion);
questionDbContext.SaveChanges();
dbquestiontranslation.ForEach(i => i.QuestionId = dbquestion.Id); dbquestiontranslation.ForEach(i => i.QuestionId = dbquestion.Id);
questionDbContext.QuestionsTranslations.AddRange(dbquestiontranslation); questionDbContext.QuestionsTranslations.AddRange(dbquestiontranslation);
questionDbContext.SaveChanges(); questionDbContext.SaveChanges();