adding multiple questions for survey id
This commit is contained in:
parent
4b9ab46901
commit
9188ded00e
@ -109,12 +109,11 @@ namespace DamageAssesment.Api.Questions.Controllers
|
|||||||
}
|
}
|
||||||
return CreatedAtRoute("DefaultApi",questions);
|
return CreatedAtRoute("DefaultApi",questions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// POST request for creating a multiple question (multilingual).
|
/// PUT request for update a multiple question (multilingual) for survey.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HttpPut("questions/multiple/{surveyid}")]
|
[HttpPut("questions/multiple/{surveyid}")]
|
||||||
public async Task<IActionResult> UpdateQuestions(int surveyid, List<Models.Question> questions)
|
public async Task<IActionResult> CreateQuestions(int surveyid, List<Models.Question> questions)
|
||||||
{
|
{
|
||||||
if (questions != null)
|
if (questions != null)
|
||||||
{
|
{
|
||||||
|
@ -9,7 +9,7 @@ namespace DamageAssesment.Api.Questions.Interfaces
|
|||||||
Task<(bool IsSuccess, List<SurveyQuestions> SurveyQuestions, string ErrorMessage)> GetSurveyQuestionAsync(int surveyId,string language);
|
Task<(bool IsSuccess, List<SurveyQuestions> SurveyQuestions, string ErrorMessage)> GetSurveyQuestionAsync(int surveyId,string language);
|
||||||
Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> PostQuestionAsync(Models.Question Question);
|
Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> PostQuestionAsync(Models.Question Question);
|
||||||
Task<(bool IsSuccess, IEnumerable<Models.MultiLanguage> Question, string ErrorMessage)> PostQuestionsAsync(List<Models.Question> Questions);
|
Task<(bool IsSuccess, IEnumerable<Models.MultiLanguage> Question, string ErrorMessage)> PostQuestionsAsync(List<Models.Question> Questions);
|
||||||
Task<(bool IsSuccess, IEnumerable<Models.MultiLanguage> Question, string ErrorMessage)> PutQuestionsAsync(int surveyId, List<Models.Question> Questions);
|
Task<(bool IsSuccess, IEnumerable<Models.MultiLanguage> Question, string ErrorMessage)> PutQuestionsAsync(int surveyId,List<Models.Question> Questions);
|
||||||
Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> UpdateQuestionAsync(Models.Question Question);
|
Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> UpdateQuestionAsync(Models.Question Question);
|
||||||
Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> DeleteQuestionAsync(int id);
|
Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> DeleteQuestionAsync(int id);
|
||||||
|
|
||||||
|
@ -381,10 +381,24 @@ namespace DamageAssesment.Api.Questions.Providers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
questionDbContext.Questions.ToList().RemoveAll(s=> s.SurveyId == surveyId);
|
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();
|
questionDbContext.SaveChanges();
|
||||||
var response = await PostQuestionsAsync(Questions);
|
}
|
||||||
return (response);
|
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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -425,8 +439,11 @@ namespace DamageAssesment.Api.Questions.Providers
|
|||||||
|
|
||||||
if (question != null)
|
if (question != null)
|
||||||
{
|
{
|
||||||
|
var questiontrans=await questionDbContext.QuestionsTranslations.AsNoTracking().Where(x=>x.QuestionId== id).ToListAsync();
|
||||||
var result = mapper.Map<Db.Question, Models.MultiLanguage>(question);
|
var result = mapper.Map<Db.Question, Models.MultiLanguage>(question);
|
||||||
result.Text = CreateMultiLanguageObject(GetQuestionsTranslations(result.Id, ""));
|
result.Text = CreateMultiLanguageObject(GetQuestionsTranslations(result.Id, ""));
|
||||||
|
if(questiontrans!=null)
|
||||||
|
questionDbContext.QuestionsTranslations.RemoveRange(questiontrans);
|
||||||
questionDbContext.Questions.Remove(question);
|
questionDbContext.Questions.Remove(question);
|
||||||
questionDbContext.SaveChanges();
|
questionDbContext.SaveChanges();
|
||||||
return (true, result, $"QuestionID {id} deleted Successfuly");
|
return (true, result, $"QuestionID {id} deleted Successfuly");
|
||||||
|
Loading…
Reference in New Issue
Block a user