Exemplo n.º 1
0
        public ActionResult PostTemplateUpdate(PostTemplateModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMaintenance))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult {
                    Errors = ModelState.SerializeErrors()
                }));
            }

            var template = _postTemplateService.GetPostTemplateById(model.Id);

            if (template == null)
            {
                throw new ArgumentException("No template found with the specified id");
            }
            template = model.ToEntity(template);
            _postTemplateService.UpdatePostTemplate(template);

            return(new NullJsonResult());
        }
Exemplo n.º 2
0
        public void CompilePost(Guid postId)
        {
            var post = _database.GetCollection <Post>("posts").FindById(postId);

            if (post == null)
            {
                throw new InvalidOperationException("Cannot find post with ID:" + postId);
            }

            var pipeline = new MarkdownPipelineBuilder()
                           .UseAdvancedExtensions()
                           .Build();

            string contentHtml = Markdown.ToHtml(post.ContentMarkdown, pipeline);

            var templateModel = new PostTemplateModel
            {
                AuthorName  = post.AuthorName,
                Title       = post.Title,
                ContentHtml = contentHtml,
                PublishedOn = post.PublishedOn,
            };

            string viewWithViewModel = _viewRender.RenderAsync("Templates/Post.cshtml", templateModel).GetAwaiter().GetResult();

            //output the post html
            File.WriteAllText(@$ "C:\Code\Afsw\src\client-site\{post.Slug}.html", viewWithViewModel);
Exemplo n.º 3
0
        public async Task <IActionResult> GetPosts([FromForm] int pageIndex = 1)
        {
            var(posts, loadmore) = await _postService.GetPagedPostsAsync(pageIndex);

            var model = new PostTemplateModel
            {
                Posts    = posts,
                LoadMore = loadmore
            };
            var postTemplate = await _renderService.RenderViewToStringAsync("Templates/_Post", model);

            return(Json(new
            {
                posts = postTemplate,
                loadMore = model.LoadMore
            }));
        }
Exemplo n.º 4
0
        public ActionResult PostTemplateAdd([Bind(Exclude = "Id")] PostTemplateModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMaintenance))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult {
                    Errors = ModelState.SerializeErrors()
                }));
            }

            var template = new PostTemplate();

            template = model.ToEntity(template);
            _postTemplateService.InsertPostTemplate(template);

            return(new NullJsonResult());
        }
Exemplo n.º 5
0
        public async Task <IActionResult> GetUserPosts(string username, [FromForm] int pageIndex = 1)
        {
            var user = await _userService.GetUserByUserNameAsync(username);

            if (user == null)
            {
                return(NotFound());
            }

            var result = await _postService.GetUserPostsAsync(pageIndex, user.Id);

            var model = new PostTemplateModel
            {
                Posts    = result.data,
                LoadMore = result.loadMore
            };
            var postTemplate = await _renderService.RenderViewToStringAsync("Templates/_Post", model);

            return(Json(new
            {
                posts = postTemplate,
                loadMore = model.LoadMore
            }));
        }
Exemplo n.º 6
0
 public static PostTemplate ToEntity(this PostTemplateModel model, PostTemplate destination)
 {
     return model.MapTo(destination);
 }
Exemplo n.º 7
0
 public static PostTemplate ToEntity(this PostTemplateModel model)
 {
     return model.MapTo<PostTemplateModel, PostTemplate>();
 }