forked from MDCPS/DamageAssessment_Backend
		
	adding multiple questions for survey id
This commit is contained in:
		| @ -377,6 +377,36 @@ namespace DamageAssesment.Api.Questions.Providers | ||||
|                 return (false, null, ex.Message); | ||||
|             } | ||||
|         } | ||||
|        | ||||
|         public async Task<(bool IsSuccess, IEnumerable<Models.MultiLanguage> Question, string ErrorMessage)> PutQuestionsAsync(int surveyId, List<Models.Question> Questions) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var questions=await questionDbContext.Questions.AsNoTracking().Where(a=>a.SurveyId == surveyId).ToListAsync(); | ||||
|                 if (questions != null) | ||||
|                 { | ||||
|                     List<int> questionids=questions.Select(a=>a.Id).ToList(); | ||||
|                     var questiontrans = await questionDbContext.QuestionsTranslations.AsNoTracking().Where(x => questionids.Contains(x.QuestionId)).ToListAsync(); | ||||
|                     if (questiontrans != null) | ||||
|                         questionDbContext.QuestionsTranslations.RemoveRange(questiontrans); | ||||
|                     questionDbContext.Questions.RemoveRange(questions); | ||||
|                     questionDbContext.SaveChanges(); | ||||
|                 } | ||||
|                 List<Models.MultiLanguage> results = new List<MultiLanguage>(); | ||||
|                 logger?.LogInformation("Query Question"); | ||||
|                 foreach (Models.Question Question in Questions) | ||||
|                 { | ||||
|                     Question.SurveyId = surveyId; | ||||
|                     results.Add(InsertQuestion(Question)); | ||||
|                 } | ||||
|                 return (true, results, null); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger?.LogError(ex.ToString()); | ||||
|                 return (false, null, ex.Message); | ||||
|             } | ||||
|         } | ||||
|         public async Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> UpdateQuestionAsync(Models.Question Question) | ||||
|         { | ||||
|             try | ||||
| @ -410,8 +440,11 @@ namespace DamageAssesment.Api.Questions.Providers | ||||
|  | ||||
|                 if (question != null) | ||||
|                 { | ||||
|                     var questiontrans=await questionDbContext.QuestionsTranslations.AsNoTracking().Where(x=>x.QuestionId== id).ToListAsync(); | ||||
|                     var result = mapper.Map<Db.Question, Models.MultiLanguage>(question); | ||||
|                     result.Text = CreateMultiLanguageObject(GetQuestionsTranslations(result.Id, "")); | ||||
|                     if(questiontrans!=null) | ||||
|                         questionDbContext.QuestionsTranslations.RemoveRange(questiontrans); | ||||
|                     questionDbContext.Questions.Remove(question); | ||||
|                     questionDbContext.SaveChanges(); | ||||
|                     return (true, result, $"QuestionID {id} deleted Successfuly"); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user