public HttpResponseMessage SelectAll()
        {
            ItemsResponse <Image> response = new ItemsResponse <Image>();

            response.Items = _imagesService.Get();

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
        public IActionResult Delete([FromForm(Name = ("Id"))] int Id)
        {
            var carImage = _imagesService.Get(Id).Data;

            var result = _imagesService.Delete(carImage);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
Beispiel #3
0
        public bool deleteFilesInDirectory(int id)
        {
            DeleteObjectResponse response = null;
            bool ok = false;

            try
            {
                if (id > 0)
                {
                    Image image = _imagesService.Get(id);

                    if (image != null)
                    {
                        string fileNameAtAws = image.ImageUrl;

                        AWSCredentials awsCredentials = new BasicAWSCredentials(_configService.AwsAccessKeyId, _configService.AwsSecret);
                        AmazonS3Client client         = new AmazonS3Client(awsCredentials, Amazon.RegionEndpoint.USWest2);

                        DeleteObjectRequest fileDeleteRequest = new DeleteObjectRequest();
                        fileDeleteRequest.BucketName = _configService.AwsBucketName;
                        fileDeleteRequest.Key        = fileNameAtAws;

                        bool keyExists = ExistsKey(client, fileNameAtAws, fileDeleteRequest.BucketName);

                        if (keyExists)
                        {
                            response = client.DeleteObject(fileDeleteRequest);

                            ok = true;
                        }
                    }
                }
            }
            catch (AmazonS3Exception)
            {
                throw;
            }

            return(ok);
        }