示例#1
0
 public void InsertPost(Post post)
 {
     InsertPostCommand.Execute(new
     {
         post.UserId,
         post.Hash,
         post.Content,
         post.Timestamp,
         post.Likes
     });
 }
示例#2
0
        public Post SubmitPost(CreatePostModel model)
        {
            //If statement to update the post if there is already one in the database.
            if (model.PostId != 0)
            {
                //converts the data into a post object.
                Post newPost = ConvertToPostWithPostId(model.PostPurpose, model.PostTitle, model.PostDescription,
                                                       model.ExpirationDate, model.PostStatus, model.SubCategoryId,
                                                       model.DatePosted, model.CategoryId, model.PostedBy, model.PostId);

                //command to update the post.
                UpdatePostCommand command = new UpdatePostCommand(newPost);
                commandBus.Execute(command);

                //grabs all images that were uploaded.
                List <String> updateImagePaths = ImagePathCreation();

                //inserts each image into the picture database.
                foreach (string path in updateImagePaths)
                {
                    InsertPictureCommand pictureCommand =
                        new InsertPictureCommand(new Picture(newPost.PostId, path));
                    commandBus.Execute(pictureCommand);
                }

                return(newPost);
            }

            //converts the data into a post object.
            Post post = ConvertToPost(model.PostPurpose, model.PostTitle, model.PostDescription, model.ExpirationDate,
                                      model.PostStatus, model.SubCategoryId, model.DatePosted, model.CategoryId,
                                      model.PostedBy);
            InsertPostCommand postcommand = new InsertPostCommand(post);

            commandBus.Execute(postcommand, delegate(Post result) { post = result; });

            // grabs all images that were uploaded.
            List <String> imagePaths = ImagePathCreation();


            //inserts each image into the picture database.
            foreach (string path in imagePaths)
            {
                InsertPictureCommand command = new InsertPictureCommand(new Picture(post.PostId, path));
                commandBus.Execute(command);
            }
            return(post);
        }