f97f891d67
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>
58 lines
1.9 KiB
C#
58 lines
1.9 KiB
C#
using AsadiTools.Data;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
|
|
namespace AsadiTools.Pages.Admin.Products;
|
|
|
|
[Authorize(AuthenticationSchemes = "AdminCookie")]
|
|
public class EditModel(AppDbContext db) : PageModel
|
|
{
|
|
[BindProperty] public ProductInput Input { get; set; } = new();
|
|
public int ProductId { get; private set; }
|
|
|
|
public async Task<IActionResult> OnGetAsync(int id)
|
|
{
|
|
var p = await db.Products.FindAsync(id);
|
|
if (p is null) return NotFound();
|
|
ProductId = id;
|
|
Input = new ProductInput
|
|
{
|
|
NameFa = p.NameFa,
|
|
NameEn = p.NameEn,
|
|
Description = p.Description,
|
|
Price = p.Price,
|
|
DiscountPrice = p.DiscountPrice,
|
|
Category = p.Category,
|
|
Brand = p.Brand,
|
|
Sku = p.Sku,
|
|
Stock = p.Stock,
|
|
IsActive = p.IsActive,
|
|
ImageUrl = p.ImageUrl,
|
|
};
|
|
return Page();
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostAsync(int id)
|
|
{
|
|
if (!ModelState.IsValid) { ProductId = id; return Page(); }
|
|
var p = await db.Products.FindAsync(id);
|
|
if (p is null) return NotFound();
|
|
|
|
p.NameFa = Input.NameFa;
|
|
p.NameEn = Input.NameEn;
|
|
p.Description = Input.Description;
|
|
p.Price = Input.Price;
|
|
p.DiscountPrice = Input.DiscountPrice;
|
|
p.Category = Input.Category;
|
|
p.Brand = string.IsNullOrEmpty(Input.Brand) ? null : Input.Brand;
|
|
p.Sku = Input.Sku;
|
|
p.Stock = Input.Stock;
|
|
p.IsActive = Input.IsActive;
|
|
p.ImageUrl = string.IsNullOrWhiteSpace(Input.ImageUrl) ? null : Input.ImageUrl;
|
|
|
|
await db.SaveChangesAsync();
|
|
return RedirectToPage("/Admin/Products/Index");
|
|
}
|
|
}
|