Пример #1
0
        /// <summary>
        /// Performs additional processing and loads related models.
        /// </summary>
        /// <param name="post">The source post</param>
        /// <param name="model">The targe model</param>
        private async void Process <T>(Data.Post post, T model) where T : Models.PostBase
        {
            model.EnableComments = post.EnableComments;
            if (model.EnableComments)
            {
                model.CommentCount = await _db.PostComments.CountAsync(c => c.PostId == model.Id).ConfigureAwait(false);
            }
            model.CloseCommentsAfterDays = post.CloseCommentsAfterDays;

            if (!(model is Models.IContentInfo))
            {
                if (post.Blocks.Count > 0)
                {
                    foreach (var postBlock in post.Blocks.OrderBy(b => b.SortOrder))
                    {
                        if (postBlock.Block.ParentId.HasValue)
                        {
                            var parent = post.Blocks.FirstOrDefault(b => b.BlockId == postBlock.Block.ParentId.Value);
                            if (parent != null)
                            {
                                postBlock.Block.ParentId = parent.Block.Id;
                            }
                        }
                    }
                    model.Blocks = _contentService.TransformBlocks(post.Blocks.OrderBy(b => b.SortOrder).Select(b => b.Block));
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Performs additional processing and loads related models.
        /// </summary>
        /// <param name="post">The source post</param>
        /// <param name="model">The targe model</param>
        private void Process <T>(Data.Post post, T model) where T : Models.PostBase
        {
            model.Category = api.Categories.GetById(post.CategoryId);

            foreach (var tag in api.Tags.GetByPostId(post.Id).OrderBy(t => t.Title))
            {
                model.Tags.Add((Models.Taxonomy)tag);
            }
        }
Пример #3
0
        // AddBlogImplementation###

        // ###AddPostImplementation
        public override IGraphQlObjectResult <Post?> AddPost(string blogId, NewPost newPost) =>
        this.ResolveTask(async _ =>
        {
            var post = new Data.Post {
                BlogId = int.Parse(blogId), Title = newPost.Title, Content = newPost.PostContent
            };
            context.Add(post);
            await context.SaveChangesAsync();
            return(post);
        }).Nullable(post => post.AsContract <PostResolver>());
Пример #4
0
        public async Task <IActionResult> Post([FromServices] GetPostQuery getPostQuery, string categoryCode, string postUrl)
        {
            Data.Post post = await getPostQuery.WithUnpublish().WithoutMarkDown().ExecuteAsync(categoryCode, postUrl);

            if (post == null)
            {
                return(new NotFoundResult());
            }

            return(Json(post));
        }
Пример #5
0
 /// <summary>
 /// Performs additional processing and loads related models.
 /// </summary>
 /// <param name="post">The source post</param>
 /// <param name="model">The targe model</param>
 private void Process <T>(Data.Post post, T model) where T : Models.PostBase
 {
     if (!(model is Models.IContentInfo))
     {
         if (post.Blocks.Count > 0)
         {
             var blocks = post.Blocks
                          .OrderBy(b => b.SortOrder)
                          .Select(b => b.Block)
                          .ToList();
             model.Blocks = _contentService.TransformBlocks(blocks);
         }
     }
 }
Пример #6
0
        // AddBlogImplementation###

        // ###AddPostImplementation
        public override IGraphQlObjectResult <Post?> AddPost(string blogId, NewPost newPost) =>
        this.ResolveTask(async _ =>
        {
            var blog = Data.BloggingData.Blogs.FirstOrDefault(blog => blog.BlogId == Guid.Parse(blogId));
            if (blog == null)
            {
                return(null);
            }
            var post = new Data.Post {
                PostId = Guid.NewGuid(), Title = newPost.Title, Content = newPost.PostContent
            };
            blog.Posts.Add(post);
            await Task.Yield();
            return(post);
        }).Nullable(post => post.AsContract <PostResolver>());
        public async Task <IActionResult> OnGetAsync(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Post = await _context.Posts
                   .Include(p => p.Image).SingleOrDefaultAsync(m => m.Id == id);

            if (Post == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Пример #8
0
        public async Task <IActionResult> OnGetAsync(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Post = await _context.Posts
                   .Include(p => p.Image).SingleOrDefaultAsync(m => m.Id == id);

            if (Post == null)
            {
                return(NotFound());
            }
            ViewData["ImageId"] = new SelectList(_context.Images, "Id", "Id");
            return(Page());
        }
        public async Task <IActionResult> OnPostAsync(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Post = await _context.Posts.FindAsync(id);

            if (Post != null)
            {
                _context.Posts.Remove(Post);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Пример #10
0
        /// <summary>
        /// Performs additional processing and loads related models.
        /// </summary>
        /// <param name="post">The source post</param>
        /// <param name="model">The targe model</param>
        private void Process <T>(Data.Post post, T model) where T : Models.PostBase
        {
            if (!(model is Models.IContentInfo))
            {
                if (post.Blocks.Count > 0)
                {
                    var blocks = post.Blocks
                                 .OrderBy(b => b.SortOrder)
                                 .Select(b => b.Block)
                                 .ToList();
                    model.Blocks = contentService.TransformBlocks(blocks);
                }
            }
            model.Category = api.Categories.GetById(post.CategoryId);

            foreach (var tag in api.Tags.GetByPostId(post.Id).OrderBy(t => t.Title))
            {
                model.Tags.Add((Models.Taxonomy)tag);
            }
        }
Пример #11
0
 /// <summary>
 /// Performs additional processing and loads related models.
 /// </summary>
 /// <param name="post">The source post</param>
 /// <param name="model">The targe model</param>
 private void Process <T>(Data.Post post, T model) where T : Models.PostBase
 {
     if (!(model is Models.IContentInfo))
     {
         if (post.Blocks.Count > 0)
         {
             foreach (var postBlock in post.Blocks.OrderBy(b => b.SortOrder))
             {
                 if (postBlock.Block.ParentId.HasValue)
                 {
                     var parent = post.Blocks.FirstOrDefault(b => b.BlockId == postBlock.Block.ParentId.Value);
                     if (parent != null)
                     {
                         postBlock.Block.ParentId = parent.Block.Id;
                     }
                 }
             }
             model.Blocks = _contentService.TransformBlocks(post.Blocks.OrderBy(b => b.SortOrder).Select(b => b.Block));
         }
     }
 }
Пример #12
0
        public string AddPost(string blogid, string username, string password, MetaPost post, bool publish)
        {
            EnsureUser(username, password).Wait();

            var newStory = new Data.Post();

            try
            {
                newStory.Title         = post.title;
                newStory.Content       = post.description;
                newStory.DatePublished = post.dateCreated == DateTime.MinValue ? DateTime.UtcNow : post.dateCreated;
                newStory.Tags          = string.Join(",", post.categories);
                newStory.IsPublished   = publish;
                newStory.Slug          = newStory.GetStoryUrl();

                _repo.AddPost(newStory);
                _repo.SaveAll();
            }
            catch (Exception)
            {
                throw new MetaWeblogException("Failed to save the post.");
            }
            return(newStory.Id.ToString());
        }
        public async Task <ResponseModel <bool> > Handle(CreatePostCommand request, CancellationToken cancellationToken)
        {
            var response = new ResponseModel <bool>()
            {
                Status       = HttpStatusCode.InternalServerError,
                IsSuccessful = false,
                Result       = false,
                Errors       = default
            };

            try
            {
                var category = await _categoryRepository.GetById(request.CategoryId);

                if (category is null)
                {
                    _logger.LogWarning($"{request.CategoryId} is not found");
                    return(_customExceptionBuilder.BuildEntityNotFoundException(response, request.CategoryId, ErrorTypes.EntityNotFound));
                }
                var post = new Data.Post()
                {
                    Category   = category,
                    PostStatus = request.PostStatus,
                    Content    = _htmlSanitizerHelper.SanitizeInput(request.Content),
                    Title      = _htmlSanitizerHelper.SanitizeInput(request.Title),
                    Id         = request.Id
                };

                await _postRepository.CreateAsync(post);

                response.Status       = HttpStatusCode.Created;
                response.IsSuccessful = true;
                response.Result       = true;

                return(response);
            }
            catch (Exception e)
            {
                if (e is ArgumentException)
                {
                    _logger.LogCritical(e, e.StackTrace, "Method : CreatePostCommandHandler - Handle - ArgumentException");
                    return(_customExceptionBuilder.BuildMaliciousInputFoundException(response, e.Message,
                                                                                     ErrorTypes.MaliciousInput));
                }
                _logger.LogCritical(e, e.StackTrace, "Method : CreatePostCommandHandler - Handle");

                var identicalPrimaryKeyExceptionResponse =
                    _customExceptionBuilder.BuildIdenticalPrimaryKeyException(e, response, request.Id);

                if (identicalPrimaryKeyExceptionResponse != null)
                {
                    return(identicalPrimaryKeyExceptionResponse);
                }
            }

            response.Errors = new List <ErrorResponse>()
            {
                new ErrorResponse()
                {
                    Reason  = 500,
                    Message = "An unexpected error occured"
                }
            };

            return(response);
        }