a bunch of stuff

This commit is contained in:
2026-04-22 20:09:26 -05:00
parent 5267701e32
commit fc7db1fedd
16 changed files with 697 additions and 362 deletions

View File

@@ -0,0 +1,86 @@
@page "/book"
@using Microsoft.AspNetCore.Components.Forms
<div class="container booking-page">
<div class="section-title">
<h1>Request an Appointment</h1>
<p>Complete the form below and a technician will review your case.</p>
</div>
<EditForm Model="@Model" OnValidSubmit="HandleSubmit" class="booking-form-wrapper">
<DataAnnotationsValidator />
<div class="form-grid">
<div class="form-column">
<h3 class="form-heading">1. Appliance Details</h3>
<div class="field-group">
<label>Appliance Type</label>
<InputSelect @bind-Value="Model.Type" class="custom-input">
<option value="">Select an appliance...</option>
<option>Refrigerator</option>
<option>Washing Machine</option>
<option>Dishwasher</option>
<option>Oven / Stove</option>
<option>Dryer</option>
</InputSelect>
</div>
<div class="field-group">
<label>Appliance Brand</label>
<InputSelect @bind-Value="Model.Brand" class="custom-input">
<option value="">Select a brand...</option>
<option>LG</option>
<option>Maytag</option>
<option>Whirlpool</option>
<option>Kitchen Aid</option>
<option>Amana</option>
<option>GE</option>
<option>Samsung</option>
<option>Bosch</option>
<option>Frigidaire</option>
<option>Kenmore</option>
<option>Other (please include in notes)</option>
</InputSelect>
</div>
<div class="field-group">
<label>Describe the Issue</label>
<InputTextArea @bind-Value="Model.Notes"
placeholder="e.g. Making a clicking noise, not draining, error code F1E2..."
class="custom-input textarea" />
</div>
</div>
<div class="form-column">
<h3 class="form-heading">2. Photos & Contact</h3>
<div class="upload-zone">
<p><strong>Upload Photos/Video</strong></p>
<p class="small-text">Tip: A photo of the <u>model number sticker</u> helps us arrive with the right parts!</p>
<InputFile OnChange="HandleFiles" multiple class="file-input" id="file-upload" />
<label for="file-upload" class="btn btn-secondary">Add Media</label>
@if (SelectedFiles.Any())
{
<div class="file-count">@SelectedFiles.Count files attached</div>
}
</div>
<div class="field-group">
<label>Full Name</label>
<InputText @bind-Value="Model.Name" class="custom-input" />
</div>
<div class="field-group">
<label>Phone Number</label>
<InputText @bind-Value="Model.Phone" class="custom-input" />
</div>
</div>
</div>
<div class="form-footer">
<button type="submit" class="btn btn-primary btn-large">Submit Repair Request</button>
</div>
</EditForm>
</div>

View File

@@ -0,0 +1,17 @@
using Microsoft.AspNetCore.Components.Forms;
namespace ApplianceRepair.Components.Pages
{
public partial class Book()
{
private RepairRequestModel Model = new();
private List<IBrowserFile> SelectedFiles = new();
private void HandleFiles(InputFileChangeEventArgs e) => SelectedFiles.AddRange(e.GetMultipleFiles());
private async Task HandleSubmit()
{
// Logic to process the request
}
}
}

View File

