more view components, adding filter capabilities
This commit is contained in:
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.7.34031.279
|
VisualStudioVersion = 17.7.34031.279
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FakePieShop", "FakePieShop\FakePieShop.csproj", "{8B6E0F54-FB13-438B-A6FE-EFABA4FAC43D}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FakePieShop", "FakePieShop\FakePieShop.csproj", "{8B6E0F54-FB13-438B-A6FE-EFABA4FAC43D}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
|||||||
19
FakePieShop/Components/CategoryMenu.cs
Normal file
19
FakePieShop/Components/CategoryMenu.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using FakePieShop.Repositories;
|
||||||
|
using FakePieShop.Models;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace FakePieShop.Components
|
||||||
|
{
|
||||||
|
public class CategoryMenu : ViewComponent
|
||||||
|
{
|
||||||
|
private readonly ICategoryRepository _categoryRepository;
|
||||||
|
|
||||||
|
public CategoryMenu(ICategoryRepository categoryRepository) => _categoryRepository = categoryRepository;
|
||||||
|
|
||||||
|
public IViewComponentResult Invoke()
|
||||||
|
{
|
||||||
|
IEnumerable<Category> categories = _categoryRepository.AllCategories.OrderBy(c => c.CategoryName);
|
||||||
|
return View(categories);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
26
FakePieShop/Components/ShoppingCartSummary.cs
Normal file
26
FakePieShop/Components/ShoppingCartSummary.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
using FakePieShop.Models;
|
||||||
|
using FakePieShop.ViewModels;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace FakePieShop.Components
|
||||||
|
{
|
||||||
|
public class ShoppingCartSummary : ViewComponent
|
||||||
|
{
|
||||||
|
private readonly IShoppingCart _shoppingCart;
|
||||||
|
|
||||||
|
public ShoppingCartSummary(IShoppingCart shoppingCart)
|
||||||
|
{
|
||||||
|
_shoppingCart = shoppingCart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IViewComponentResult Invoke()
|
||||||
|
{
|
||||||
|
var items = _shoppingCart.GetShoppingCartItems();
|
||||||
|
_shoppingCart.ShoppingCartItems = items;
|
||||||
|
|
||||||
|
var shoppingCartViewModel = new ShoppingCartViewModel(_shoppingCart, _shoppingCart.GetShoppingCartTotal());
|
||||||
|
|
||||||
|
return View(shoppingCartViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
using FakePieShop.Models;
|
using FakePieShop.ViewModels;
|
||||||
using FakePieShop.Models.ViewModels;
|
using FakePieShop.Repositories;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace FakePieShop.Controllers
|
namespace FakePieShop.Controllers
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using FakePieShop.Models;
|
using FakePieShop.Models;
|
||||||
using FakePieShop.Models.ViewModels;
|
using FakePieShop.Repositories;
|
||||||
|
using FakePieShop.ViewModels;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace FakePieShop.Controllers
|
namespace FakePieShop.Controllers
|
||||||
@@ -15,9 +16,23 @@ namespace FakePieShop.Controllers
|
|||||||
_categoryRepository = categoryRepository;
|
_categoryRepository = categoryRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult List()
|
public IActionResult List(string category)
|
||||||
{
|
{
|
||||||
PieListViewModel pieListViewModel = new PieListViewModel(_pieRepository.AllPies, "All Pies");
|
IEnumerable<Pie> pies;
|
||||||
|
string? currentCategory;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(category))
|
||||||
|
{
|
||||||
|
pies = _pieRepository.AllPies.OrderBy(p => p.PieId);
|
||||||
|
currentCategory = "All pies";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pies = _pieRepository.AllPies.Where(p => p.Category.CategoryName == category).OrderBy(p => p.PieId);
|
||||||
|
currentCategory = _categoryRepository.AllCategories.FirstOrDefault(c => c.CategoryName == category)?.CategoryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
PieListViewModel pieListViewModel = new(pies, currentCategory);
|
||||||
return View(pieListViewModel);
|
return View(pieListViewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using FakePieShop.Models;
|
using FakePieShop.Models;
|
||||||
using FakePieShop.Models.ViewModels;
|
using FakePieShop.ViewModels;
|
||||||
|
using FakePieShop.Repositories;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace FakePieShop.Controllers
|
namespace FakePieShop.Controllers
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
namespace FakePieShop.Models
|
|
||||||
{
|
|
||||||
public class MockCategoryRepository : ICategoryRepository
|
|
||||||
{
|
|
||||||
public IEnumerable<Category> AllCategories =>
|
|
||||||
new List<Category>
|
|
||||||
{
|
|
||||||
new Category { CategoryId = 1, CategoryName = "Fruit pies", Description = "All-fruity pies" },
|
|
||||||
new Category { CategoryId = 2, CategoryName = "Cheese cakes", Description = "Cheesy all the way" },
|
|
||||||
new Category { CategoryId = 3, CategoryName = "Seasonal pies", Description = "Get in the mood for a seasonal pie" }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
namespace FakePieShop.Models
|
|
||||||
{
|
|
||||||
public class MockPieRepository : IPieRepository
|
|
||||||
{
|
|
||||||
private readonly ICategoryRepository _categoryRepository = new MockCategoryRepository();
|
|
||||||
|
|
||||||
public IEnumerable<Pie> AllPies
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return new List<Pie>
|
|
||||||
{
|
|
||||||
new Pie
|
|
||||||
{
|
|
||||||
PieId = 1,
|
|
||||||
Name = "Strawberry Pie",
|
|
||||||
Price = 15.95M,
|
|
||||||
ShortDescription = "Lorem Ipsum",
|
|
||||||
LongDescription = "Lorem Ipsum",
|
|
||||||
Category = _categoryRepository.AllCategories.ToList()[0],
|
|
||||||
ImageUrl = "https://gillcleerenpluralsight.blob.core.windows.net/files/strawberrypie.jpg",
|
|
||||||
InStock = true,
|
|
||||||
IsPieOfTheWeek = true,
|
|
||||||
ImageThumbnailUrl = "https://gillcleerenpluralsight.blob.core.windows.net/files/strawberrypiesmall.jpg"
|
|
||||||
},
|
|
||||||
new Pie
|
|
||||||
{
|
|
||||||
PieId = 2,
|
|
||||||
Name = "Cheese cake",
|
|
||||||
Price = 18.95M,
|
|
||||||
ShortDescription = "Lorem Ipsum",
|
|
||||||
LongDescription = "Lorem Ipsum",
|
|
||||||
Category = _categoryRepository.AllCategories.ToList()[1],
|
|
||||||
ImageUrl = "https://gillcleerenpluralsight.blob.core.windows.net/files/cheesecake.jpg",
|
|
||||||
InStock = true,
|
|
||||||
IsPieOfTheWeek = false,
|
|
||||||
ImageThumbnailUrl = "https://gillcleerenpluralsight.blob.core.windows.net/files/cheesecakesmall.jpg"
|
|
||||||
},
|
|
||||||
new Pie
|
|
||||||
{
|
|
||||||
PieId = 3,
|
|
||||||
Name = "Rhubarb Pie",
|
|
||||||
Price = 15.95M,
|
|
||||||
ShortDescription = "Lorem Ipsum",
|
|
||||||
LongDescription = "Lorem Ipsum",
|
|
||||||
Category = _categoryRepository.AllCategories.ToList()[0],
|
|
||||||
ImageUrl = "https://gillcleerenpluralsight.blob.core.windows.net/files/rhubarbpie.jpg",
|
|
||||||
InStock = true,
|
|
||||||
IsPieOfTheWeek = false,
|
|
||||||
ImageThumbnailUrl = "https://gillcleerenpluralsight.blob.core.windows.net/files/rhubarbpiesmall.jpg"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<Pie> PiesOfTheWeek
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return AllPies.Where(p => p.IsPieOfTheWeek);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Pie? GetPieById(int pieId)
|
|
||||||
{
|
|
||||||
return AllPies.FirstOrDefault(p => p.PieId == pieId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<Pie> SearchPies(string searchQuery)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using BethanysPieShop.Models;
|
using BethanysPieShop.Models;
|
||||||
using FakePieShop.Models;
|
using FakePieShop.Models;
|
||||||
|
using FakePieShop.Repositories;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace FakePieShop.Models
|
using FakePieShop.Models;
|
||||||
|
|
||||||
|
namespace FakePieShop.Repositories
|
||||||
{
|
{
|
||||||
public class CategoryRepository : ICategoryRepository
|
public class CategoryRepository : ICategoryRepository
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace FakePieShop.Models
|
using FakePieShop.Models;
|
||||||
|
|
||||||
|
namespace FakePieShop.Repositories
|
||||||
{
|
{
|
||||||
public interface ICategoryRepository
|
public interface ICategoryRepository
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace FakePieShop.Models
|
using FakePieShop.Models;
|
||||||
|
|
||||||
|
namespace FakePieShop.Repositories
|
||||||
{
|
{
|
||||||
public interface IPieRepository
|
public interface IPieRepository
|
||||||
{
|
{
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using FakePieShop.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace FakePieShop.Models
|
namespace FakePieShop.Repositories
|
||||||
{
|
{
|
||||||
public class PieRepository : IPieRepository
|
public class PieRepository : IPieRepository
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace FakePieShop.Models.ViewModels
|
using FakePieShop.Models;
|
||||||
|
|
||||||
|
namespace FakePieShop.ViewModels
|
||||||
{
|
{
|
||||||
public class HomeViewModel
|
public class HomeViewModel
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace FakePieShop.Models.ViewModels
|
using FakePieShop.Models;
|
||||||
|
|
||||||
|
namespace FakePieShop.ViewModels
|
||||||
{
|
{
|
||||||
public class PieListViewModel
|
public class PieListViewModel
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace FakePieShop.Models.ViewModels
|
using FakePieShop.Models;
|
||||||
|
|
||||||
|
namespace FakePieShop.ViewModels
|
||||||
{
|
{
|
||||||
public class ShoppingCartViewModel
|
public class ShoppingCartViewModel
|
||||||
{
|
{
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
@model IEnumerable<Category>
|
||||||
|
|
||||||
|
<li class="nav-item dropdown">
|
||||||
|
<a class="nav-link dropdown-toggle"
|
||||||
|
data-toggle="dropdown"
|
||||||
|
href="#"
|
||||||
|
role="button"
|
||||||
|
data-bs-toggle="dropdown"
|
||||||
|
id="nav-dropdown"
|
||||||
|
aria-expanded="false">
|
||||||
|
Shop
|
||||||
|
</a>
|
||||||
|
<ul class="dropdown-menu" aria-labelledby="nav-dropdown">
|
||||||
|
@foreach (var category in Model)
|
||||||
|
{
|
||||||
|
<li>
|
||||||
|
<a class="dropdown-item"
|
||||||
|
asp-controller="Pie"
|
||||||
|
asp-action="List"
|
||||||
|
asp-route-category="@category.CategoryName">
|
||||||
|
@category.CategoryName
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
<li>
|
||||||
|
<a asp-controller="Pie" asp-action="List" asp-route-Category="" class="dropdown-item">All pies</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
@model ShoppingCartViewModel
|
||||||
|
|
||||||
|
@if (Model.ShoppingCart.ShoppingCartItems.Count > 0)
|
||||||
|
{
|
||||||
|
<ul class="navbar-nav mb-2 mb-lg-0">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-cart3" viewBox="0 0 16 16">
|
||||||
|
<path d="M0 1.5A.5.5 0 0 1 .5 1H2a.5.5 0 0 1 .485.379L2.89 3H14.5a.5.5 0 0 1 .49.598l-1 5a.5.5 0 0 1-.465.401l-9.397.472L4.415 11H13a.5.5 0 0 1 0 1H4a.5.5 0 0 1-.491-.408L2.01 3.607 1.61 2H.5a.5.5 0 0 1-.5-.5zM3.102 4l.84 4.479 9.144-.459L13.89 4H3.102zM5 12a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm-7 1a1 1 0 1 1 0 2 1 1 0 0 1 0-2zm7 0a1 1 0 1 1 0 2 1 1 0 0 1 0-2z" />
|
||||||
|
</svg>
|
||||||
|
<span id="cart-status">
|
||||||
|
@Model.ShoppingCart.ShoppingCartItems.Count
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
|
namespace FakePieShop.Views.Shared.Components.ShoppingCartSummary
|
||||||
|
{
|
||||||
|
public class DefaultModel : PageModel
|
||||||
|
{
|
||||||
|
public void OnGet()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,6 +35,7 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" asp-controller="Pie" asp-action="List">Pie List</a>
|
<a class="nav-link" asp-controller="Pie" asp-action="List">Pie List</a>
|
||||||
</li>
|
</li>
|
||||||
|
<vc:vc:shopping-cart-summary></vc:vc:shopping-cart-summary>
|
||||||
<!-- <li class="nav-item">
|
<!-- <li class="nav-item">
|
||||||
<a class="nav-link" asp-controller="Contact" asp-action="Index">Contact</a>
|
<a class="nav-link" asp-controller="Contact" asp-action="Index">Contact</a>
|
||||||
</li> -->
|
</li> -->
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
@using FakePieShop.Models;
|
@using FakePieShop.Models
|
||||||
@using FakePieShop.Models.ViewModels;
|
@using FakePieShop.ViewModels
|
||||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
@using FakePieShop.Components
|
||||||
|
|
||||||
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
|
@addTagHelper *, FakePieShop
|
||||||
@@ -28,6 +28,14 @@ build_metadata.AdditionalFiles.CssScope =
|
|||||||
build_metadata.AdditionalFiles.TargetPath = Vmlld3NcUGllXExpc3QuY3NodG1s
|
build_metadata.AdditionalFiles.TargetPath = Vmlld3NcUGllXExpc3QuY3NodG1s
|
||||||
build_metadata.AdditionalFiles.CssScope =
|
build_metadata.AdditionalFiles.CssScope =
|
||||||
|
|
||||||
|
[C:/Users/mikay/source/repos/FakePieShop/FakePieShop/Views/Shared/Components/CategoryMenu/Default.cshtml]
|
||||||
|
build_metadata.AdditionalFiles.TargetPath = Vmlld3NcU2hhcmVkXENvbXBvbmVudHNcQ2F0ZWdvcnlNZW51XERlZmF1bHQuY3NodG1s
|
||||||
|
build_metadata.AdditionalFiles.CssScope =
|
||||||
|
|
||||||
|
[C:/Users/mikay/source/repos/FakePieShop/FakePieShop/Views/Shared/Components/ShoppingCartSummary/Default.cshtml]
|
||||||
|
build_metadata.AdditionalFiles.TargetPath = Vmlld3NcU2hhcmVkXENvbXBvbmVudHNcU2hvcHBpbmdDYXJ0U3VtbWFyeVxEZWZhdWx0LmNzaHRtbA==
|
||||||
|
build_metadata.AdditionalFiles.CssScope =
|
||||||
|
|
||||||
[C:/Users/mikay/source/repos/FakePieShop/FakePieShop/Views/Shared/_Carousel.cshtml]
|
[C:/Users/mikay/source/repos/FakePieShop/FakePieShop/Views/Shared/_Carousel.cshtml]
|
||||||
build_metadata.AdditionalFiles.TargetPath = Vmlld3NcU2hhcmVkXF9DYXJvdXNlbC5jc2h0bWw=
|
build_metadata.AdditionalFiles.TargetPath = Vmlld3NcU2hhcmVkXF9DYXJvdXNlbC5jc2h0bWw=
|
||||||
build_metadata.AdditionalFiles.CssScope =
|
build_metadata.AdditionalFiles.CssScope =
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -28,6 +28,14 @@ build_metadata.AdditionalFiles.CssScope =
|
|||||||
build_metadata.AdditionalFiles.TargetPath = Vmlld3NcUGllXExpc3QuY3NodG1s
|
build_metadata.AdditionalFiles.TargetPath = Vmlld3NcUGllXExpc3QuY3NodG1s
|
||||||
build_metadata.AdditionalFiles.CssScope =
|
build_metadata.AdditionalFiles.CssScope =
|
||||||
|
|
||||||
|
[C:/Users/mikay/source/repos/FakePieShop/FakePieShop/Views/Shared/Components/CategoryMenu/Default.cshtml]
|
||||||
|
build_metadata.AdditionalFiles.TargetPath = Vmlld3NcU2hhcmVkXENvbXBvbmVudHNcQ2F0ZWdvcnlNZW51XERlZmF1bHQuY3NodG1s
|
||||||
|
build_metadata.AdditionalFiles.CssScope =
|
||||||
|
|
||||||
|
[C:/Users/mikay/source/repos/FakePieShop/FakePieShop/Views/Shared/Components/ShoppingCartSummary/Default.cshtml]
|
||||||
|
build_metadata.AdditionalFiles.TargetPath = Vmlld3NcU2hhcmVkXENvbXBvbmVudHNcU2hvcHBpbmdDYXJ0U3VtbWFyeVxEZWZhdWx0LmNzaHRtbA==
|
||||||
|
build_metadata.AdditionalFiles.CssScope =
|
||||||
|
|
||||||
[C:/Users/mikay/source/repos/FakePieShop/FakePieShop/Views/Shared/_Carousel.cshtml]
|
[C:/Users/mikay/source/repos/FakePieShop/FakePieShop/Views/Shared/_Carousel.cshtml]
|
||||||
build_metadata.AdditionalFiles.TargetPath = Vmlld3NcU2hhcmVkXF9DYXJvdXNlbC5jc2h0bWw=
|
build_metadata.AdditionalFiles.TargetPath = Vmlld3NcU2hhcmVkXF9DYXJvdXNlbC5jc2h0bWw=
|
||||||
build_metadata.AdditionalFiles.CssScope =
|
build_metadata.AdditionalFiles.CssScope =
|
||||||
|
|||||||
Reference in New Issue
Block a user