In my asp.net web API 2, I am reading values from web.config from the controller into my DTO as a response to the client. It is working as expected, I wonder if there are any improvements to make it better. Should I read it from a database or elsewhere? So I would be glad if you can share your comments.
Here is the controller related part:
[HttpGet]
[Route("reconciliation")]
public async Task<IHttpActionResult> GameReconciliation(ReconciliationDto reconciliationDto)
{
if (!ModelState.IsValid) return BadRequest(ModelState);
using var recon = await _gameServices.GameReconciliation(reconciliationDto);
switch (recon.StatusCode)
{
case HttpStatusCode.NotFound:
{
return NotFound();
}
case HttpStatusCode.InternalServerError:
{
return InternalServerError();
}
case HttpStatusCode.OK:
{
var responseStream = await recon.Content.ReadAsStringAsync();
var resultResponse = JsonConvert.DeserializeObject<ReconciliationResponse>(responseStream);
//Transform ReconciliationResponse into DTO for returning result
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<ReconciliationResponse, ReconciliationResponseDto>().ForMember(x => x.ReconDateTime,
opt => opt.MapFrom(src => (src.ReconciliationResponseDateTime.ToString("yyyy-MM-dd"))));
});
var iMapper = config.CreateMapper();
var resultDto = iMapper.Map<ReconciliationResponse, ReconciliationResponseDto>(resultResponse);
//EAN Barcode Added
**resultDto.Ean = WebConfigurationManager.AppSettings["000000001570"];**
return Ok(resultDto);
}
case HttpStatusCode.Unauthorized:
{
return Unauthorized();
}
case HttpStatusCode.RequestTimeout:
{
return InternalServerError();
}
}
recon.Dispose();
return Ok(recon);
}
Here is web.config related part:
<appSettings>
<!--TEST EAN-->
<add key="000000001570" value="9799753293685" />