@@ -0,0 +1,105 @@
.booking-page {
padding: 60px 20px;
}
.booking-form-wrapper {
background: #fff;
padding: 40px;
border-radius: 8px;
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
border-top: 5px solid #0056b3;
}
.form-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 40px;
}
.form-heading {
color: #0056b3;
margin-bottom: 20px;
font-size: 1.3rem;
border-bottom: 1px solid #eee;
padding-bottom: 10px;
}
.field-group {
margin-bottom: 20px;
margin-right: 20px;
}
.field-group label {
display: block;
font-weight: bold;
margin-bottom: 8px;
color: #333;
}
::deep .custom-input {
width: 100%;
padding: 12px;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 1rem;
}
::deep .textarea {
height: 120px;
resize: none;
}
/* Upload Styling */
.upload-zone {
background: #f8f9fa;
border: 2px dashed #0056b3;
padding: 20px;
text-align: center;
border-radius: 8px;
margin-bottom: 25px;
}
.small-text {
font-size: 0.85rem;
color: #666;
margin: 10px 0;
}
.file-input {
display: none;
}
.file-count {
margin-top: 10px;
font-size: 0.9rem;
color: #0056b3;
font-weight: bold;
}
.form-footer {
text-align: center;
margin-top: 30px;
}
.btn-large {
background: #4CAF50;
color: white;
border: none;
padding: 15px 40px;
border-radius: 50px;
font-weight: 700;
cursor: pointer;
box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
transition: all 0.3s ease;
}
/* Match your mobile responsiveness */
@media (max-width: 768px) {
.form-grid {
grid-template-columns: 1fr;
}
.booking-form-wrapper {
padding: 20px;
}
}

View File

@@ -10,31 +10,7 @@ namespace ApplianceRepair.Components.Pages
{
if (!cache.TryGetValue(nameof(HomePageModel), out Model))
{
Model = Defaults.DefaultHomePageContent;
var homePageRecord = await homePageReader.ReadLatestRecord();
if (homePageRecord != null)
{
Model = new HomePageModel(homePageRecord);
var serviceCardRecords = await contentCardReader.ReadAllByPageAndGroup(nameof(Home), "Services");
if (serviceCardRecords != null)
{
foreach (var record in serviceCardRecords)
{
Model.ServicesCards!.Add(new ContentCardModel(record));
}
}
var trustCardRecords = await contentCardReader.ReadAllByPageAndGroup(nameof(Home), "Trust");
if (trustCardRecords != null)
{
foreach (var record in trustCardRecords)
{
Model.TrustCards!.Add(new ContentCardModel(record));
}
}
}
Model = await homePageReader.ReadLatestRecordWithModel(contentCardReader) ?? Defaults.DefaultHomePageContent;
var cacheOptions = new MemoryCacheEntryOptions()
.SetAbsoluteExpiration(TimeSpan.FromHours(24))
@@ -43,6 +19,5 @@ namespace ApplianceRepair.Components.Pages
cache.Set(nameof(HomePageModel), Model, cacheOptions);
}
}
}
}

View File

@@ -21,8 +21,8 @@ else
<h1>@Model.HeaderLine1 <br><span>@Model.HeaderLine2</span></h1>
<p>@Model.HeaderText</p>
<div class="cta-group">
<a href="@Model.HeaderButton1Link" class="btn btn-primary">@Model.HeaderButton1Text</a>
<a href="@Model.HeaderButton2Link" class="btn btn-secondary">@Model.HeaderButton2Text</a>
<a href="phone:@Model.FormattedPhoneNumber" class="btn btn-primary">Call for Same-Day Service</a>
<a href="/book" class="btn btn-secondary">Request an Appointment</a>
</div>
</div>
</header>

View File

