Skip to content

Commit

Permalink
Merge pull request #23 from idseefeld/modelsbuilder
Browse files Browse the repository at this point in the history
Umbraco v10 + sqlite
  • Loading branch information
idseefeld committed Jun 20, 2022
2 parents c479880 + 63feb6c commit 40a529a
Show file tree
Hide file tree
Showing 299 changed files with 12,048 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Readme.md
Expand Up @@ -43,3 +43,6 @@ To login to the Umbraco backoffice use these credentials:

### Read more:
Go to [adolfi.dev](https://adolfi.dev) if you want to read more Umbraco and Unit Testing articles.

### Upgrade to Umbraco v10.0.0-rc5
Find an upgrade version in [UmbracoTenDemoSite](UmbracoTenDemoSite).
Binary file modified UmbracoNineDemoSite.Web/umbraco/Data/Umbraco.sdf
Binary file not shown.
12 changes: 12 additions & 0 deletions UmbracoTenDemoSite/UmbracoTenDemoSite.Core/Features/Class1.cs
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UmbracoTenDemoSite.Core.Features
{
internal class Class1
{
}
}
@@ -0,0 +1,43 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Web;
using Umbraco.Cms.Web.Common.Controllers;
using Umbraco.Extensions;
using UmbracoTenDemoSite.Core.Features.Shared.Components.Hero;
using UmbracoTenDemoSite.Core.Features.Shared.Extensions;
using generatedModels = UmbracoTenDemoSite.Core;

namespace UmbracoTenDemoSite.Core.Features.Home
{
public class HomeController : RenderController
{
public HomeController(ILogger<RenderController> logger, ICompositeViewEngine compositeViewEngine, IUmbracoContextAccessor umbracoContextAccessor) : base(logger, compositeViewEngine, umbracoContextAccessor) { }

public IActionResult Home(ContentModel model)
{
var mbModel = model.Content as generatedModels.Home ?? new generatedModels.Home(model.Content, null);
var viewModel = new HomeViewModel()
{
Heading = mbModel.Heading,
Preamble = mbModel.Preamble,
BackgroundImage = mbModel.BackgroundImage,
CallToActionLabel = mbModel.CallToActionLabel,
CallToActionUrl = mbModel.CallToActionUrl?.Url(),
Blocks = mbModel.Blocks
};
viewModel.Hero = new HeroViewModel()
{
CallToActionUrl = viewModel.CallToActionUrl,
CallToActionLabel = viewModel.CallToActionLabel,
BackgroundImageUrl = viewModel.BackgroundImage,
Preamble = viewModel.Preamble,
Heading = viewModel.Heading
};
viewModel.MapSitePageBase(mbModel);

return View(viewModel);
}
}
}
@@ -0,0 +1,19 @@
using Umbraco.Cms.Core.Models.Blocks;
using UmbracoTenDemoSite.Core.Features.Shared.Components.Hero;
using UmbracoTenDemoSite.Core.Features.Shared.Content;

namespace UmbracoTenDemoSite.Core.Features.Home
{
public class HomeViewModel : SitePageBase, IHeadingPage
{
public HomeViewModel() : base() { }

public string Heading { get; set; }
public string Preamble { get; set; }
public string BackgroundImage { get; set; }
public string CallToActionUrl { get; set; }
public string CallToActionLabel { get; set; }
public BlockListModel Blocks { get; set; }
public HeroViewModel Hero { get; set; }
}
}
@@ -0,0 +1,30 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Web;
using Umbraco.Cms.Web.Common.Controllers;
using UmbracoTenDemoSite.Core.Features.Shared.Extensions;
using generatedModels = UmbracoTenDemoSite.Core;

namespace UmbracoTenDemoSite.Core.Features.Page
{
public class PageController : RenderController
{
public PageController(ILogger<RenderController> logger, ICompositeViewEngine compositeViewEngine, IUmbracoContextAccessor umbracoContextAccessor) : base(logger, compositeViewEngine, umbracoContextAccessor) { }

public IActionResult Page(ContentModel model)
{
var mbModel = model.Content as generatedModels.Page ?? new generatedModels.Page(model.Content, null);
var viewModel = new PageViewModel()
{
Heading = mbModel.Heading,
BodyText = mbModel.BodyText,
Blocks = mbModel.Blocks
};
viewModel.MapSitePageBase(mbModel);

return View(viewModel);
}
}
}
@@ -0,0 +1,17 @@
using Umbraco.Cms.Core.Models.Blocks;
using Umbraco.Cms.Core.Strings;
using UmbracoTenDemoSite.Core.Features.Shared.Content;

namespace UmbracoTenDemoSite.Core.Features.Page
{
public class PageViewModel : SitePageBase, IHeadingPage
{
public PageViewModel() : base() { }

public string Heading { get; set; }

public IHtmlEncodedString BodyText { get; set; }

public BlockListModel Blocks { get; set; }
}
}
@@ -0,0 +1,32 @@
using Umbraco.Cms.Core.Models.PublishedContent;
using UmbracoTenDemoSite.Core.Features.Shared.Constants;
using UmbracoTenDemoSite.Core.Features.Shared.Content;
using UmbracoTenDemoSite.Integrations.Products.Entities;

namespace UmbracoTenDemoSite.Core.Features.Products
{
public class ProductPageViewModel : SitePageBase, IHeadingPage
{

public ProductPageViewModel(IProduct product) : base()
{
this.Id = product.Id;
this.Name = product.Name;
this.Description = product.Description;
this.PageDescription = product.ShortDescription;
this.ImageUrl = product.ImageUrl;
this.Price = product.Price;
}

public new int Id { get; set; }
public new string Name { get; set; }
public string Description { get; set; }
public string ImageUrl { get; set; }
public int Price { get; set; }
public string UrlSegment => $"{Id}/{Name}";

public string Heading { get; set; }
public override string PageTitle => this.Name;
public override string PageDescription { get; set; }
}
}
@@ -0,0 +1,16 @@
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using UmbracoTenDemoSite.Integrations.Products.Services;

namespace UmbracoTenDemoSite.Core.Features.Products
{
public class ProductsComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.Services.AddTransient<IProductService, ProductService>();
builder.ContentFinders().Append<ProductsContentFinder>();
}
}
}
@@ -0,0 +1,65 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using Microsoft.Extensions.Logging;
using System.Linq;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Web;
using Umbraco.Cms.Web.Common.Controllers;
using Umbraco.Extensions;
using UmbracoTenDemoSite.Core.Features.Shared.Extensions;
using UmbracoTenDemoSite.Integrations.Products.Entities;
using UmbracoTenDemoSite.Integrations.Products.Services;
using generatedModels = UmbracoTenDemoSite.Core;

