Adding endpoint for mutiple questions update

This commit is contained in:
Reginald Cherenfant Jasmin 2023-12-07 02:16:00 -05:00
parent 3de53c1198
commit d7005479c5
7 changed files with 43 additions and 12 deletions

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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);
}
/// <summary>
/// POST request for creating a multiple question (multilingual).
/// </summary>
[HttpPost("questions/multiple/{surveyid}")]
public async Task<IActionResult> UpdateQuestions(int surveyid, List<Models.Question> 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);
}
/// <summary>
/// POST request for creating a new question (multilingual).
/// </summary>

View File

@ -9,6 +9,7 @@ namespace DamageAssesment.Api.Questions.Interfaces
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, 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, Models.MultiLanguage Question, string ErrorMessage)> UpdateQuestionAsync(Models.Question Question);
Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> DeleteQuestionAsync(int id);

View File

@ -52,11 +52,9 @@ if (app.Environment.IsDevelopment())
questionProvider.SeedData();
}
}
<<<<<<< HEAD
=======
// Enable CORS, authentication, and authorization middleware.
>>>>>>> 9ec9b8b96fc7c5767fcddf1e4e52bde203fcf619
app.UseCors("DamageAppCorsPolicy");
app.UseAuthorization();

View File

@ -376,6 +376,22 @@ 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
{
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