@@ -0,0 +1,111 @@
@page "/admin/editpages"
@rendermode InteractiveServer
<div class="admin-wrapper">
<div class="container">
<header class="admin-header">
<h1>Page Content Management</h1>
<p>Update your business details and home page content below.</p>
</header>
@if (HomePageModel == null)
{
<div class="loading-state">
<div class="spinner"></div>
<p>Loading your settings...</p>
</div>
}
else
{
<div class="admin-wrapper">
<div class="container">
<header class="admin-header">
<div class="tab-container">
<button class="tab-btn @(currentTab == AdminTab.Home ? "active" : "")"
@onclick="() => currentTab = AdminTab.Home">
Home Page
</button>
</div>
</header>
@if (currentTab == AdminTab.Home)
{
<EditForm FormName="HomePageForm" Model="HomePageModel" OnValidSubmit="SaveHomePageModel" On class="admin-form home-page-form">
<DataAnnotationsValidator />
<div class="form-section text-center">
<h3><i class="icon">🏠</i> Hero Section</h3>
<div class="input-group">
<label>Main Headline</label>
<InputText @bind-Value="HomePageModel.HeaderLine1" class="form-input" />
</div>
<div class="input-group">
<label>Highlighted Text (Green)</label>
<InputText @bind-Value="HomePageModel.HeaderLine2" class="form-input" />
</div>
<div class="input-group">
<label>Description Text</label>
<InputTextArea @bind-Value="HomePageModel.HeaderText" class="form-input" rows="3" />
</div>
</div>
<div class="form-section text-center">
<h3><i class="icon">🛠️</i> Services</h3>
<div class="cards-grid">
@foreach (var card in HomePageModel.ServicesCards)
{
<div class="content-card">
<div class="input-group">
<label>Header</label>
<InputTextArea @bind-Value="card.Header" class="form-input" />
</div>
<div class="input-group">
<label>Text</label>
<InputTextArea @bind-Value="card.Text" class="form-input" />
</div>
</div>
}
</div>
<button type="button" class="btn btn-save" @onclick="AddServiceCard">Add Service Card</button>
</div>
<div class="form-section text-center">
<h3><i class="icon">🛡️</i> Trust</h3>
<div class="cards-grid">
@foreach (var card in HomePageModel.TrustCards)
{
<div class="content-card">
<div class="input-group">
<label>Header</label>
<InputTextArea @bind-Value="card.Header" class="form-input" />
</div>
<div class="input-group">
<label>Text</label>
<InputTextArea @bind-Value="card.Text" class="form-input" />
</div>
</div>
}
</div>
<button type="button" class="btn btn-save" @onclick="AddTrustCard">Add Trust Card</button>
</div>
<div class="admin-footer">
<button type="submit" class="btn btn-save">Save</button>
<button type="button" class="btn btn-revert" @onclick="RevertHomePageModel">Revert</button>
</div>
</EditForm>
}
else
{
<h1>Another page</h1>
}
</div>
</div>
}
</div>
</div>

View File

@@ -0,0 +1,64 @@
namespace ApplianceRepair.Components.Pages.admin
{
public partial class EditPages(HomePageReader homePageReader, ContentCardReader contentCardReader)
{
public HomePageModel? HomePageModel;
private enum AdminTab { Home, About }
private AdminTab currentTab = AdminTab.Home;
override
protected async void OnInitialized()
{
HomePageModel = await homePageReader.ReadLatestRecordWithModel(contentCardReader) ?? Defaults.DefaultHomePageContent;
}
private async void RevertHomePageModel()
{
HomePageModel = await homePageReader.ReadLatestRecordWithModel(contentCardReader) ?? Defaults.DefaultHomePageContent;
}
private async void SaveHomePageModel()
{
HomePageModel.CreatedAt = DateTime.Now;
HomePageModel.UpdatedAt = DateTime.Now;
foreach (var card in HomePageModel.ServicesCards)
{
await contentCardReader.UpdateRecord(card);
}
foreach (var card in HomePageModel.TrustCards)
{
await contentCardReader.UpdateRecord(card);
}
await homePageReader.AddRecord(HomePageModel);
}
private void AddServiceCard()
{
HomePageModel?.ServicesCards.Add(new ContentCardModel() {
CreatedAt = DateTime.Now,
UpdatedAt = DateTime.Now,
BelongsToPage = HomePageModel.PageName,
Group = HomePageModel.ContentCardTypes.Service.ToString(),
Header = "Service Name",
Text = "Short Description"
});
}
private async void AddTrustCard()
{
HomePageModel?.TrustCards.Add(new ContentCardModel()
{
CreatedAt = DateTime.Now,
UpdatedAt = DateTime.Now,
BelongsToPage = HomePageModel.PageName,
Group = HomePageModel.ContentCardTypes.Trust.ToString(),
Header = "Header",
Text = "Short Description"
});
}
}
}

View File

