Beispiel #1
0
        public HttpResponseMessage PostAddCommentToPicture(CommentModel comment, int pictureId, string sessionKey)
        {
            try
            {
                var userService = new UserService();
                var user        = userService.GetUserBySessionKey(sessionKey);

                Validator.ValidateUser(user, USER_ACCESS_DENIED);

                var pictureService = new PictureService();
                var picture        = pictureService.GetPictureById(pictureId);

                Validator.ValidatePicture(picture, PICTURE_NOT_FOUND);

                var newComment = pictureService.AddPictureComment(comment, picture, user);

                var commentToReturn = new CommentModel()
                {
                    CreatedAt = newComment.CreatedAt,
                    Id        = newComment.Id,
                    Text      = newComment.Text,
                    UserName  = user.UserName
                };

                return(this.Request.CreateResponse(HttpStatusCode.Created, commentToReturn));
            }
            catch (Exception ex)
            {
                return(this.Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message));
            }
        }