Exemplo n.º 1
0
        public PropertyPhoto AddPhoto(PropertyPhoto photo)
        {
            if (photo == null)
                throw new ParamMissingException("You must provide a photo instance.");

            if (string.IsNullOrWhiteSpace(photo.PhotoUrl))
                throw new ParamMissingException("Photo URL cannot be null.");

            if (string.IsNullOrWhiteSpace(photo.ThumbnailUrl))
                throw new ParamMissingException("Thumbnail URL cannot be null.");

            Property property = Repository.Single<Property>(
                x => x.ListingKey  == photo.ListingKey);
            if (property == null)
                throw new InvalidValueException("Property not found.");

            PropertyPhoto dbPhoto = Repository.Single<PropertyPhoto>(x => x.PhotoUrl.Equals(photo.PhotoUrl)
                                        && x.ListingKey == photo.ListingKey);
            if (dbPhoto != null)
                throw new AlreadyExistsException("Property photo with file name already exits.");

            Repository.Add<PropertyPhoto>(photo);
            Repository.Save();
            return photo;
        }
 public HttpResponseMessage AddPhoto(PropertyPhoto photo)
 {
     try
     {
         if( photo == null)
             return Request.CreateResponse(HttpStatusCode.NotAcceptable, GetErrorResponse("Photo must have values."));
         return Request.CreateResponse(HttpStatusCode.OK, _photoManager.AddPhoto(photo));
     }catch (ParamMissingException e){
         return Request.CreateResponse(HttpStatusCode.NotAcceptable, new ErrorResponse{ Message = e.Message });
     } catch (AlreadyExistsException e){
         return Request.CreateResponse(HttpStatusCode.Conflict, new ErrorResponse{ Message = e.Message });
     }catch (InvalidValueException e){
         return Request.CreateResponse(HttpStatusCode.NotAcceptable, new ErrorResponse{ Message = e.Message });
     }catch (UserNotFoundException e){
         return Request.CreateResponse(HttpStatusCode.NotFound, new ErrorResponse{ Message = e.Message });
     }catch (Exception e){
         return Request.CreateResponse(HttpStatusCode.InternalServerError, new ErrorResponse { Message = "Bugger! Server encountered an issue... " + e.Message });
     }
 }