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.UseSwagger();
app.UseSwaggerUI(); app.UseSwaggerUI();
} }
<<<<<<< HEAD
=======
// Enable CORS, authentication, and authorization middleware. // Enable CORS, authentication, and authorization middleware.
>>>>>>> 9ec9b8b96fc7c5767fcddf1e4e52bde203fcf619
app.UseCors("DamageAppCorsPolicy"); app.UseCors("DamageAppCorsPolicy");
app.UseAuthorization(); app.UseAuthorization();
app.UseHttpsRedirection(); app.UseHttpsRedirection();

View File

@ -50,14 +50,12 @@ if (app.Environment.IsDevelopment())
employeesProvider.SeedData(); employeesProvider.SeedData();
} }
} }
<<<<<<< HEAD
app.UseCors("DamageAppCorsPolicy"); app.UseCors("DamageAppCorsPolicy");
=======
// Enable CORS, authentication, and authorization middleware. // Enable CORS, authentication, and authorization middleware.
app.UseCors("DamageAppCorsPolicy"); app.UseCors("DamageAppCorsPolicy");
>>>>>>> 9ec9b8b96fc7c5767fcddf1e4e52bde203fcf619
app.UseAuthorization(); app.UseAuthorization();
app.MapControllers(); app.MapControllers();

View File

@ -51,14 +51,12 @@ if (app.Environment.IsDevelopment())
regionProvider.SeedData(); regionProvider.SeedData();
} }
} }
<<<<<<< HEAD
app.UseCors("DamageAppCorsPolicy"); app.UseCors("DamageAppCorsPolicy");
=======
// Enable CORS, authentication, and authorization middleware. // Enable CORS, authentication, and authorization middleware.
app.UseCors("DamageAppCorsPolicy"); app.UseCors("DamageAppCorsPolicy");
>>>>>>> 9ec9b8b96fc7c5767fcddf1e4e52bde203fcf619
app.UseAuthorization(); app.UseAuthorization();
app.MapControllers(); app.MapControllers();

View File

@ -1,4 +1,5 @@
using DamageAssesment.Api.Questions.Interfaces; using DamageAssesment.Api.Questions.Interfaces;
using DamageAssesment.Api.Questions.Models;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace DamageAssesment.Api.Questions.Controllers namespace DamageAssesment.Api.Questions.Controllers
@ -108,6 +109,27 @@ namespace DamageAssesment.Api.Questions.Controllers
} }
return CreatedAtRoute("DefaultApi",questions); 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> /// <summary>
/// POST request for creating a new question (multilingual). /// POST request for creating a new question (multilingual).
/// </summary> /// </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, 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, 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);

View File

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

View File

@ -376,6 +376,22 @@ namespace DamageAssesment.Api.Questions.Providers
return (false, null, ex.Message); 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) public async Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> UpdateQuestionAsync(Models.Question Question)
{ {
try try