|
|
|
@ -33,7 +33,10 @@ namespace WfApi.Controllers
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = await _quote.GetQuoteById(id);
|
|
|
|
|
|
|
|
|
|
if (result == null)
|
|
|
|
|
{
|
|
|
|
|
throw new KeyNotFoundException($"Error : No quotes found with the ID: {id}.");
|
|
|
|
|
}
|
|
|
|
|
if (result!=null)
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult<IActionResult>(Ok(result));
|
|
|
|
@ -256,20 +259,27 @@ namespace WfApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (newQuote == null)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(new { message = "Les données de la quote sont requises." });
|
|
|
|
|
}
|
|
|
|
|
if (newQuote == null)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(new { message = "Les données de la quote sont requises." });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var existingPlayer = _quote.GetQuoteById(newQuote.Id).Result;
|
|
|
|
|
if (existingPlayer != null)
|
|
|
|
|
{
|
|
|
|
|
return Conflict(new { message = "Une quote avec cet ID existe déjà." });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_quote.AddQuote(newQuote);
|
|
|
|
|
if (await _quote.GetQuoteById(newQuote.Id) != null)
|
|
|
|
|
{
|
|
|
|
|
return Conflict(new { message = "Une quote avec cet ID existe déjà." });
|
|
|
|
|
}
|
|
|
|
|
newQuote.IsValide=false;
|
|
|
|
|
var quote=_quote.AddQuote(newQuote);
|
|
|
|
|
|
|
|
|
|
return CreatedAtAction(nameof(GetAllQuote), new { id = newQuote.Id }, newQuote);
|
|
|
|
|
return CreatedAtAction(nameof(CreateQuote), new { id = newQuote.Id }, quote);
|
|
|
|
|
}
|
|
|
|
|
catch (KeyNotFoundException e)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.NotFound, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
@ -331,22 +341,24 @@ namespace WfApi.Controllers
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
|
|
|
public async Task<IActionResult> DeleteQuote([FromQuery] int idQuote)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = _quote.RemoveQuote(idQuote);
|
|
|
|
|
|
|
|
|
|
if (result.IsCompletedSuccessfully)
|
|
|
|
|
try {
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult<IActionResult>(Ok(result));
|
|
|
|
|
_quote.RemoveQuote(idQuote).Wait();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return await Task.FromResult<IActionResult>(Ok());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
catch (KeyNotFoundException e)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
return StatusCode((int)HttpStatusCode.NotFound, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" });
|
|
|
|
|
return StatusCode((int) HttpStatusCode.InternalServerError, new { message = "Erreur interne du serveur." });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|