namespace UmbracoTenDemoSite.Core.Features.Products
{
public class ProductsContainerController : RenderController
{
private readonly IProductService productService;

public ProductsContainerController(ILogger<RenderController> logger, ICompositeViewEngine compositeViewEngine, IUmbracoContextAccessor umbracoContextAccessor, IProductService productService) : base(logger, compositeViewEngine, umbracoContextAccessor)
{
this.productService = productService;
}

public IActionResult ProductsContainer(ContentModel model)
{
var mbModel = model.Content as generatedModels.ProductsContainer ?? new generatedModels.ProductsContainer(model.Content, null);
var currentProduct = CurrentProduct;
if (currentProduct == null)
{
var viewModel = new ProductsContainerViewModel()
{
Products = this.productService.GetAll().Select(product => new ProductPageViewModel(product)),
Heading = mbModel.Heading
};
viewModel.MapSitePageBase(mbModel);

return View("ProductsContainer", viewModel);
}
else
{
var viewModel = new ProductPageViewModel(currentProduct)
{
Heading = mbModel.Heading,
SiteName = mbModel?.Root().Name
};

return View("ProductPage", viewModel);
}
}

public IProduct CurrentProduct
{
get
{
var segments = Request.Path.Value.Split("/");
if (!int.TryParse(segments[2], out var id))
{
return null;
}
return this.productService.Get(id);
}
}
}
}
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using UmbracoTenDemoSite.Core.Features.Shared.Content;

namespace UmbracoTenDemoSite.Core.Features.Products
{
public class ProductsContainerViewModel : SitePageBase, IHeadingPage
{
public ProductsContainerViewModel() : base() { }

public string Heading { get; set; }

public IEnumerable<ProductPageViewModel> Products { get; set; }
}
}
@@ -0,0 +1,63 @@
using System.Linq;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Cms.Core.Routing;
using Umbraco.Cms.Core.Web;
using UmbracoTenDemoSite.Integrations.Products.Services;

namespace UmbracoTenDemoSite.Core.Features.Products
{
/// <summary>
/// Docs: https://our.umbraco.com/Documentation/Reference/Routing/Request-Pipeline/IContentFinder
/// </summary>
public class ProductsContentFinder : IContentFinder
{
private readonly IProductService productService;
private readonly IUmbracoContextAccessor umbracoContextAccessor;
public readonly IPublishedSnapshotAccessor publishedSnapshotAccessor;

public ProductsContentFinder(IProductService productService, IUmbracoContextAccessor umbracoContextAccessor, IPublishedSnapshotAccessor publishedSnapshotAccessor)
{
this.productService = productService;
this.umbracoContextAccessor = umbracoContextAccessor;
this.publishedSnapshotAccessor = publishedSnapshotAccessor;
}
//IContentFinder.TryFindContent is now async
public Task<bool> TryFindContent(IPublishedRequestBuilder request)
{
var segments = request.AbsolutePathDecoded.Split("/");
if (!int.TryParse(segments[2], out var id))
{
return Task.FromResult(false);
}

var product = this.productService.Get(id);
if (product == null)
{
return Task.FromResult(false);
}

var contentType = ProductsContainer
.GetModelContentType(publishedSnapshotAccessor);

umbracoContextAccessor
.TryGetUmbracoContext(out IUmbracoContext umbracoContext);
var container = umbracoContext?
.Content?
.GetByContentType(contentType)
.FirstOrDefault();

if (container == null)
{
return Task.FromResult(false);
}

if(!segments[1].Equals(container.UrlSegment, System.StringComparison.InvariantCultureIgnoreCase))
{
return Task.FromResult(false);
}

request.SetPublishedContent(container);
return Task.FromResult(true);
}
}
}
@@ -0,0 +1,25 @@
using Examine;
using Umbraco.Cms.Infrastructure.Search;
using Umbraco.Cms.Web.Common.Controllers;
using UmbracoTenDemoSite.Core.Features.Search.Criteria;
using UmbracoTenDemoSite.Core.Features.Search.Models;
using UmbracoTenDemoSite.Core.Features.Search.Services;

namespace UmbracoTenDemoSite.Core.Features.Search.Controllers
{
public class SearchApiController : UmbracoApiController
{
private readonly SearchService _searchService;
public SearchApiController(SearchService searchService)
{
_searchService = searchService;
}
public SearchResults Search(string searchTerm, int skip, int take)
{
var criteria = new BaseSearchCriteria { SearchTerm = searchTerm, Skip = skip, Take = take};
var results = _searchService.Search(criteria);

return results;
}
}
}

0 comments on commit 40a529a

Please sign in to comment.