44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
|
|
using Meezi.Core.Entities;
|
||
|
|
using Meezi.Core.Enums;
|
||
|
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
using Microsoft.Extensions.Logging;
|
||
|
|
|
||
|
|
namespace Meezi.Infrastructure.Data;
|
||
|
|
|
||
|
|
public static class DemoCouponSeeder
|
||
|
|
{
|
||
|
|
public static async Task EnsureCouponsAsync(AppDbContext db, string cafeId, ILogger logger)
|
||
|
|
{
|
||
|
|
if (await db.Coupons.AnyAsync(c => c.CafeId == cafeId && c.Code == "WELCOME10"))
|
||
|
|
return;
|
||
|
|
|
||
|
|
db.Coupons.AddRange(
|
||
|
|
new Coupon
|
||
|
|
{
|
||
|
|
Id = "coupon_demo_welcome10",
|
||
|
|
CafeId = cafeId,
|
||
|
|
Code = "WELCOME10",
|
||
|
|
Type = CouponType.Percentage,
|
||
|
|
Value = 10,
|
||
|
|
MaxDiscount = 50_000,
|
||
|
|
MinOrderAmount = 100_000,
|
||
|
|
UsageLimit = 100,
|
||
|
|
IsActive = true
|
||
|
|
},
|
||
|
|
new Coupon
|
||
|
|
{
|
||
|
|
Id = "coupon_demo_save20k",
|
||
|
|
CafeId = cafeId,
|
||
|
|
Code = "SAVE20",
|
||
|
|
Type = CouponType.FixedAmount,
|
||
|
|
Value = 20_000,
|
||
|
|
MinOrderAmount = 150_000,
|
||
|
|
UsageLimit = 50,
|
||
|
|
IsActive = true
|
||
|
|
});
|
||
|
|
|
||
|
|
await db.SaveChangesAsync();
|
||
|
|
logger.LogInformation("Demo coupons seeded: WELCOME10, SAVE20 for cafe {CafeId}", cafeId);
|
||
|
|
}
|
||
|
|
}
|