Ejemplo n.º 1
0
        public async Task <IActionResult> ImageDelete(int imageId)
        {
            try
            {
                string fileName = _outdoorPowerRepository.DeleteDealerInventoryImage(imageId);

                if (await _outdoorPowerRepository.SaveChangesAsync())
                {
                    // Remove all images
                    if (System.IO.File.Exists(fileName))
                    {
                        // Delete the image file.
                        System.IO.File.Delete(fileName);
                    }

                    return(Ok(imageId));
                }
            } catch (Exception ex)
            {
                _logger.LogError($"An error occurred when deleting image (id: {imageId},  Error Message: {ex}");
            }
            return(BadRequest("Failed to delete the image."));
        }