Files
abzarasadi/Pages/Admin/Products/Edit.cshtml.cs
T
Soroush Asadi f97f891d67
CI/CD / CI — dotnet build (push) Successful in 44s
CI/CD / Deploy — docker compose (push) Failing after 1s
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>
2026-06-01 22:08:43 +03:30

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");
}
}