From 2e59f4d8ed2e33b297cdd539302ee4411618f254 Mon Sep 17 00:00:00 2001 From: Khwezi Mngoma Date: Wed, 20 May 2026 17:47:53 +0200 Subject: [PATCH 1/2] Fixed input model attributes --- ShopAdmin/Components/CreateProduct.razor | 1 + ShopAdmin/Components/CreateProduct.razor.cs | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ShopAdmin/Components/CreateProduct.razor b/ShopAdmin/Components/CreateProduct.razor index 227a2f9..ea6b2bd 100644 --- a/ShopAdmin/Components/CreateProduct.razor +++ b/ShopAdmin/Components/CreateProduct.razor @@ -93,6 +93,7 @@
+ @if (string.IsNullOrEmpty(ProductModel.ImageUrl)) { diff --git a/ShopAdmin/Components/CreateProduct.razor.cs b/ShopAdmin/Components/CreateProduct.razor.cs index a8b7565..8f75892 100644 --- a/ShopAdmin/Components/CreateProduct.razor.cs +++ b/ShopAdmin/Components/CreateProduct.razor.cs @@ -8,7 +8,6 @@ public partial class CreateProduct([FromKeyedServices(BookshopBucketName)] IS3Se private bool isCalendarOpen = false; private DateTime calendarViewingMonth = DateTime.Today; private List calendarDays = new(); - private string currentCalendarMonthYearText => calendarViewingMonth.ToString("MMMM yyyy"); private readonly CancellationTokenSource cancellationTokenSource = new(); private CancellationToken cancellationToken; @@ -189,27 +188,33 @@ public partial class CreateProduct([FromKeyedServices(BookshopBucketName)] IS3Se public class CreateProductModel { + [MaxLength(128)] [Required(ErrorMessage = "Product name is required.")] public string? Name { get; set; } + [MaxLength(512)] [Required(ErrorMessage = "Summary is required.")] public string? Summary { get; set; } + [MaxLength(2048)] [Required(ErrorMessage = "Description is required.")] public string? Description { get; set; } [Range(0.01, double.MaxValue, ErrorMessage = "Price must be greater than zero.")] public decimal Price { get; set; } + [MaxLength(128)] [Required(ErrorMessage = "Author metadata is required.")] public string? Author { get; set; } [Required(ErrorMessage = "Publication Date is required.")] public DateTime PublishDate { get; set; } = DateTime.Today; + [MaxLength(255)] [Required(ErrorMessage = "Copyright Information field is required.")] public string? CopyrightInfo { get; set; } + [MaxLength(128)] [Required(ErrorMessage = "ISBN code is required.")] [RegularExpression(@"^(?=(?:\D*\d){10}(?:(?:\D*\d){3})?$)[\d-]+$", ErrorMessage = "Please enter a valid ISBN-10 or ISBN-13 string.")] public string? Isbn { get; set; } From 0d3bd525813d7e8184d79d9f5faaf1fef2f13ff7 Mon Sep 17 00:00:00 2001 From: Khwezi Mngoma Date: Wed, 20 May 2026 21:18:41 +0200 Subject: [PATCH 2/2] Moved CreateProductModel to shared Features library --- ShopAdmin/Components/CreateProduct.razor.cs | 40 +-------------------- ShopAdmin/ShopAdmin.csproj | 2 +- 2 files changed, 2 insertions(+), 40 deletions(-) diff --git a/ShopAdmin/Components/CreateProduct.razor.cs b/ShopAdmin/Components/CreateProduct.razor.cs index 8f75892..87cbfa6 100644 --- a/ShopAdmin/Components/CreateProduct.razor.cs +++ b/ShopAdmin/Components/CreateProduct.razor.cs @@ -1,4 +1,5 @@ using LiteCharms.Features.S3.Abstractions; +using LiteCharms.Features.Shop.Products.Models; using static LiteCharms.Features.S3.Constants; namespace ShopAdmin.Components; @@ -184,43 +185,4 @@ public partial class CreateProduct([FromKeyedServices(BookshopBucketName)] IS3Se isCalendarOpen = false; // Collapse popup smoothly on successful selection StateHasChanged(); } -} - -public class CreateProductModel -{ - [MaxLength(128)] - [Required(ErrorMessage = "Product name is required.")] - public string? Name { get; set; } - - [MaxLength(512)] - [Required(ErrorMessage = "Summary is required.")] - public string? Summary { get; set; } - - [MaxLength(2048)] - [Required(ErrorMessage = "Description is required.")] - public string? Description { get; set; } - - [Range(0.01, double.MaxValue, ErrorMessage = "Price must be greater than zero.")] - public decimal Price { get; set; } - - [MaxLength(128)] - [Required(ErrorMessage = "Author metadata is required.")] - public string? Author { get; set; } - - [Required(ErrorMessage = "Publication Date is required.")] - public DateTime PublishDate { get; set; } = DateTime.Today; - - [MaxLength(255)] - [Required(ErrorMessage = "Copyright Information field is required.")] - public string? CopyrightInfo { get; set; } - - [MaxLength(128)] - [Required(ErrorMessage = "ISBN code is required.")] - [RegularExpression(@"^(?=(?:\D*\d){10}(?:(?:\D*\d){3})?$)[\d-]+$", ErrorMessage = "Please enter a valid ISBN-10 or ISBN-13 string.")] - public string? Isbn { get; set; } - - [Required(ErrorMessage = "Primary image is required.")] - public string? ImageUrl { get; set; } - - public List Thumbnails { get; set; } = []; } \ No newline at end of file diff --git a/ShopAdmin/ShopAdmin.csproj b/ShopAdmin/ShopAdmin.csproj index 7ec4ff7..dadf1c8 100644 --- a/ShopAdmin/ShopAdmin.csproj +++ b/ShopAdmin/ShopAdmin.csproj @@ -16,7 +16,7 @@ - +