@@ -0,0 +1,240 @@
.admin-wrapper {
background-color: #f4f7f6;
min-height: 100vh;
padding: 60px 0;
font-family: 'Open Sans', sans-serif;
}
.admin-header {
text-align: center;
margin-bottom: 40px;
}
.admin-footer {
text-align: center;
}
.tab-container {
display: inline-flex;
background: #e0e6ed;
padding: 5px;
border-radius: 50px;
margin-top: 20px;
}
.tab-btn {
padding: 10px 25px;
border: none;
background: transparent;
font-family: 'Montserrat', sans-serif;
font-weight: 600;
cursor: pointer;
border-radius: 50px;
transition: all 0.3s ease;
color: #666;
}
.tab-btn.active {
background: #2a5298; /* Your Trust Blue */
color: white;
box-shadow: 0 4px 10px rgba(42, 82, 152, 0.2);
}
h1 {
font-family: 'Montserrat', sans-serif;
color: #2a5298;
font-weight: 700;
}
.form-section {
background: #fff;
padding: 100px;
border-radius: 15px;
box-shadow: 0 10px 30px rgba(0,0,0,0.05);
margin-bottom: 30px;
border: 1px solid #f0f0f0;
font-family: 'Montserrat', sans-serif;
}
.text-center {
text-align: center;
max-width: 70vw;
margin-left: auto;
margin-right: auto;
}
.form-section h3 {
color: #2a5298;
margin-bottom: 20px;
font-size: 1.2rem;
border-bottom: 2px solid #f4f7f6;
padding-bottom: 10px;
}
.input-group {
margin-bottom: 20px;
}
.input-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
}
label {
display: block;
font-family: 'Montserrat', sans-serif;
font-weight: 600;
font-size: 0.85rem;
text-transform: uppercase;
letter-spacing: 0.5px;
color: #2a5298;
margin-bottom: 8px;
margin-top: 15px;
}
.cards-grid {
display: flex;
flex-direction: row;
align-content: center;
justify-content: center;
column-gap: 2rem;
padding-top: 2rem;
padding-bottom: 2rem;
}
.content-card {
background: #fcfcfc;
border: 1px solid #e0e6ed;
border-radius: 12px;
padding: 20px;
transition: transform 0.2s ease;
display: flex;
flex-direction: column;
align-content: center;
}
.content-card:hover {
border-color: #2a5298;
box-shadow: 0 5px 15px rgba(0,0,0,0.05);
}
.content-card .input-group {
max-width: 100%;
display: flex;
flex-direction: column;
align-content: center;
}
.content-card ::deep .form-input {
max-width: 80%;
align-self: center;
}
::deep .form-input,
::deep textarea.form-input {
width: 100%;
padding: 14px 18px;
font-size: 1rem;
font-family: 'Open Sans', sans-serif;
color: #444;
background-color: #ffffff;
border: 2px solid #e0e6ed;
border-radius: 12px;
transition: all 0.2s ease-in-out;
display: block;
box-shadow: inset 0 1px 2px rgba(0,0,0,0.02);
}
::deep .form-input:focus,
::deep textarea.form-input:focus {
outline: none;
border-color: #2a5298;
background-color: #fff;
box-shadow: 0 0 0 4px rgba(42, 82, 152, 0.1);
}
::deep textarea.form-input {
min-height: 120px;
resize: vertical;
line-height: 1.5;
}
.btn-save {
background: #4CAF50;
color: white;
border: none;
padding: 15px 40px;
border-radius: 50px;
font-weight: 700;
cursor: pointer;
box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
transition: all 0.3s ease;
max-width: 10vw;
}
.btn-save:hover {
transform: translateY(-2px);
background: #43a047;
}
.btn-revert {
background: transparent;
color: #666;
border: 2px solid #ccc;
padding: 15px 30px;
border-radius: 50px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
margin-left: 10px;
max-width: 30vw;
}
.btn-revert:hover {
background: #eee;
color: #333;
border-color: #999;
}
.status-msg {
margin-left: 20px;
color: #4CAF50;
font-weight: 600;
animation: fadeIn 0.5s ease;
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@media (max-width: 768px) {
.input-row {
grid-template-columns: 1fr;
}
.btn-save {
max-width: 40vw;
}
.btn-revert {
max-width: 40vw;
}
.cards-grid {
flex-direction: column;
align-content: center;
justify-content: center;
row-gap: 2rem;
}
}

View File

@@ -44,4 +44,13 @@
public string? PhoneNumber { get; set; }
public string? SupportEmail { get; set; }
}
public class RepairRequestRecord
{
public string? Type { get; set; }
public string? Brand { get; set; }
public string? Notes { get; set; }
public string? Name { get; set; }
public string? Phone { get; set; }
}
}

