private async Task <ImageEntity> AddImageDetailsToRDS(ImageModel imageModel, string imageKey)
        {
            try
            {
                var imageEntity = new ImageEntity
                {
                    Description = imageModel.Description,
                    FileSizeKb  = ((decimal)imageModel.ImageFile.Length) / 1024,
                    FileType    = imageModel.ImageFile.ContentType,
                    ImageKey    = imageKey,
                    createdDate = DateTime.Now
                };

                _amazonRDS.Images.Add(imageEntity);
                var itensAdded = await _amazonRDS.SaveChangesAsync();

                if (itensAdded == 1)
                {
                    return(imageEntity);
                }
                else
                {
                    throw new CustomException(System.Net.HttpStatusCode.InternalServerError, "An unexpected error occurred. Please try again.");
                }
            }
            catch
            {
                await _awsS3service.RemoveFileAsync(imageKey);

                throw new CustomException(System.Net.HttpStatusCode.InternalServerError, "An unexpected error occurred. Please try again.");
            }
        }
Esempio n. 2
0
 public async Task <IActionResult> RemoveFileAsync(string fileName, string bucketName)
 {
     return(string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(bucketName)
         ? BadRequest("please provide valid file and/or valid bucketName name")
         : await ActionAsync(async() =>
     {
         var response = await _service.RemoveFileAsync(fileName, bucketName);
         return StatusCode((int)response.HttpStatusCode, response);
     }));
 }