From 81c1fc0c14253457c3c4fc24735e787ace1db70b Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Tue, 30 May 2023 07:18:47 +0300 Subject: [PATCH] Add index razor page --- Controllers/HomeController.cs | 19 ------------------- {Views/Home => Pages}/Index.cshtml | 6 ++++-- {Views/Home => Pages/Shared}/_About.cshtml | 0 {Views => Pages}/Shared/_Layout.cshtml | 0 {Views/Home => Pages/Shared}/_Masthead.cshtml | 0 {Views => Pages}/Shared/_Navigation.cshtml | 0 {Views/Home => Pages/Shared}/_Projects.cshtml | 16 ++++++++++++---- {Views/Home => Pages/Shared}/_SignUp.cshtml | 0 Program.cs | 2 ++ 9 files changed, 18 insertions(+), 25 deletions(-) delete mode 100644 Controllers/HomeController.cs rename {Views/Home => Pages}/Index.cshtml (70%) rename {Views/Home => Pages/Shared}/_About.cshtml (100%) rename {Views => Pages}/Shared/_Layout.cshtml (100%) rename {Views/Home => Pages/Shared}/_Masthead.cshtml (100%) rename {Views => Pages}/Shared/_Navigation.cshtml (100%) rename {Views/Home => Pages/Shared}/_Projects.cshtml (79%) rename {Views/Home => Pages/Shared}/_SignUp.cshtml (100%) diff --git a/Controllers/HomeController.cs b/Controllers/HomeController.cs deleted file mode 100644 index 028322c..0000000 --- a/Controllers/HomeController.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; -using MyDarling.Models; - -namespace MyDarling.Controllers -{ - public class HomeController : Controller - { - private DataContext context; - public HomeController(DataContext context) - { - this.context = context; - } - public IActionResult Index() - { - return View(context.UnderwearBundles.Include(b => b.Figures)); - } - } -} \ No newline at end of file diff --git a/Views/Home/Index.cshtml b/Pages/Index.cshtml similarity index 70% rename from Views/Home/Index.cshtml rename to Pages/Index.cshtml index 54ff64d..a3ec3a5 100644 --- a/Views/Home/Index.cshtml +++ b/Pages/Index.cshtml @@ -1,7 +1,9 @@ +@page @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers - +@using MyDarling.Models; +@inject DataContext context; @{ - Layout = "_Layout"; + Layout="_Layout"; } diff --git a/Views/Home/_About.cshtml b/Pages/Shared/_About.cshtml similarity index 100% rename from Views/Home/_About.cshtml rename to Pages/Shared/_About.cshtml diff --git a/Views/Shared/_Layout.cshtml b/Pages/Shared/_Layout.cshtml similarity index 100% rename from Views/Shared/_Layout.cshtml rename to Pages/Shared/_Layout.cshtml diff --git a/Views/Home/_Masthead.cshtml b/Pages/Shared/_Masthead.cshtml similarity index 100% rename from Views/Home/_Masthead.cshtml rename to Pages/Shared/_Masthead.cshtml diff --git a/Views/Shared/_Navigation.cshtml b/Pages/Shared/_Navigation.cshtml similarity index 100% rename from Views/Shared/_Navigation.cshtml rename to Pages/Shared/_Navigation.cshtml diff --git a/Views/Home/_Projects.cshtml b/Pages/Shared/_Projects.cshtml similarity index 79% rename from Views/Home/_Projects.cshtml rename to Pages/Shared/_Projects.cshtml index 1eb67bc..4b9a62e 100644 --- a/Views/Home/_Projects.cshtml +++ b/Pages/Shared/_Projects.cshtml @@ -1,11 +1,19 @@ -@model IQueryable; -@using System.Globalization; +@using System.Globalization +@using Microsoft.EntityFrameworkCore +@using MyDarling.Models +@inject DataContext context + +@{ + var bundles = context.UnderwearBundles + .Include(b => b.Figures) + .Where(b => b.Price != 0 && b.Figures.Count > 0) + .OrderByDescending(b => b.Id); +}
- @foreach (var bundle in @Model.Where(b => b.Price != 0 && b.Figures.Count > 0) - .OrderByDescending(b => b.Id)) + @foreach (var bundle in bundles) {
diff --git a/Views/Home/_SignUp.cshtml b/Pages/Shared/_SignUp.cshtml similarity index 100% rename from Views/Home/_SignUp.cshtml rename to Pages/Shared/_SignUp.cshtml diff --git a/Program.cs b/Program.cs index cfc572a..361be3e 100644 --- a/Program.cs +++ b/Program.cs @@ -26,12 +26,14 @@ builder.Services.Configure( opts => }); builder.Services.AddControllersWithViews(); +builder.Services.AddRazorPages(); var app = builder.Build(); app.UseStaticFiles(); app.MapControllers(); app.MapDefaultControllerRoute(); +app.MapRazorPages(); app.UseAuthentication(); app.UseAuthorization();