111 lines
3.6 KiB
C#
111 lines
3.6 KiB
C#
using gehGassi.Core.Interfaces;
|
|
using gehGassi.Domain.Favourites;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using gehGassi.Domain.Common;
|
|
using gehGassi.Domain.Devices;
|
|
|
|
namespace gehGassi.Core.Services
|
|
{
|
|
/// <summary>
|
|
/// Service der die Verwaltung von Devices der App-User ermöglicht
|
|
/// </summary>
|
|
public class DeviceService : ServiceBase<Device>, IDeviceService
|
|
{
|
|
/// <summary>
|
|
/// Erstellt eine Instanz
|
|
/// </summary>
|
|
/// <param name="unitOfWork">Instanz eines IUnitOfWork</param>
|
|
public DeviceService(IUnitOfWork unitOfWork) : base(unitOfWork)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Anlegen oder Aktualisieren eines Devices
|
|
/// </summary>
|
|
/// <param name="appUserId">ID des AppUsers</param>
|
|
/// <param name="installationId">eindeutige InstallationsID</param>
|
|
/// <param name="platform">Platform (OS)</param>
|
|
/// <param name="notificationPlatform">Platform (PNS)</param>
|
|
/// <param name="channel">Token des Users</param>
|
|
/// <param name="language">Sprache die am Gerät eingestellt ist</param>
|
|
/// <param name="suppresCommit">Soll Commit untertrückt werden</param>
|
|
/// <returns>Device</returns>
|
|
public async Task<Device> CreateOrUpdateAsync(string appUserId, string installationId, Platform platform, NotificationPlatform notificationPlatform, string channel, string language, bool suppresCommit)
|
|
{
|
|
var device = await Repository.FirstOrDefaultAsync(c => c.AppUserId == appUserId && c.InstallationId == installationId);
|
|
if (device != null)
|
|
{
|
|
device.Platform = platform;
|
|
device.NotificationPlatform = notificationPlatform;
|
|
device.Channel = channel;
|
|
device.Language = language;
|
|
device.LastUpdate = DateTimeOffset.UtcNow;
|
|
}
|
|
else
|
|
{
|
|
device = new Device
|
|
{
|
|
AppUserId = appUserId,
|
|
InstallationId = installationId,
|
|
Platform = platform,
|
|
NotificationPlatform = notificationPlatform,
|
|
Channel = channel,
|
|
Language = language,
|
|
Created = DateTimeOffset.UtcNow
|
|
};
|
|
Repository.Add(device);
|
|
}
|
|
|
|
if (!suppresCommit)
|
|
await CommitAsync("System");
|
|
|
|
return device;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Löschen eines Devices eines Benutzers mit einer InstallationsId
|
|
/// </summary>
|
|
/// <param name="appUserId"></param>
|
|
/// <param name="installationId"></param>
|
|
/// <param name="suppresCommit">Soll Commit untertrückt werden</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> DeleteAsync(string appUserId, string installationId, bool suppresCommit)
|
|
{
|
|
var device = await Repository.FirstOrDefaultAsync(c => c.AppUserId == appUserId && c.InstallationId == installationId);
|
|
if (device != null)
|
|
{
|
|
Remove(device);
|
|
if (!suppresCommit)
|
|
await CommitAsync("System");
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt eine Liste aller Devices eines App-Users zurück
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des AppUsers</param>
|
|
/// <returns>Liste von Devices</returns>
|
|
public async Task<List<Device>> GetAllAsync(string appUserId)
|
|
{
|
|
return (await Repository.FindAsync(c => c.AppUserId == appUserId).ConfigureAwait(false)).ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt ein Device für einen App-User zurück
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des App-Users</param>
|
|
/// <param name="installationId">InstallationsId des Devices</param>
|
|
/// <returns>Device oder null, wenn nicht gefunden</returns>
|
|
public async Task<Device> GetAsycn(string appUserId, string installationId)
|
|
{
|
|
return await Repository.FirstOrDefaultAsync(c => c.AppUserId == appUserId && c.InstallationId == installationId);
|
|
}
|
|
}
|
|
}
|