75 lines
2.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using gehGassi.Core.Interfaces;
using gehGassi.Domain.Common;
using gehGassi.Domain.Payment;
namespace gehGassi.Core.Services
{
/// <summary>
/// Service der die Verwaltung von Wallets ermöglicht
/// </summary>
public class WalletService : ServiceBase<Wallet>, IWalletService
{
/// <summary>
/// Erstellt eine Instanz
/// </summary>
/// <param name="unitOfWork">Instanz eines IUnitOfWork</param>
public WalletService(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
/// <summary>
/// Erstellen eines Wallets für einen AppUser
/// </summary>
/// <param name="appUserId">Id des AppUsers</param>
/// <param name="walletId">ID des Walltes bei Mangopay</param>
/// <param name="type">Typ des Wallets</param>
/// <param name="ownerId">Id des Payment Owners (PaymentId)</param>
/// <param name="currency">Währung ISO 4217 Code</param>
/// <param name="description">Beschreibung</param>
/// <returns>Wallet</returns>
public Wallet Create(string appUserId, string walletId, WalletType type, string ownerId, string currency, string description)
{
var wallet = new Wallet
{
Id = Guid.NewGuid().ToString("N"),
AppUserId = appUserId,
Type = type,
OwnerId = ownerId,
WalletId = walletId,
Currency = currency,
Description = description,
Balance = 0,
UpdatedAt = DateTimeOffset.UtcNow
};
return wallet;
}
/// <summary>
/// Gibt ein Wallet für einen AppUser mit einem Typ zurück
/// </summary>
/// <param name="appUserId">Id des AppUsers</param>
/// <param name="type">Typ des Wallets</param>
/// <returns>Wallet oder null, wenn nicht gefunden</returns>
public async Task<Wallet> GetAsync(string appUserId, WalletType type)
{
var wallet = await Repository.FirstOrDefaultAsync(c => c.AppUserId == appUserId && c.Type == type).ConfigureAwait(false);
return wallet;
}
/// <summary>
/// Gibt eine Liste aller Wallets eines AppUsers zurück
/// </summary>
/// <param name="appUserId">Id des AppUsers</param>
/// <returns>Liste von Wallets</returns>
public async Task<List<Wallet>> GetAllAsync(string appUserId)
{
return (await Repository.FindAsync(c => c.AppUserId == appUserId).ConfigureAwait(false)).ToList();
}
}
}