public async Task <HttpResponseMessage> DeleteAsync(int id) { try { FileUploadService svc = new FileUploadService(); FileUploadAddRequest model = new FileUploadAddRequest(); model = svc.SelectById(id); var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/upload"), model.SystemFileName); try { var deleteObjectRequest = new DeleteObjectRequest { BucketName = bucketname, Key = model.SystemFileName }; await awsS3Client.DeleteObjectAsync(deleteObjectRequest); } catch (AmazonS3Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e)); } if (File.Exists(fileSavePath)) { File.Delete(fileSavePath); } svc.Delete(id); SuccessResponse resp = new SuccessResponse(); return(Request.CreateResponse(HttpStatusCode.OK, resp)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage GetById(int id) { try { FileUploadService svc = new FileUploadService(); ItemResponse <FileUploadAddRequest> resp = new ItemResponse <FileUploadAddRequest>(); resp.Item = svc.SelectById(id); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.OK, ex)); } }