working through models, repositories

This commit is contained in:
2023-10-30 15:18:47 -05:00
parent 043b5a95f3
commit 2459e6a89e
24 changed files with 197 additions and 7 deletions

Binary file not shown.

BIN
.vs/slnx.sqlite Normal file

Binary file not shown.

View File

@@ -1,7 +0,0 @@
using Microsoft.AspNetCore.Mvc;
[Controller]
class PieController
{
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,10 @@
namespace FakePieShop.Models
{
public class Category
{
public int CategoryId { get; set; }
public string CategoryName { get; set; } = string.Empty;
public string? Description { get; set; }
public List<Pie>? Pies { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
namespace FakePieShop.Models
{
public interface ICategoryRepository
{
IEnumerable<Category> AllCategories { get; }
}
}

View File

@@ -0,0 +1,9 @@
namespace FakePieShop.Models
{
public interface IPieRepository
{
IEnumerable<Pie> AllPies { get; }
IEnumerable<Pie> PiesOfTheWeek { get; }
Pie? GetPieById(int pieId);
}
}

View File

@@ -0,0 +1,13 @@
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" }
};
}
}

View File

@@ -0,0 +1,65 @@
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
}
};
}
}
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();
}
}
}

20
FakePieShop/Models/Pie.cs Normal file
View File

@@ -0,0 +1,20 @@
using System.ComponentModel;
namespace FakePieShop.Models
{
public class Pie
{
public int PieId { get; set; }
public string Name { get; set; } = String.Empty;
public string? ShortDescription { get; set; }
public string? LongDescription { get; set; }
public string? AllergyInformation { get; set; }
public decimal Price { get; set; }
public string? ImageUrl { get; set; }
public string? ImageThumbnailUrl { get; set; }
public bool IsPieOfTheWeek { get; set; }
public bool InStock { get; set; }
public int CategoryId { get; set; }
public Category Category { get; set; } = default!;
}
}

View File

@@ -1,7 +1,11 @@
using FakePieShop.Models;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
// add services to application
builder.Services.AddControllersWithViews();
builder.Services.AddScoped<IPieRepository, MockPieRepository>();
builder.Services.AddScoped<ICategoryRepository, MockCategoryRepository>();
WebApplication app = builder.Build();

View File

@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]

View File

@@ -0,0 +1,23 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("FakePieShop")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("FakePieShop")]
[assembly: System.Reflection.AssemblyTitleAttribute("FakePieShop")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.

View File

@@ -0,0 +1 @@
8f4f401b3263a248ed5de2b5fc4f8ebb38be89a7

View File

@@ -0,0 +1,17 @@
is_global = true
build_property.TargetFramework = net6.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb = true
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = FakePieShop
build_property.RootNamespace = FakePieShop
build_property.ProjectDir = C:\Users\mikay\source\repos\FakePieShop\FakePieShop\
build_property.RazorLangVersion = 6.0
build_property.SupportLocalizedComponentNames =
build_property.GenerateRazorMetadataSourceChecksumAttributes =
build_property.MSBuildProjectDirectory = C:\Users\mikay\source\repos\FakePieShop\FakePieShop
build_property._RazorSourceGeneratorDebug =

View File

@@ -0,0 +1,17 @@
// <auto-generated/>
global using global::Microsoft.AspNetCore.Builder;
global using global::Microsoft.AspNetCore.Hosting;
global using global::Microsoft.AspNetCore.Http;
global using global::Microsoft.AspNetCore.Routing;
global using global::Microsoft.Extensions.Configuration;
global using global::Microsoft.Extensions.DependencyInjection;
global using global::Microsoft.Extensions.Hosting;
global using global::Microsoft.Extensions.Logging;
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Net.Http.Json;
global using global::System.Threading;
global using global::System.Threading.Tasks;