示例#1
0
        public HttpResponseMessage DeleteIssue(int issueId)
        {
            ApiResult result;

            try
            {
                String locationName = "";
                var    images       = _imageRepository.GetImagesForIssue(issueId);
                if (images.Count > 0)
                {
                    int locationId = _issueRepository.GetLocationIdForIssue(issueId);
                    if (locationId == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Issue for image does not exists, or access denied"));
                    }

                    var location = _locationRepository.Get(locationId);
                    if (location == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Location not found"));
                    }

                    locationName = location.Name;
                }

                _issueRepository.Delete(issueId, User.Identity.Name);

                // delete images from disk
                foreach (var image in images)
                {
                    DeleteImageFile(locationName, image);
                }

                result = ApiResult.Success;
            }
            catch (LocationNotFoundException)
            {
                result = ApiResult.LocationNotFound;
            }
            catch (UserNotFoundException)
            {
                result = ApiResult.UserNotFound;
            }
            catch (UnauthorizedAccessException)
            {
                return(new HttpResponseMessage(HttpStatusCode.Unauthorized));
            }
            catch (IssueNotFoundException)
            {
                result = ApiResult.IssueNotFound;
            }
            catch (Exception)
            {
                return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, new ApiResponse {
                Result = result
            }));
        }
示例#2
0
        public HttpResponseMessage GetImages(int issueId)
        {
            ApiResult result;

            try
            {
                var images   = _imageRepository.GetImagesForIssue(issueId).ToList();
                var imageVMs = images.Select(ModelToVM).ToList();

                return(Request.CreateResponse(HttpStatusCode.OK,
                                              new ApiResponse
                {
                    Result = ApiResult.Success,
                    JsonContent = JsonConvert.SerializeObject(imageVMs, Formatting.None)
                }));
            }
            catch (LocationNotFoundException)
            {
                result = ApiResult.LocationNotFound;
            }
            catch (UserNotFoundException)
            {
                result = ApiResult.UserNotFound;
            }
            catch (UnauthorizedAccessException)
            {
                return(new HttpResponseMessage(HttpStatusCode.Unauthorized));
            }
            catch (Exception ex)
            {
                return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, new ApiResponse {
                Result = result
            }));
        }