View File

@@ -7,5 +7,6 @@ namespace ApplianceRepair
public DbSet<HomePageRecord> HomePage { get; set; }
public DbSet<ContentCardRecord> ContentCards { get; set; }
public DbSet<BusinessConfigRecord> BusinessConfig { get; set; }
public DbSet<RepairRequestRecord> RepairRequests { get; set; }
}
}

View File

@@ -1,124 +0,0 @@
// <auto-generated />
using System;
using ApplianceRepair;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace ApplianceRepair.Migrations
{
[DbContext(typeof(DatabaseContext))]
[Migration("20260202020516_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "9.0.12");
modelBuilder.Entity("ApplianceRepair.BusinessConfigRecord", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("PhoneNumber")
.HasColumnType("TEXT");
b.Property<string>("SupportEmail")
.HasColumnType("TEXT");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("BusinessConfig");
});
modelBuilder.Entity("ApplianceRepair.ContentCardRecord", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("BelongsToPage")
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Group")
.HasColumnType("TEXT");
b.Property<string>("Header")
.HasColumnType("TEXT");
b.Property<string>("Text")
.HasColumnType("TEXT");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("ContentCards");
});
modelBuilder.Entity("ApplianceRepair.HomePageRecord", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("CopyrightText")
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("HeaderButton1Link")
.HasColumnType("TEXT");
b.Property<string>("HeaderButton1Text")
.HasColumnType("TEXT");
b.Property<string>("HeaderButton2Link")
.HasColumnType("TEXT");
b.Property<string>("HeaderButton2Text")
.HasColumnType("TEXT");
b.Property<string>("HeaderLine1")
.HasColumnType("TEXT");
b.Property<string>("HeaderLine2")
.HasColumnType("TEXT");
b.Property<string>("HeaderText")
.HasColumnType("TEXT");
b.Property<string>("SecondaryHeaderText")
.HasColumnType("TEXT");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("HomePage");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,86 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ApplianceRepair.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "BusinessConfig",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: true),
PhoneNumber = table.Column<string>(type: "TEXT", nullable: true),
SupportEmail = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_BusinessConfig", x => x.Id);
});
migrationBuilder.CreateTable(
name: "ContentCards",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
BelongsToPage = table.Column<string>(type: "TEXT", nullable: true),
Group = table.Column<string>(type: "TEXT", nullable: true),
Header = table.Column<string>(type: "TEXT", nullable: true),
Text = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ContentCards", x => x.Id);
});
migrationBuilder.CreateTable(
name: "HomePage",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
HeaderLine1 = table.Column<string>(type: "TEXT", nullable: true),
HeaderLine2 = table.Column<string>(type: "TEXT", nullable: true),
HeaderText = table.Column<string>(type: "TEXT", nullable: true),
HeaderButton1Text = table.Column<string>(type: "TEXT", nullable: true),
HeaderButton2Text = table.Column<string>(type: "TEXT", nullable: true),
HeaderButton1Link = table.Column<string>(type: "TEXT", nullable: true),
HeaderButton2Link = table.Column<string>(type: "TEXT", nullable: true),
SecondaryHeaderText = table.Column<string>(type: "TEXT", nullable: true),
CopyrightText = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_HomePage", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "BusinessConfig");
migrationBuilder.DropTable(
name: "ContentCards");
migrationBuilder.DropTable(
name: "HomePage");
}
}
}

View File

