1
0
mirror of synced 2024-11-24 06:20:12 +01:00

Update to test play count support on older versions

This commit is contained in:
asesidaa 2023-10-14 20:32:20 +08:00
parent 7edcd07723
commit e159a427a0

View File

@ -1,4 +1,5 @@
using Domain.Enums;
using Domain.Entities;
using Domain.Enums;
using Microsoft.Extensions.Logging;
namespace Application.Game.Card.Write;
@ -29,6 +30,21 @@ public class WriteBDataCommandHandler : RequestHandlerBase<WriteCardBDataCommand
data.CardId = request.CardId;
await CardDbContext.CardBdata.Upsert(data).RunAsync(cancellationToken);
var cardPlayCount = await CardDbContext.CardPlayCounts
.FirstOrDefaultAsync(count => count.CardId == request.CardId, cancellationToken);
if (cardPlayCount is null)
{
cardPlayCount = new CardPlayCount
{
CardId = request.CardId,
PlayCount = 0,
LastPlayedTime = DateTime.Now
};
}
cardPlayCount.PlayCount++;
cardPlayCount.LastPlayedTime = DateTime.Now;
await CardDbContext.CardPlayCounts.Upsert(cardPlayCount).RunAsync(cancellationToken);
await CardDbContext.SaveChangesAsync(cancellationToken);
return new ServiceResult<string>(request.Data);