.sujenanth
07/31/2023, 5:11 PMSebastiaan
07/31/2023, 6:26 PMBlogOverviewControllercsharp
using Cultiv.Site.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Web;
using Umbraco.Cms.Web.Common.Controllers;
using Umbraco.Cms.Web.Common.PublishedModels;
namespace Cultiv.Controllers;
public class BlogOverviewController : RenderController
{
    private readonly IVariationContextAccessor _variationContextAccessor;
    private readonly ServiceContext _serviceContext;
        
    public BlogOverviewController(ILogger<BlogOverviewController> logger, 
        ICompositeViewEngine compositeViewEngine, 
        IUmbracoContextAccessor umbracoContextAccessor,
        IVariationContextAccessor variationContextAccessor, 
        ServiceContext context)
        : base(logger, compositeViewEngine, umbracoContextAccessor)
    {
        _variationContextAccessor = variationContextAccessor;
        _serviceContext = context;
    }
        
    [HttpGet]
    public IActionResult Index([FromQuery(Name = "page")] int page = 1)
    {
        var publishedValueFallback = new PublishedValueFallback(_serviceContext, _variationContextAccessor);
        var model = new BlogOverviewModel(CurrentPage, publishedValueFallback) { Page = page };
        var allBlogPosts = model.Children.ToList();
            
        var skip = 10 * model.Page - 10;
            
        model.TotalPages = Convert.ToInt32(Math.Ceiling(allBlogPosts.Count / 10.0));
        model.PreviousPage = model.Page - 1;
        model.NextPage = model.Page + 1;
        model.IsFirstPage = model.Page <= 1;
        model.IsLastPage = model.Page >= model.TotalPages;
            
        var selection = allBlogPosts.OrderByDescending(x => x.CreateDate)
            .Skip(skip)
            .Take(10)
            .Select(publishedContent => publishedContent as BlogPost)
            .ToList();
        model.PagedBlogPosts = selection;
        return CurrentTemplate(model);
    }
}blogOverview.sujenanth
08/02/2023, 7:59 AMMatt Wise
08/02/2023, 8:03 AM.sujenanth
08/02/2023, 8:11 AM.sujenanth
08/02/2023, 8:32 AMMatt Wise
08/02/2023, 8:33 AMMatt Wise
08/02/2023, 8:34 AMMatt Wise
08/02/2023, 8:35 AM.sujenanth
08/02/2023, 9:12 AM.sujenanth
08/02/2023, 11:46 AM.sujenanth
08/02/2023, 11:46 AMMatt Wise
08/02/2023, 11:50 AMhuwred
08/02/2023, 1:29 PMMadhackerZA
08/02/2023, 5:36 PM