Files
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

72 lines
2.2 KiB
C#

using AsadiTools.Data;
using AsadiTools.Models;
using AsadiTools.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.ComponentModel.DataAnnotations;
namespace AsadiTools.Pages.Checkout;
public class CheckoutIndexModel(AppDbContext db, CartService cart) : PageModel
{
[BindProperty]
public InputModel Input { get; set; } = new();
public List<CartItem> CartItems { get; private set; } = [];
public string? OrderNumber { get; private set; }
public string? ErrorMessage { get; private set; }
public class InputModel
{
[Required(ErrorMessage = "نام الزامی است")]
public string CustomerName { get; set; } = string.Empty;
[Required(ErrorMessage = "شماره موبایل الزامی است")]
public string CustomerPhone { get; set; } = string.Empty;
public string? CustomerAddress { get; set; }
public string? Notes { get; set; }
}
public IActionResult OnGet()
{
CartItems = cart.GetItems();
if (!CartItems.Any()) return RedirectToPage("/Shop/Index");
return Page();
}
public async Task<IActionResult> OnPostAsync()
{
CartItems = cart.GetItems();
if (!CartItems.Any()) return RedirectToPage("/Shop/Index");
if (!ModelState.IsValid) return Page();
var orderNumber = $"ORD-{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}";
var order = new Order
{
OrderNumber = orderNumber,
CustomerName = Input.CustomerName,
CustomerPhone = Input.CustomerPhone,
CustomerAddress = Input.CustomerAddress,
Notes = Input.Notes,
Items = CartItems.Select(i => new OrderItem
{
ProductId = i.ProductId,
ProductNameFa = i.NameFa,
Price = i.Price,
Quantity = i.Qty,
}).ToList(),
};
order.Subtotal = order.Items.Sum(i => i.Subtotal);
order.Total = order.Subtotal;
db.Orders.Add(order);
await db.SaveChangesAsync();
cart.Clear();
OrderNumber = orderNumber;
return Page();
}
}