Initial commit — AsadiTools v1.0
Full ASP.NET Core 10 Razor Pages app for آساد ابزار tool repair shop in Karaj, Iran (official DeWalt representative). Features: - Homepage, Services, DeWalt page, Shop (pagination + images) - 10 brand SEO pages (/brands/*) with rich Persian content + FAQ schema - Blog engine with admin management (/blog, /Admin/Blog) - Cart, Checkout, Contact (OpenStreetMap embed) - Admin panel: Products CRUD, Orders, Blog, Change Password - Jalali date formatting, product images, SiteData centralised contact - Docker + docker-compose with healthcheck - Gitea CI/CD via .gitea/workflows/ci-cd.yml (NuGet through Nexus mirror) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
@page
|
||||
@model AsadiTools.Pages.Shop.DetailModel
|
||||
@{ ViewData["Title"] = Model.Product?.NameFa ?? "قطعه"; Layout = "_Layout"; }
|
||||
|
||||
@if (Model.Product is null)
|
||||
{
|
||||
<div class="max-w-xl mx-auto text-center py-20"><p class="text-gray-500">محصول یافت نشد.</p><a href="/Shop" class="text-blue-600 hover:underline mt-2 block">بازگشت به فروشگاه</a></div>
|
||||
}
|
||||
else
|
||||
{
|
||||
var p = Model.Product;
|
||||
var cat = SiteData.Categories.FirstOrDefault(c => c.Id == p.Category);
|
||||
var brand = SiteData.Brands.FirstOrDefault(b => b.Id == p.Brand);
|
||||
|
||||
<div class="max-w-5xl mx-auto px-4 py-8">
|
||||
<nav class="flex items-center gap-2 text-sm text-gray-500 mb-8">
|
||||
<a href="/" class="hover:text-blue-600">خانه</a><span>/</span>
|
||||
<a href="/Shop" class="hover:text-blue-600">فروشگاه</a><span>/</span>
|
||||
<span class="text-gray-800">@p.NameFa</span>
|
||||
</nav>
|
||||
|
||||
<div class="grid md:grid-cols-2 gap-10">
|
||||
<div class="rounded-3xl overflow-hidden aspect-square @(string.IsNullOrEmpty(p.ImageUrl) ? "bg-gradient-to-br from-blue-50 to-blue-100 flex items-center justify-center text-8xl" : "")">
|
||||
@if (!string.IsNullOrEmpty(p.ImageUrl))
|
||||
{
|
||||
<img src="@p.ImageUrl" alt="@p.NameFa" class="w-full h-full object-cover" />
|
||||
}
|
||||
else
|
||||
{
|
||||
@(cat?.Icon ?? "🔧")
|
||||
}
|
||||
</div>
|
||||
<div>
|
||||
<div class="flex flex-wrap gap-2 mb-4">
|
||||
@if (brand != null) { <span class="text-sm font-bold px-3 py-1 rounded-full text-white" style="background-color:@brand.Color">@brand.NameFa</span> }
|
||||
@if (cat != null) { <span class="text-sm px-3 py-1 rounded-full bg-gray-100 text-gray-600">@cat.Icon @cat.NameFa</span> }
|
||||
</div>
|
||||
<h1 class="text-2xl font-extrabold text-gray-900 mb-2">@p.NameFa</h1>
|
||||
@if (p.NameEn != null) { <p class="text-gray-400 text-sm mb-4 font-mono">@p.NameEn</p> }
|
||||
@if (p.Sku != null) { <p class="text-xs text-gray-400 mb-6 bg-gray-100 inline-block px-3 py-1 rounded-full">کد محصول: @p.Sku</p> }
|
||||
@if (p.Description != null) { <p class="text-gray-600 leading-7 mb-6 text-sm">@p.Description</p> }
|
||||
|
||||
<div class="mb-6">
|
||||
@if (p.HasDiscount) { <p class="text-gray-400 line-through text-lg">@SiteData.FormatPrice(p.Price)</p> }
|
||||
<p class="text-3xl font-extrabold text-blue-700">@SiteData.FormatPrice(p.FinalPrice)</p>
|
||||
</div>
|
||||
|
||||
<div class="mb-6">
|
||||
@if (p.Stock > 0)
|
||||
{
|
||||
<span class="text-green-600 text-sm font-medium">🟢 موجود در انبار (@p.Stock عدد)</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-red-500 text-sm font-medium">🔴 ناموجود</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
<form method="post" class="flex gap-3">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="productId" value="@p.Id" />
|
||||
<input type="hidden" name="nameFa" value="@p.NameFa" />
|
||||
<input type="hidden" name="price" value="@p.FinalPrice" />
|
||||
<input type="hidden" name="sku" value="@p.Sku" />
|
||||
<button type="submit" @(p.Stock == 0 ? "disabled" : "")
|
||||
class="flex-1 flex items-center justify-center gap-2 bg-blue-700 text-white py-3.5 rounded-xl font-bold hover:bg-blue-800 transition-colors disabled:bg-gray-200 disabled:text-gray-400">
|
||||
🛒 @(p.Stock == 0 ? "ناموجود" : "افزودن به سبد خرید")
|
||||
</button>
|
||||
<a href="/Cart" class="flex items-center gap-2 border-2 border-blue-700 text-blue-700 py-3.5 px-4 rounded-xl font-bold hover:bg-blue-50">سبد</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using AsadiTools.Data;
|
||||
using AsadiTools.Models;
|
||||
using AsadiTools.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace AsadiTools.Pages.Shop;
|
||||
|
||||
public class DetailModel(AppDbContext db, CartService cart) : PageModel
|
||||
{
|
||||
public Product? Product { get; private set; }
|
||||
|
||||
public async Task OnGetAsync(int id)
|
||||
{
|
||||
Product = await db.Products.FindAsync(id);
|
||||
}
|
||||
|
||||
public IActionResult OnPost(int productId, string nameFa, decimal price, string? sku)
|
||||
{
|
||||
cart.AddItem(new CartItem { ProductId = productId, NameFa = nameFa, Price = price, Sku = sku, Qty = 1 });
|
||||
return RedirectToPage("/Cart/Index");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
@page
|
||||
@model AsadiTools.Pages.Shop.ShopIndexModel
|
||||
@{ ViewData["Title"] = "فروشگاه قطعات یدکی ابزار برقی"; Layout = "_Layout"; }
|
||||
|
||||
<div class="bg-blue-800 text-white py-10 px-4">
|
||||
<div class="max-w-6xl mx-auto">
|
||||
<h1 class="text-3xl font-extrabold mb-2">فروشگاه قطعات یدکی</h1>
|
||||
<p class="text-blue-200">قطعات اصل ابزار برقی صنعتی با گارانتی</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="max-w-6xl mx-auto px-4 py-8">
|
||||
<!-- Filters -->
|
||||
<div class="bg-white rounded-2xl border border-gray-100 p-5 mb-8">
|
||||
<form method="get" class="mb-5">
|
||||
<input type="text" name="search" value="@Model.Search" placeholder="جستجو در قطعات..."
|
||||
class="w-full border border-gray-200 rounded-xl px-4 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500" />
|
||||
</form>
|
||||
|
||||
<div class="mb-4">
|
||||
<p class="text-xs text-gray-500 font-bold mb-2">دستهبندی</p>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<a href="/Shop" class="text-sm px-3 py-1.5 rounded-full border transition-colors @(Model.Category == null ? "bg-blue-700 text-white border-blue-700" : "border-gray-200 text-gray-600 hover:border-blue-400")">همه</a>
|
||||
@foreach (var cat in SiteData.Categories)
|
||||
{
|
||||
<a href="/Shop?category=@cat.Id@(Model.Brand != null ? "&brand=" + Model.Brand : "")"
|
||||
class="text-sm px-3 py-1.5 rounded-full border transition-colors @(Model.Category == cat.Id ? "bg-blue-700 text-white border-blue-700" : "border-gray-200 text-gray-600 hover:border-blue-400")">
|
||||
@cat.Icon @cat.NameFa
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="text-xs text-gray-500 font-bold mb-2">برند</p>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<a href="/Shop@(Model.Category != null ? "?category=" + Model.Category : "")"
|
||||
class="text-sm px-3 py-1.5 rounded-full border transition-colors @(Model.Brand == null ? "bg-blue-700 text-white border-blue-700" : "border-gray-200 text-gray-600 hover:border-blue-400")">همه برندها</a>
|
||||
@foreach (var brand in SiteData.Brands)
|
||||
{
|
||||
<a href="/Shop?brand=@brand.Id@(Model.Category != null ? "&category=" + Model.Category : "")"
|
||||
class="text-sm px-3 py-1.5 rounded-full border transition-colors @(Model.Brand == brand.Id ? "bg-blue-700 text-white border-blue-700" : "border-gray-200 text-gray-600 hover:border-blue-400")">
|
||||
@brand.NameFa
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="text-sm text-gray-500 mb-5">@Model.TotalCount محصول یافت شد</p>
|
||||
|
||||
@if (!Model.Products.Any())
|
||||
{
|
||||
<div class="text-center py-20 text-gray-400">
|
||||
<div class="text-5xl mb-4">🔍</div>
|
||||
<p>محصولی یافت نشد</p>
|
||||
<a href="/Shop" class="text-blue-600 text-sm mt-2 hover:underline block">مشاهده همه محصولات</a>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-5">
|
||||
@foreach (var p in Model.Products)
|
||||
{
|
||||
var cat = SiteData.Categories.FirstOrDefault(c => c.Id == p.Category);
|
||||
var brand = SiteData.Brands.FirstOrDefault(b => b.Id == p.Brand);
|
||||
<div class="bg-white rounded-xl shadow-sm border border-gray-100 hover:shadow-md transition-shadow flex flex-col">
|
||||
@if (!string.IsNullOrEmpty(p.ImageUrl))
|
||||
{
|
||||
<div class="rounded-t-xl overflow-hidden" style="height:160px">
|
||||
<img src="@p.ImageUrl" alt="@p.NameFa" loading="lazy"
|
||||
class="w-full h-full object-cover"
|
||||
onerror="this.parentElement.innerHTML='<div class=\'bg-gradient-to-br from-blue-50 to-blue-100 h-full flex items-center justify-center text-5xl\'>@(cat?.Icon ?? "🔧")</div>'" />
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="bg-gradient-to-br from-blue-50 to-blue-100 rounded-t-xl p-8 flex items-center justify-center text-5xl">
|
||||
@(cat?.Icon ?? "🔧")
|
||||
</div>
|
||||
}
|
||||
<div class="p-4 flex flex-col flex-1 gap-3">
|
||||
<div class="flex flex-wrap gap-1.5">
|
||||
@if (brand != null) { <span class="text-xs font-bold px-2 py-0.5 rounded-full text-white" style="background-color:@brand.Color">@brand.NameFa</span> }
|
||||
@if (cat != null) { <span class="text-xs px-2 py-0.5 rounded-full bg-gray-100 text-gray-600">@cat.NameFa</span> }
|
||||
@if (p.Stock == 0) { <span class="text-xs px-2 py-0.5 rounded-full bg-red-100 text-red-600">ناموجود</span> }
|
||||
</div>
|
||||
<div>
|
||||
<a href="/Shop/Detail?id=@p.Id" class="font-bold text-gray-900 hover:text-blue-700 transition-colors leading-snug block">@p.NameFa</a>
|
||||
@if (p.Sku != null) { <p class="text-xs text-gray-400 mt-0.5">کد: @p.Sku</p> }
|
||||
</div>
|
||||
<div class="mt-auto">
|
||||
@if (p.HasDiscount) { <p class="text-sm text-gray-400 line-through">@SiteData.FormatPrice(p.Price)</p> }
|
||||
<p class="text-lg font-bold text-blue-700">@SiteData.FormatPrice(p.FinalPrice)</p>
|
||||
</div>
|
||||
<form method="post" asp-page-handler="AddToCart">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="productId" value="@p.Id" />
|
||||
<input type="hidden" name="nameFa" value="@p.NameFa" />
|
||||
<input type="hidden" name="price" value="@p.FinalPrice" />
|
||||
<input type="hidden" name="sku" value="@p.Sku" />
|
||||
<button type="submit" @(p.Stock == 0 ? "disabled" : "")
|
||||
class="w-full flex items-center justify-center gap-2 bg-blue-700 text-white py-2.5 rounded-lg text-sm font-medium hover:bg-blue-800 transition-colors disabled:bg-gray-200 disabled:text-gray-400 disabled:cursor-not-allowed">
|
||||
🛒 @(p.Stock == 0 ? "ناموجود" : "افزودن به سبد")
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (Model.TotalPages > 1)
|
||||
{
|
||||
<div class="flex justify-center items-center gap-2 mt-10">
|
||||
@if (Model.CurrentPage > 1)
|
||||
{
|
||||
<a href="/Shop?page=@(Model.CurrentPage - 1)@(Model.Category != null ? "&category=" + Model.Category : "")@(Model.Brand != null ? "&brand=" + Model.Brand : "")@(Model.Search != null ? "&search=" + Model.Search : "")"
|
||||
class="px-4 py-2 rounded-xl border border-gray-200 text-sm text-gray-600 hover:border-blue-400 hover:text-blue-700 transition-colors">
|
||||
‹ قبلی
|
||||
</a>
|
||||
}
|
||||
@for (var i = Math.Max(1, Model.CurrentPage - 2); i <= Math.Min(Model.TotalPages, Model.CurrentPage + 2); i++)
|
||||
{
|
||||
<a href="/Shop?page=@i@(Model.Category != null ? "&category=" + Model.Category : "")@(Model.Brand != null ? "&brand=" + Model.Brand : "")@(Model.Search != null ? "&search=" + Model.Search : "")"
|
||||
class="px-4 py-2 rounded-xl border text-sm transition-colors @(i == Model.CurrentPage ? "bg-blue-700 text-white border-blue-700" : "border-gray-200 text-gray-600 hover:border-blue-400 hover:text-blue-700")">
|
||||
@i
|
||||
</a>
|
||||
}
|
||||
@if (Model.CurrentPage < Model.TotalPages)
|
||||
{
|
||||
<a href="/Shop?page=@(Model.CurrentPage + 1)@(Model.Category != null ? "&category=" + Model.Category : "")@(Model.Brand != null ? "&brand=" + Model.Brand : "")@(Model.Search != null ? "&search=" + Model.Search : "")"
|
||||
class="px-4 py-2 rounded-xl border border-gray-200 text-sm text-gray-600 hover:border-blue-400 hover:text-blue-700 transition-colors">
|
||||
بعدی ›
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -0,0 +1,48 @@
|
||||
using AsadiTools.Data;
|
||||
using AsadiTools.Models;
|
||||
using AsadiTools.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AsadiTools.Pages.Shop;
|
||||
|
||||
public class ShopIndexModel(AppDbContext db, CartService cart) : PageModel
|
||||
{
|
||||
public const int PageSize = 12;
|
||||
|
||||
public List<Product> Products { get; private set; } = [];
|
||||
public string? Category { get; private set; }
|
||||
public string? Brand { get; private set; }
|
||||
public string? Search { get; private set; }
|
||||
public int CurrentPage { get; private set; } = 1;
|
||||
public int TotalPages { get; private set; }
|
||||
public int TotalCount { get; private set; }
|
||||
|
||||
public async Task OnGetAsync(string? category, string? brand, string? search, int page = 1)
|
||||
{
|
||||
Category = category;
|
||||
Brand = brand;
|
||||
Search = search;
|
||||
|
||||
var q = db.Products.Where(p => p.IsActive);
|
||||
if (category is not null) q = q.Where(p => p.Category == category);
|
||||
if (brand is not null) q = q.Where(p => p.Brand == brand);
|
||||
if (search is not null) q = q.Where(p => p.NameFa.Contains(search) || (p.NameEn != null && p.NameEn.Contains(search)) || (p.Sku != null && p.Sku.Contains(search)));
|
||||
|
||||
TotalCount = await q.CountAsync();
|
||||
TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);
|
||||
CurrentPage = Math.Clamp(page, 1, Math.Max(1, TotalPages));
|
||||
|
||||
Products = await q.OrderByDescending(p => p.Id)
|
||||
.Skip((CurrentPage - 1) * PageSize)
|
||||
.Take(PageSize)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public IActionResult OnPostAddToCart(int productId, string nameFa, decimal price, string? sku)
|
||||
{
|
||||
cart.AddItem(new CartItem { ProductId = productId, NameFa = nameFa, Price = price, Sku = sku, Qty = 1 });
|
||||
return RedirectToPage();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user