using System; using System.Threading.Tasks; using Wino.Core.Domain.Entities; namespace Wino.Core.Services { public interface ITokenService { Task GetTokenInformationAsync(Guid accountId); Task SaveTokenInformationAsync(Guid accountId, TokenInformation tokenInformation); } public class TokenService : BaseDatabaseService, ITokenService { public TokenService(IDatabaseService databaseService) : base(databaseService) { } public Task GetTokenInformationAsync(Guid accountId) => Connection.Table().FirstOrDefaultAsync(a => a.AccountId == accountId); public async Task SaveTokenInformationAsync(Guid accountId, TokenInformation tokenInformation) { // Delete all tokens for this account. await Connection.Table().DeleteAsync(a => a.AccountId == accountId); // Save new token info to the account. tokenInformation.AccountId = accountId; await Connection.InsertOrReplaceAsync(tokenInformation); } } }