aboutsummaryrefslogtreecommitdiffstats
path: root/src/Pages/Index.cshtml.cs
blob: 3cefa0d1a9c30dc64f35bfef7d9bb13d660278ef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using VSH.Data;
using VSH.Data.Database;
using VSH.Data.Enums;

namespace VSH.Pages;

public class IndexModel : PageModel
{
	private readonly MainDbContext _context;

	public string ContactHtml { get; set; }
	public List<Product> HighlightedProducts { get; set; } = new();

	public IndexModel(MainDbContext context) {
		_context = context;
	}

	public ActionResult OnGet() {
		ContactHtml = _context.Documents.OrderBy(c => c.Created)
							  .LastOrDefault(c => c.Type == DocumentType.CONTACT_PAGE)
							  ?.Content;
		HighlightedProducts = _context.Products
									  .Where(c => c.ShowOnFrontpage
												  && c.VisibilityState == ProductVisibility.DEFAULT)
									  .Include(c => c.Category)
									  .ToList();
		return Page();
	}
}