@@ -1,121 +0,0 @@
// <auto-generated />
using System;
using ApplianceRepair;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace ApplianceRepair.Migrations
{
[DbContext(typeof(DatabaseContext))]
partial class DatabaseContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "9.0.12");
modelBuilder.Entity("ApplianceRepair.BusinessConfigRecord", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("PhoneNumber")
.HasColumnType("TEXT");
b.Property<string>("SupportEmail")
.HasColumnType("TEXT");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("BusinessConfig");
});
modelBuilder.Entity("ApplianceRepair.ContentCardRecord", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("BelongsToPage")
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Group")
.HasColumnType("TEXT");
b.Property<string>("Header")
.HasColumnType("TEXT");
b.Property<string>("Text")
.HasColumnType("TEXT");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("ContentCards");
});
modelBuilder.Entity("ApplianceRepair.HomePageRecord", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("CopyrightText")
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("HeaderButton1Link")
.HasColumnType("TEXT");
b.Property<string>("HeaderButton1Text")
.HasColumnType("TEXT");
b.Property<string>("HeaderButton2Link")
.HasColumnType("TEXT");
b.Property<string>("HeaderButton2Text")
.HasColumnType("TEXT");
b.Property<string>("HeaderLine1")
.HasColumnType("TEXT");
b.Property<string>("HeaderLine2")
.HasColumnType("TEXT");
b.Property<string>("HeaderText")
.HasColumnType("TEXT");
b.Property<string>("SecondaryHeaderText")
.HasColumnType("TEXT");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("HomePage");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -21,6 +21,13 @@
public class HomePageModel : HomePageRecord
{
public static string PageName = "Home";
public enum ContentCardTypes
{
Service,
Trust,
}
public string BusinessName { get; set; }
public string FormattedPhoneNumber { get; set; }
public string PhoneNumberCallLink { get; set; }
@@ -69,7 +76,7 @@
}
}
public class BusinessConfig : BusinessConfigRecord
public class RepairRequestModel : RepairRequestRecord
{
}

View File

@@ -26,7 +26,6 @@ using (var scope = app.Services.CreateScope())
try
{
services.GetRequiredService<DatabaseContext>().Database.EnsureCreated();
services.GetRequiredService<DatabaseContext>().Database
}
catch (Exception ex)
{

View File

@@ -6,7 +6,40 @@ namespace ApplianceRepair
{
public async Task<HomePageRecord?> ReadLatestRecord()
{
return await db.HomePage.OrderByDescending(page => page.Id).FirstAsync();
var records = await db.HomePage.OrderByDescending(page => page.Id).FirstOrDefaultAsync();
return records;
}
public async Task<HomePageModel?> ReadLatestRecordWithModel(ContentCardReader contentCardReader)
{
var record = await db.HomePage.OrderByDescending(page => page.Id).FirstOrDefaultAsync();
if (record == null)
{
return null;
}
var model = new HomePageModel(record);
var pageName = HomePageModel.PageName;
var services = await contentCardReader.ReadAllByPageAndGroup(pageName, HomePageModel.ContentCardTypes.Service.ToString()) ?? [];
foreach (var card in services)
{
model.ServicesCards.Add(new ContentCardModel(card));
}
var trust = await contentCardReader.ReadAllByPageAndGroup(pageName, HomePageModel.ContentCardTypes.Trust.ToString()) ?? [];
foreach (var card in trust)
{
model.TrustCards.Add(new ContentCardModel(card));
}
return model;
}
public async Task AddRecord(HomePageRecord record)
{
await db.AddAsync(record);
await db.SaveChangesAsync();
}
}
@@ -21,6 +54,25 @@ namespace ApplianceRepair
{
return await db.ContentCards.Where(card => card.BelongsToPage == belongsToPage).ToListAsync();
}
public async Task AddRecord(ContentCardRecord record)
{
await db.ContentCards.AddAsync(record);
}
public async Task UpdateRecord(ContentCardRecord record)
{
var found = db.ContentCards.Where((card) => card.Id == record.Id).FirstOrDefault();
if (found == null)
{
await AddRecord(record);
}
else
{
db.ContentCards.Update(record);
}
await db.SaveChangesAsync();
}
}
public class BusinessConfigReader(DatabaseContext db)