156 lines
5.9 KiB
C#
156 lines
5.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.Payment;
|
|
using gehGassi.Domain.Shop;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace gehGassi.Core.Services
|
|
{
|
|
/// <summary>
|
|
/// Service der die Verwaltung von Transaktionsgebühren ermöglichts
|
|
/// </summary>
|
|
public class TransactionFeeService : ServiceBase<TransactionFee>, ITransactionFeeService
|
|
{
|
|
private readonly IRepository<GehGassiFee> _gehGassiRepository;
|
|
|
|
/// <summary>
|
|
/// Erstellt eine Instanz
|
|
/// </summary>
|
|
/// <param name="unitOfWork">Instanz eines IUnitOfWork</param>
|
|
public TransactionFeeService(IUnitOfWork unitOfWork) : base(unitOfWork)
|
|
{
|
|
_gehGassiRepository = unitOfWork.GetRepository<GehGassiFee>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt eine gefilterte Liste von Transaktionsgebühren zurück
|
|
/// </summary>
|
|
/// <param name="filter">Filterbegriff der in bestimmten Feldern gesucht wird</param>
|
|
/// <returns>List betroffener Transaktionsgebühren</returns>
|
|
public IQueryable<TransactionFee> Filter(string filter)
|
|
{
|
|
return Repository.Query(c => c.PayInType != null && c.Deleted == false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Erstellen einer Tranksaktionsgebühr
|
|
/// </summary>
|
|
/// <returns>Tranksaktionsgebühr</returns>
|
|
public TransactionFee Create()
|
|
{
|
|
var item = new TransactionFee()
|
|
{
|
|
Id = Guid.NewGuid().ToString("N")
|
|
};
|
|
return item;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Prüft ob schon eine Einstellung für einen Typ vorhanden ist
|
|
/// </summary>
|
|
/// <param name="payInType">Zahlungsmethode</param>
|
|
/// <returns>true wenn bereits vorhanden, false sonst</returns>
|
|
public async Task<bool> ExistsAsync(PayInType payInType)
|
|
{
|
|
var item = await Repository.FirstOrDefaultAsync(c => c.PayInType == payInType && c.Deleted == false).ConfigureAwait(false);
|
|
return item != null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt eine Liste von Transaktionsgebühren zurück, die für die Synchronisation benötigt werden
|
|
/// </summary>
|
|
/// <param name="lastUpdate">Letztes Update oder null wenn noch keines</param>
|
|
/// <returns>Liste von Transaktionsgebühren</returns>
|
|
public async Task<List<TransactionFee>> GetForSyncAsync(DateTimeOffset? lastUpdate)
|
|
{
|
|
if (lastUpdate.HasValue)
|
|
{
|
|
return (await Repository.FindAsync(c => c.UpdatedAt > lastUpdate.Value).ConfigureAwait(false)).ToList();
|
|
}
|
|
else
|
|
{
|
|
return (await Repository.GetAllAsync().ConfigureAwait(false)).ToList();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt eine gefilterte Liste von GehGassi-Gebühren zurück
|
|
/// </summary>
|
|
/// <param name="filter">Filterbegriff der in bestimmten Feldern gesucht wird</param>
|
|
/// <returns>List betroffener GehGassi-Gebühren</returns>
|
|
public IQueryable<GehGassiFee> FilterGehGassiFees(string filter)
|
|
{
|
|
return _gehGassiRepository.Query(c => c.Id != "" && c.Deleted == false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Erstellen einer GehGassi-Gebühr
|
|
/// </summary>
|
|
/// <returns>GehGassi-Gebühr</returns>
|
|
public GehGassiFee CreateGehGassiFee()
|
|
{
|
|
var item = new GehGassiFee()
|
|
{
|
|
Id = Guid.NewGuid().ToString("N")
|
|
};
|
|
return item;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt eine GehGassi-Gebühr zurück
|
|
/// </summary>
|
|
/// <param name="id">Id der Gebühr</param>
|
|
/// <returns>Gebühr oder null, wenn nicht gefunden</returns>
|
|
public async Task<GehGassiFee> GetGehGassiFeeAsync(string id)
|
|
{
|
|
return await _gehGassiRepository.FirstOrDefaultAsync(c => c.Id == id).ConfigureAwait(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Prüft ob schon eine Einstellung für einen Startbetrag vorhanden ist
|
|
/// </summary>
|
|
/// <param name="startAmmount">Startbetrag</param>
|
|
/// <param name="ignoreId">ID die ignoriert werden soll</param>
|
|
/// <returns>true wenn bereits vorhanden, false sonst</returns>
|
|
public async Task<bool> ExistsGehGassiFeeAsync(decimal startAmmount, string ignoreId)
|
|
{
|
|
var item = await _gehGassiRepository.FirstOrDefaultAsync(c => c.StartAmmount == startAmmount && c.Deleted == false && c.Id != ignoreId).ConfigureAwait(false);
|
|
return item != null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Hinzufügen einer GehGassi-Gebühr
|
|
/// </summary>
|
|
/// <param name="gehGassiFee">GehGassi-Gebühr</param>
|
|
public void AddGehGassiFee(GehGassiFee gehGassiFee)
|
|
{
|
|
_gehGassiRepository.Add(gehGassiFee);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Löschen einer GehGassi-Gebühr
|
|
/// </summary>
|
|
/// <param name="gehGassiFee">GehGassi-Gebühr</param>
|
|
public void RemoveGehGassiFee(GehGassiFee gehGassiFee)
|
|
{
|
|
_gehGassiRepository.Remove(gehGassiFee);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt eine GehGassi-Gebühr zurück die für den Startbetrag gilt
|
|
/// </summary>
|
|
/// <param name="startAmmount">Start-Betrag</param>
|
|
/// <returns>Gebühr oder null, wenn nicht gefunden</returns>
|
|
public async Task<GehGassiFee> GetMinGehGassiFeeAsync(decimal startAmmount)
|
|
{
|
|
var fee = await (_gehGassiRepository.Query(c => c.StartAmmount <= startAmmount && c.Deleted == false).OrderByDescending(c => c.StartAmmount)).FirstOrDefaultAsync().ConfigureAwait(false);
|
|
return fee;
|
|
}
|
|
}
|
|
}
|