- ASP.NET Core 8 REST API server - 12 API endpoints matching EA Synergy protocol - SQLite database with Entity Framework Core - Web admin panel with Bootstrap 5 - User, Catalog, Session, Purchase management - Comprehensive documentation Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
53 lines
1.4 KiB
C#
53 lines
1.4 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using RR3CommunityServer.Data;
|
|
using static RR3CommunityServer.Data.RR3DbContext;
|
|
|
|
namespace RR3CommunityServer.Pages;
|
|
|
|
public class PurchasesModel : PageModel
|
|
{
|
|
private readonly RR3DbContext _context;
|
|
|
|
public PurchasesModel(RR3DbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public List<Purchase> Purchases { get; set; } = new();
|
|
public decimal TotalValue { get; set; }
|
|
public string? SearchQuery { get; set; }
|
|
|
|
public async Task OnGetAsync(string? search)
|
|
{
|
|
SearchQuery = search;
|
|
|
|
var query = _context.Purchases.AsQueryable();
|
|
|
|
if (!string.IsNullOrEmpty(search))
|
|
{
|
|
query = query.Where(p => p.Sku.Contains(search) ||
|
|
(p.UserId != null && p.UserId.ToString()!.Contains(search)));
|
|
}
|
|
|
|
Purchases = await query
|
|
.OrderByDescending(p => p.PurchaseDate)
|
|
.ToListAsync();
|
|
|
|
TotalValue = Purchases.Sum(p => p.Price);
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostDeleteAsync(int purchaseId)
|
|
{
|
|
var purchase = await _context.Purchases.FindAsync(purchaseId);
|
|
if (purchase != null)
|
|
{
|
|
_context.Purchases.Remove(purchase);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
return RedirectToPage();
|
|
}
|
|
}
|