コード例 #1
0
        public HttpResponseMessage Delete(string diagramid, string imagename)
        {
            //Get the current authenticated user
            string UserId    = UserHelper.GetCurrentUserID().ToLower();
            string DiagramId = diagramid.ToLower();
            string ImageName = imagename.ToLower();

            string Blobname = UserId + "/" + DiagramId + "/" + imagename;

            try
            {
                if (BlobManager.ImageExists(Blobname))
                {
                    bool ImageDeleted = BlobManager.DeleteImage(Blobname);
                    if (ImageDeleted)
                    {
                        var response = Request.CreateErrorResponse(HttpStatusCode.OK, "'" + imagename + "' has been deleted successfully");
                        response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
                        return(response);
                    }
                    else
                    {
                        var response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "'" + imagename +
                                                                   "' cannot be deleted, Try again and make sure the image info is correct.");
                        response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
                        return(response);
                    }
                }
                else //Image cannot be found
                {
                    var response = Request.CreateErrorResponse(HttpStatusCode.NotFound, "'" + imagename + "' image cannot be found");
                    response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
                    //response.StatusCode = HttpStatusCode.NotFound;
                    throw new HttpResponseException(response);
                }
            }
            catch (Exception Ex)
            {
                string Err      = string.Format("Unable to delete the image {0}", imagename);
                var    response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, Err);
                response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
                Log.LogError("ImageAPI: Unable to delete the image {0}, Error: {1}", imagename, Ex.Message);
                throw new HttpResponseException(response);
            }
        }