public async Task <IActionResult> GetToys() { var location = GetControllerActionNames(); try { _logger.LogInfo($"{location}: Attempted Call"); var toys = await _toyRepository.FindAll(); var response = _mapper.Map <IList <ToyDTO> >(toys); _logger.LogInfo($"{location}: Successful"); foreach (var item in response) { if (!string.IsNullOrEmpty(item.Image)) { var imgPath = GetImagePath(item.Image); if (System.IO.File.Exists(imgPath)) { byte[] imgBytes = System.IO.File.ReadAllBytes(imgPath); item.File = Convert.ToBase64String(imgBytes); } } } _logger.LogInfo($"{location}: Successful"); return(Ok(response)); } catch (Exception e) { return(internalError($"{location}: {e.Message} - {e.InnerException}")); } }