Files
TakeoutSaaS.AdminApi/src/Application/TakeoutSaaS.Application/App/QuotaPackages/Handlers/CreateQuotaPackageCommandHandler.cs
MSuMshk ab59e2e3e2 feat: 新增配额包/支付相关实体与迁移
App:新增 operation_logs/quota_packages/tenant_payments/tenant_quota_package_purchases 表

Identity:修正 Avatar 字段类型(varchar(256)->text),保持现有数据不变
2025-12-17 17:27:45 +08:00

55 lines
1.9 KiB
C#

using MediatR;
using TakeoutSaaS.Application.App.QuotaPackages.Commands;
using TakeoutSaaS.Application.App.QuotaPackages.Dto;
using TakeoutSaaS.Domain.Tenants.Entities;
using TakeoutSaaS.Domain.Tenants.Repositories;
using TakeoutSaaS.Shared.Abstractions.Ids;
namespace TakeoutSaaS.Application.App.QuotaPackages.Handlers;
/// <summary>
/// 创建配额包命令处理器。
/// </summary>
public sealed class CreateQuotaPackageCommandHandler(
IQuotaPackageRepository quotaPackageRepository,
IIdGenerator idGenerator)
: IRequestHandler<CreateQuotaPackageCommand, QuotaPackageDto>
{
/// <inheritdoc />
public async Task<QuotaPackageDto> Handle(CreateQuotaPackageCommand request, CancellationToken cancellationToken)
{
// 1. 创建配额包实体
var quotaPackage = new QuotaPackage
{
Id = idGenerator.NextId(),
Name = request.Name,
QuotaType = request.QuotaType,
QuotaValue = request.QuotaValue,
Price = request.Price,
IsActive = request.IsActive,
SortOrder = request.SortOrder,
Description = request.Description,
CreatedAt = DateTime.UtcNow
};
// 2. 保存到数据库
await quotaPackageRepository.AddAsync(quotaPackage, cancellationToken);
await quotaPackageRepository.SaveChangesAsync(cancellationToken);
// 3. 返回 DTO
return new QuotaPackageDto
{
Id = quotaPackage.Id,
Name = quotaPackage.Name,
QuotaType = quotaPackage.QuotaType,
QuotaValue = quotaPackage.QuotaValue,
Price = quotaPackage.Price,
IsActive = quotaPackage.IsActive,
SortOrder = quotaPackage.SortOrder,
Description = quotaPackage.Description,
CreatedAt = quotaPackage.CreatedAt,
UpdatedAt = quotaPackage.UpdatedAt
};
}
}