From d7005479c5c607dc8bfec0c1b9325f3e42f8ae05 Mon Sep 17 00:00:00 2001 From: Reginald Cherenfant Jasmin Date: Thu, 7 Dec 2023 02:16:00 -0500 Subject: [PATCH] Adding endpoint for mutiple questions update --- .../Program.cs | 4 +--- .../DamageAssesment.Api.Employees/Program.cs | 4 +--- .../DamageAssesment.Api.Locations/Program.cs | 4 +--- .../Controllers/QuestionsController.cs | 22 +++++++++++++++++++ .../Interfaces/IQuestionsProvider.cs | 1 + .../DamageAssesment.Api.Questions/Program.cs | 4 +--- .../Providers/QuestionsProvider.cs | 16 ++++++++++++++ 7 files changed, 43 insertions(+), 12 deletions(-) diff --git a/DamageAssesmentApi/DamageAssesment.Api.Attachments/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Program.cs index ba0f71c..c415f31 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Attachments/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Program.cs @@ -54,11 +54,9 @@ if (app.Environment.IsDevelopment()) app.UseSwagger(); app.UseSwaggerUI(); } -<<<<<<< HEAD -======= // Enable CORS, authentication, and authorization middleware. ->>>>>>> 9ec9b8b96fc7c5767fcddf1e4e52bde203fcf619 + app.UseCors("DamageAppCorsPolicy"); app.UseAuthorization(); app.UseHttpsRedirection(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Employees/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.Employees/Program.cs index 01d561b..b1af271 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Employees/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Employees/Program.cs @@ -50,14 +50,12 @@ if (app.Environment.IsDevelopment()) employeesProvider.SeedData(); } } -<<<<<<< HEAD + app.UseCors("DamageAppCorsPolicy"); -======= // Enable CORS, authentication, and authorization middleware. app.UseCors("DamageAppCorsPolicy"); ->>>>>>> 9ec9b8b96fc7c5767fcddf1e4e52bde203fcf619 app.UseAuthorization(); app.MapControllers(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Locations/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.Locations/Program.cs index d2ef35b..fa92c7b 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Locations/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Locations/Program.cs @@ -51,14 +51,12 @@ if (app.Environment.IsDevelopment()) regionProvider.SeedData(); } } -<<<<<<< HEAD + app.UseCors("DamageAppCorsPolicy"); -======= // Enable CORS, authentication, and authorization middleware. app.UseCors("DamageAppCorsPolicy"); ->>>>>>> 9ec9b8b96fc7c5767fcddf1e4e52bde203fcf619 app.UseAuthorization(); app.MapControllers(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/Controllers/QuestionsController.cs b/DamageAssesmentApi/DamageAssesment.Api.Questions/Controllers/QuestionsController.cs index c73ff8a..ae17006 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Questions/Controllers/QuestionsController.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Questions/Controllers/QuestionsController.cs @@ -1,4 +1,5 @@ using DamageAssesment.Api.Questions.Interfaces; +using DamageAssesment.Api.Questions.Models; using Microsoft.AspNetCore.Mvc; namespace DamageAssesment.Api.Questions.Controllers @@ -108,6 +109,27 @@ namespace DamageAssesment.Api.Questions.Controllers } return CreatedAtRoute("DefaultApi",questions); } + + /// + /// POST request for creating a multiple question (multilingual). + /// + [HttpPost("questions/multiple/{surveyid}")] + public async Task UpdateQuestions(int surveyid, List questions) + { + if (questions != null) + { + var result = await this.questionsProvider.PutQuestionsAsync(surveyid,questions); + if (result.IsSuccess) + { + return Ok(result.Question); + } + if (result.ErrorMessage == "Not Found") + return NotFound(result.ErrorMessage); + + return BadRequest(result.ErrorMessage); + } + return CreatedAtRoute("DefaultApi", questions); + } /// /// POST request for creating a new question (multilingual). /// diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/Interfaces/IQuestionsProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Questions/Interfaces/IQuestionsProvider.cs index 4fcea32..eb2be52 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Questions/Interfaces/IQuestionsProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Questions/Interfaces/IQuestionsProvider.cs @@ -9,6 +9,7 @@ namespace DamageAssesment.Api.Questions.Interfaces Task<(bool IsSuccess, List SurveyQuestions, string ErrorMessage)> GetSurveyQuestionAsync(int surveyId,string language); Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> PostQuestionAsync(Models.Question Question); Task<(bool IsSuccess, IEnumerable Question, string ErrorMessage)> PostQuestionsAsync(List Questions); + Task<(bool IsSuccess, IEnumerable Question, string ErrorMessage)> PutQuestionsAsync(int surveyId, List Questions); Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> UpdateQuestionAsync(Models.Question Question); Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> DeleteQuestionAsync(int id); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.Questions/Program.cs index 8908e35..49bcda4 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Questions/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Questions/Program.cs @@ -52,11 +52,9 @@ if (app.Environment.IsDevelopment()) questionProvider.SeedData(); } } -<<<<<<< HEAD -======= + // Enable CORS, authentication, and authorization middleware. ->>>>>>> 9ec9b8b96fc7c5767fcddf1e4e52bde203fcf619 app.UseCors("DamageAppCorsPolicy"); app.UseAuthorization(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs index d6bfebc..b0b002a 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs @@ -376,6 +376,22 @@ namespace DamageAssesment.Api.Questions.Providers return (false, null, ex.Message); } } + + public async Task<(bool IsSuccess, IEnumerable Question, string ErrorMessage)> PutQuestionsAsync(int surveyId, List Questions) + { + try + { + questionDbContext.Questions.ToList().RemoveAll(s=> s.SurveyId == surveyId); + questionDbContext.SaveChanges(); + var response = await PostQuestionsAsync(Questions); + return (response); + } + 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