100 lines
3.9 KiB
C#
100 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using gehGassi.Core.Interfaces;
|
|
using gehGassi.Domain.Common;
|
|
using gehGassi.Domain.Favourites;
|
|
using gehGassi.Domain.Payment;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace gehGassi.Core.Services
|
|
{
|
|
/// <summary>
|
|
/// Service der die Verwaltung von KYC-Dokumenten ermöglicht
|
|
/// </summary>
|
|
public class IdentityDocumentService : ServiceBase<IdentityDocument>, IIdentityDocumentService
|
|
{
|
|
/// <summary>
|
|
/// Erstellt eine Instanz
|
|
/// </summary>
|
|
/// <param name="unitOfWork">Instanz eines IUnitOfWork</param>
|
|
public IdentityDocumentService(IUnitOfWork unitOfWork) : base(unitOfWork)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Erstellen eines KYC-Dokuments
|
|
/// </summary>
|
|
/// <returns>IdentityDocument</returns>
|
|
public IdentityDocument Create()
|
|
{
|
|
var item = new IdentityDocument()
|
|
{
|
|
Id = Guid.NewGuid().ToString("N"),
|
|
Created = DateTimeOffset.UtcNow
|
|
};
|
|
return item;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Erstellen eines KYC-Dokuments
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des App-Users</param>
|
|
/// <param name="mangoPayId">Id des KYC-Dokumentes bei MangoPay</param>
|
|
/// <param name="mangoPayUserId">Id des Users bei MangoPay</param>
|
|
/// <param name="documentType">Typ des Dokumentes</param>
|
|
/// <param name="source">Quelle / Dokumentenart</param>
|
|
/// <param name="status">Status der Validierung des Dokumentes</param>
|
|
/// <param name="pageCount">Anzahl der Seiten</param>
|
|
/// <returns>IdentityDocument</returns>
|
|
public IdentityDocument Create(string appUserId, string mangoPayId, string mangoPayUserId, IdentityDocumentType documentType, IdentityDocumentSource source, IdentityDocumentStatus status, int pageCount)
|
|
{
|
|
var item = Create();
|
|
item.AppUserId = appUserId;
|
|
item.MangoPayId = mangoPayId;
|
|
item.MangoPayUserId = mangoPayUserId;
|
|
item.Type = documentType;
|
|
item.Source = source;
|
|
item.Status = status;
|
|
item.PageCount = pageCount;
|
|
|
|
return item;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt ein KYC-Dokument anhand der MangoPayId zurück
|
|
/// </summary>
|
|
/// <param name="mangoPayId">Id des Dokumentes bei MangoPay</param>
|
|
/// <returns>IdentityDocument oder null, wenn nicht gefunden</returns>
|
|
public async Task<IdentityDocument> GetByMangoPayIdAsync(string mangoPayId)
|
|
{
|
|
var item = await Repository.FirstOrDefaultAsync(c => c.MangoPayId == mangoPayId).ConfigureAwait(false);
|
|
return item;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt ein KYC-Dokument zurück, bei welchem die Validierung noch läuft
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des App-USers</param>
|
|
/// <returns>IdentityDocument oder null, wenn keines gefunden</returns>
|
|
public async Task<IdentityDocument> GetValidationInProgressAsync(string appUserId)
|
|
{
|
|
var item = await Repository.FirstOrDefaultAsync(c => c.AppUserId == appUserId && c.Status == IdentityDocumentStatus.VALIDATION_ASKED).ConfigureAwait(false);
|
|
return item;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt das zuletzt erstellte KYC-Dokument für einen App-User zurück
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des App-USers</param>
|
|
/// <returns>IdentityDocument oder null, wenn keines gefunden</returns>
|
|
public async Task<IdentityDocument> GetLatestAsync(string appUserId)
|
|
{
|
|
var item = await Repository.Query(c => c.AppUserId == appUserId).OrderByDescending(c => c.Created).FirstOrDefaultAsync().ConfigureAwait(false);
|
|
return item;
|
|
}
|
|
}
|
|
}
|