- 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>
107 lines
3.2 KiB
C#
107 lines
3.2 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace RR3CommunityServer.Data;
|
|
|
|
public class RR3DbContext : DbContext
|
|
{
|
|
public RR3DbContext(DbContextOptions<RR3DbContext> options) : base(options) { }
|
|
|
|
public DbSet<Device> Devices { get; set; }
|
|
public DbSet<User> Users { get; set; }
|
|
public DbSet<Session> Sessions { get; set; }
|
|
public DbSet<Purchase> Purchases { get; set; }
|
|
public DbSet<CatalogItem> CatalogItems { get; set; }
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
// Seed some default catalog items
|
|
modelBuilder.Entity<CatalogItem>().HasData(
|
|
new CatalogItem
|
|
{
|
|
Id = 1,
|
|
Sku = "com.ea.rr3.gold_1000",
|
|
Name = "1000 Gold",
|
|
Type = "currency",
|
|
Price = 0.99m,
|
|
Available = true
|
|
},
|
|
new CatalogItem
|
|
{
|
|
Id = 2,
|
|
Sku = "com.ea.rr3.car_tier1",
|
|
Name = "Starter Car",
|
|
Type = "car",
|
|
Price = 0m,
|
|
Available = true
|
|
},
|
|
new CatalogItem
|
|
{
|
|
Id = 3,
|
|
Sku = "com.ea.rr3.upgrade_engine",
|
|
Name = "Engine Upgrade",
|
|
Type = "upgrade",
|
|
Price = 4.99m,
|
|
Available = true
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
// Database entities
|
|
public class Device
|
|
{
|
|
public int Id { get; set; }
|
|
public string DeviceId { get; set; } = string.Empty;
|
|
public string HardwareId { get; set; } = string.Empty;
|
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
|
public DateTime LastSeenAt { get; set; } = DateTime.UtcNow;
|
|
}
|
|
|
|
public class User
|
|
{
|
|
public int Id { get; set; }
|
|
public string SynergyId { get; set; } = string.Empty;
|
|
public string? DeviceId { get; set; }
|
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
|
public string? Nickname { get; set; }
|
|
}
|
|
|
|
public class Session
|
|
{
|
|
public int Id { get; set; }
|
|
public string SessionId { get; set; } = string.Empty;
|
|
public string? SynergyId { get; set; }
|
|
public string DeviceId { get; set; } = string.Empty;
|
|
public int? UserId { get; set; }
|
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
|
public DateTime ExpiresAt { get; set; }
|
|
}
|
|
|
|
public class Purchase
|
|
{
|
|
public int Id { get; set; }
|
|
public string SynergyId { get; set; } = string.Empty;
|
|
public string ItemId { get; set; } = string.Empty;
|
|
public string Sku { get; set; } = string.Empty;
|
|
public string OrderId { get; set; } = string.Empty;
|
|
public DateTime PurchaseTime { get; set; } = DateTime.UtcNow;
|
|
public string Token { get; set; } = string.Empty;
|
|
public decimal Price { get; set; }
|
|
public string Status { get; set; } = "approved";
|
|
// For web panel display
|
|
public int? UserId { get; set; }
|
|
public DateTime PurchaseDate => PurchaseTime;
|
|
}
|
|
|
|
public class CatalogItem
|
|
{
|
|
public int Id { get; set; }
|
|
public string Sku { get; set; } = string.Empty;
|
|
public string Name { get; set; } = string.Empty;
|
|
public string Type { get; set; } = string.Empty;
|
|
public decimal Price { get; set; }
|
|
public bool Available { get; set; } = true;
|
|
}
|