11582 lines
495 KiB
C#
11582 lines
495 KiB
C#
using gehGassiApp.Core.Interfaces;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using gehGassi.Dto;
|
|
using gehGassiApp.Domain.Authentication;
|
|
using gehGassiApp.Domain.Users;
|
|
using gehGassiApp.Core.Helper;
|
|
using System.Net.Http.Headers;
|
|
using gehGassi.Dto.News;
|
|
using gehGassiApp.Core.Resources;
|
|
using gehGassiApp.Domain.News;
|
|
using System.Web;
|
|
using System.Globalization;
|
|
using System.Net;
|
|
using System.Net.Http.Json;
|
|
using gehGassi.Dto.Banners;
|
|
using gehGassi.Dto.Common;
|
|
using gehGassi.Dto.Listings;
|
|
using gehGassi.Dto.Lookup;
|
|
using gehGassi.Dto.Messages;
|
|
using gehGassiApp.Domain.Banners;
|
|
using gehGassiApp.Domain.Common;
|
|
using gehGassiApp.Domain.Listings;
|
|
using gehGassiApp.Domain.Lookup;
|
|
using gehGassiApp.Domain.Messages;
|
|
using gehGassiApp.Domain.Advertisements;
|
|
using gehGassi.Dto.Advertisements;
|
|
using gehGassi.Dto.Dogs;
|
|
using gehGassi.Dto.DogWalkers;
|
|
using gehGassi.Dto.Walks;
|
|
using gehGassiApp.Domain.Dogs;
|
|
using gehGassiApp.Domain.Walks;
|
|
using gehGassi.Dto.DogOwners;
|
|
using gehGassi.Dto.Favourites;
|
|
using gehGassi.Dto.Feedback;
|
|
using gehGassi.Dto.Payment;
|
|
using gehGassi.Dto.Pushnotifications;
|
|
using gehGassi.Dto.Ratings;
|
|
using gehGassi.Dto.Reporting;
|
|
using gehGassiApp.Core.Mapper;
|
|
using gehGassiApp.Domain.AppVersions;
|
|
using gehGassiApp.Domain.Favourites;
|
|
using gehGassiApp.Domain.Feedback;
|
|
using gehGassiApp.Domain.Payment;
|
|
using gehGassiApp.Domain.Vouchers;
|
|
using gehGassiApp.Domain.Walkers;
|
|
using gehGassi.Dto.Vouchers;
|
|
using gehGassiApp.Domain.Subscriptions;
|
|
using gehGassi.Dto.Subscriptions;
|
|
using Platform = gehGassiApp.Domain.Common.Platform;
|
|
|
|
|
|
namespace gehGassiApp.Core.Services
|
|
{
|
|
/// <summary>
|
|
/// Service der die Kommunikation mit dem Server ermöglicht
|
|
/// </summary>
|
|
public class CommunicationService : ICommunicationService
|
|
{
|
|
private readonly ISettingsService _settingsService;
|
|
private readonly IAppReportingService _appReportingService;
|
|
private readonly HttpClient _httpClient;
|
|
private readonly JsonSerializerOptions _jsonOptions;
|
|
private DateTimeOffset? _lastOnlineCheck;
|
|
private bool _isOnline;
|
|
private bool _hasInternet;
|
|
|
|
/// <summary>
|
|
/// Erstellt eine Instanz
|
|
/// </summary>
|
|
/// <param name="baseAddress">Basisadresse des Servers</param>
|
|
/// <param name="settingsService">Instanz eines ISettingsService</param>
|
|
/// <param name="appReportingService">Instanz eines IAppReportingService</param>
|
|
public CommunicationService(string baseAddress, ISettingsService settingsService, IAppReportingService appReportingService)
|
|
{
|
|
_settingsService = settingsService;
|
|
_appReportingService = appReportingService;
|
|
|
|
|
|
//Sonderfall wegen lokaler Entwicklung und Verbindung zu localhost --> Android & Windows
|
|
#if DEBUG
|
|
var devSslHelper = new DevHttpsConnectionHelper(new Uri(baseAddress).Port);
|
|
_httpClient = devSslHelper.HttpClient;
|
|
_httpClient.BaseAddress = new Uri(devSslHelper.DevServerRootUrl);
|
|
#else
|
|
_httpClient = new HttpClient();
|
|
_httpClient.BaseAddress = new Uri(baseAddress);
|
|
#endif
|
|
|
|
_httpClient.DefaultRequestHeaders.Add(Common.Constants.HasHeader, Common.Constants.HasHeaderValue);
|
|
_jsonOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web);
|
|
|
|
_lastOnlineCheck = null;
|
|
_isOnline = true;
|
|
_hasInternet = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Prüft ob eine Verbindung zum Server besteht
|
|
/// </summary>
|
|
/// <returns>true wenn verbunden, false sonst</returns>
|
|
public async Task<bool> IsConnected()
|
|
{
|
|
//var appSettings = _settingsService.GetAppSettings();
|
|
|
|
var oldOnlineStatus = _isOnline;
|
|
try
|
|
{
|
|
SetClientTime();
|
|
|
|
//return false; //Um die Verbindung zu faken....
|
|
//var accessType = Connectivity.Current.NetworkAccess;
|
|
_hasInternet = Connectivity.Current.NetworkAccess == Microsoft.Maui.Networking.NetworkAccess.Internet;
|
|
if (_hasInternet)
|
|
{
|
|
//Wenn nicht Online, oder noch kein Onlinecheck durchgeführt wurde, oder der letzte Check länger als OnlineCheckDelay her ist
|
|
if (!_isOnline)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine($"Check Server online status at {DateTimeOffset.UtcNow}");
|
|
using var cts = new CancellationTokenSource(Common.Constants.IsConnectedTimeout);
|
|
var result = await _httpClient.GetAsync($"api/Status/IsOnline", cts.Token).ConfigureAwait(false);
|
|
result.EnsureSuccessStatusCode();
|
|
var success = (bool.Parse(await result.Content.ReadAsStringAsync(cts.Token)));
|
|
_isOnline = success;
|
|
_lastOnlineCheck = DateTimeOffset.UtcNow;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_isOnline = false;
|
|
_lastOnlineCheck = null;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//Wird aufgerufen wenn ein Fehler bei der Abfrage am Server vorhanden ist...
|
|
_hasInternet = Connectivity.Current.NetworkAccess == Microsoft.Maui.Networking.NetworkAccess.Internet;
|
|
_isOnline = false;
|
|
_lastOnlineCheck = null;
|
|
System.Diagnostics.Debug.WriteLine(ex.Message);
|
|
}
|
|
|
|
//var onlineStatus = new OnlineStatusMessage() { WasOnline = oldOnlineStatus, IsOnline = _isOnline && _hasInternet };
|
|
|
|
//WeakReferenceMessenger.Default.Send(new OnlineStatusChangedMessage(onlineStatus));
|
|
|
|
return _isOnline && _hasInternet;
|
|
}
|
|
|
|
#region Helper für DebugInfo
|
|
|
|
public bool GetIsOnline()
|
|
{
|
|
return _isOnline;
|
|
}
|
|
|
|
public bool GetHasInternet()
|
|
{
|
|
return _hasInternet;
|
|
}
|
|
|
|
public DateTimeOffset? GetLastOnlineCheck()
|
|
{
|
|
return _lastOnlineCheck;
|
|
}
|
|
|
|
public Microsoft.Maui.Networking.NetworkAccess GetCurrentNetworkAccess()
|
|
{
|
|
return Connectivity.Current.NetworkAccess;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
#region Registrierung
|
|
|
|
/// <summary>
|
|
/// Prüfen ob ein Benutzername noch verfügbar ist und ob das Passwort ausreicht
|
|
/// </summary>
|
|
/// <param name="userName">Benutzername</param>
|
|
/// <param name="password">Passwort</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>true wenn alles passt, false sonst</returns>
|
|
public async Task<CommunicationResult<bool>> RegisterCheckAvailableAsync(string userName, string password, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
|
|
var loginDto = new LoginDto() { UserName = userName, Password = password };
|
|
var json = JsonSerializer.Serialize(loginDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/Account/IsAvailable", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Register_Email_Exists:
|
|
result.ErrorMessage = Errors.Register_Email_Exists;
|
|
break;
|
|
case CommunicationErrors.Register_Password_Rules:
|
|
result.ErrorMessage = Errors.Register_Password_Rules;
|
|
break;
|
|
case CommunicationErrors.Register_Password_Pwned:
|
|
result.ErrorMessage = Errors.Register_Password_Pwned;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Login_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Prüfen ob ein Passwort ausreicht
|
|
/// </summary>
|
|
/// <param name="password">Passwort</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>true wenn alles passt, false sonst</returns>
|
|
public async Task<CommunicationResult<bool>> CheckPasswordAsync(string password, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
|
|
var checkDto = new CheckPasswordDto() { Password = password };
|
|
var json = JsonSerializer.Serialize(checkDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/Account/CheckPassword", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Register_Password_Rules:
|
|
result.ErrorMessage = Errors.Register_Password_Rules;
|
|
break;
|
|
case CommunicationErrors.Register_Password_Pwned:
|
|
result.ErrorMessage = Errors.Register_Password_Pwned;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Login_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Registrieren eines App-Users
|
|
/// </summary>
|
|
/// <param name="userName">Benutzername</param>
|
|
/// <param name="password">Passwort</param>
|
|
/// <param name="country">Land</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <param name="appUserType">AppUser-Typ</param>
|
|
/// <param name="firstName">Vorname</param>
|
|
/// <param name="lastName">Nachname</param>
|
|
/// <param name="birthDate">Geburtsdatum</param>
|
|
/// <param name="zip">PLZ</param>
|
|
/// <param name="city">Ort</param>
|
|
/// <param name="state">Bundesland</param>
|
|
/// <param name="nationality">Nationalität</param>
|
|
/// <param name="mainResidence">Land Hauptwohnsitz</param>
|
|
/// <returns>true wenn alles passt, false sonst</returns>
|
|
public async Task<CommunicationResult<bool>> RegisterAsync(string userName, string password, AppUserType appUserType, string firstName, string lastName, DateTimeOffset? birthDate, string zip, string city, string state, string country, string nationality, string mainResidence, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
|
|
var registerDto = new RegisterV2Dto()
|
|
{
|
|
UserName = userName,
|
|
Password = password,
|
|
AppUserType = (AppUserTypeDto)appUserType,
|
|
FirstName = firstName,
|
|
LastName = lastName,
|
|
BirthDate = birthDate,
|
|
Zip = zip,
|
|
City = city,
|
|
State = state,
|
|
CountryCode = country,
|
|
NationalityCode = nationality,
|
|
MainResidenceCountryCode = mainResidence
|
|
};
|
|
var json = JsonSerializer.Serialize(registerDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/v2/Account/Register", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Register_Email_Exists:
|
|
result.ErrorMessage = Errors.Register_Email_Exists;
|
|
break;
|
|
case CommunicationErrors.Register_Password_Rules:
|
|
result.ErrorMessage = Errors.Register_Password_Rules;
|
|
break;
|
|
case CommunicationErrors.Register_Password_Pwned:
|
|
result.ErrorMessage = Errors.Register_Password_Pwned;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Login_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Registrieren eines App-Users Extern
|
|
/// </summary>
|
|
/// <param name="userName">Benutzername</param>
|
|
/// <param name="password">Passwort</param>
|
|
/// <param name="country">Land</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <param name="appUserType">AppUser-Typ</param>
|
|
/// <param name="firstName">Vorname</param>
|
|
/// <param name="lastName">Nachname</param>
|
|
/// <param name="birthDate">Geburtsdatum</param>
|
|
/// <param name="zip">PLZ</param>
|
|
/// <param name="city">Ort</param>
|
|
/// <param name="state">Bundesland</param>
|
|
/// <param name="accessToken">Token des externen Providers</param>
|
|
/// <param name="loginProvider">Login-Provider</param>
|
|
/// <param name="nationality">Nationalität</param>
|
|
/// <param name="mainResidence">Land Hauptwohnsitz</param>
|
|
/// <returns>true wenn alles passt, false sonst</returns>
|
|
public async Task<CommunicationResult<User>> RegisterExternalAsync(string userName, string password, AppUserType appUserType, string firstName, string lastName, DateTimeOffset? birthDate, string zip, string city, string state, string country, string nationality, string mainResidence, string accessToken, string loginProvider, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<User>()
|
|
{
|
|
Success = false,
|
|
Value = null
|
|
};
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
|
|
var registerDto = new RegisterExternalV2Dto()
|
|
{
|
|
UserName = userName,
|
|
Password = password,
|
|
AppUserType = (AppUserTypeDto)appUserType,
|
|
FirstName = firstName,
|
|
LastName = lastName,
|
|
BirthDate = birthDate,
|
|
Zip = zip,
|
|
City = city,
|
|
State = state,
|
|
CountryCode = country,
|
|
AccessToken = accessToken,
|
|
LoginProvider = loginProvider,
|
|
NationalityCode = nationality,
|
|
MainResidenceCountryCode = mainResidence
|
|
};
|
|
var json = JsonSerializer.Serialize(registerDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/v2/Account/RegisterExternal", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
var userDto = await serverResult.Content.ReadFromJsonAsync<UserDto>(_jsonOptions, token);
|
|
|
|
var user = userDto.ToDomain();
|
|
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = user;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Register_Email_Exists:
|
|
result.ErrorMessage = Errors.Register_Email_Exists;
|
|
break;
|
|
case CommunicationErrors.Register_Password_Rules:
|
|
result.ErrorMessage = Errors.Register_Password_Rules;
|
|
break;
|
|
case CommunicationErrors.Register_Password_Pwned:
|
|
result.ErrorMessage = Errors.Register_Password_Pwned;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Login_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Token / Login
|
|
|
|
/// <summary>
|
|
/// Anmelden eines Benutzers
|
|
/// </summary>
|
|
/// <param name="userName">Benutzername</param>
|
|
/// <param name="password">Passwort</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>true wenn erfolgreich, false sonst</returns>
|
|
public async Task<CommunicationResult<User>> LoginAsync(string userName, string password, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<User>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
|
|
var loginDto = new LoginDto() { UserName = userName, Password = password };
|
|
var json = JsonSerializer.Serialize(loginDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/Account/Login", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var userDto = await serverResult.Content.ReadFromJsonAsync<UserDto>(_jsonOptions, token);
|
|
|
|
var user = userDto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = user;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Login_Email_NotConfirmed:
|
|
result.ErrorMessage = Errors.Login_Email_NotConfirmed;
|
|
break;
|
|
case CommunicationErrors.Login_Invalid_Credentials:
|
|
result.ErrorMessage = Errors.Login_Invalid_Credentials;
|
|
break;
|
|
case CommunicationErrors.Login_LockedOut:
|
|
result.ErrorMessage = Errors.Login_LockedOut;
|
|
break;
|
|
case CommunicationErrors.Login_Assignment_Missing:
|
|
result.ErrorMessage = Errors.Login_Assignment_Missing;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Login_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Anmelden eines Benutzers mittels Acces-Token wegen external Provider
|
|
/// </summary>
|
|
/// <param name="accessToken">Access-Token</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<User>> LoginExternalAsync(string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<User>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/Account/LoginExternal", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var stringResult = await serverResult.Content.ReadAsStringAsync(token);
|
|
var userDto = await serverResult.Content.ReadFromJsonAsync<UserDto>(_jsonOptions, token);
|
|
|
|
var user = userDto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = user;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Login_Email_NotConfirmed:
|
|
result.ErrorMessage = Errors.Login_Email_NotConfirmed;
|
|
break;
|
|
case CommunicationErrors.Login_Invalid_Credentials:
|
|
result.ErrorMessage = Errors.Login_Invalid_Credentials;
|
|
break;
|
|
case CommunicationErrors.Login_LockedOut:
|
|
result.ErrorMessage = Errors.Login_LockedOut;
|
|
break;
|
|
case CommunicationErrors.Login_Assignment_Missing:
|
|
result.ErrorMessage = Errors.Login_Assignment_Missing;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Login_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Anmelden eines Benutzers mittels Apple Provider
|
|
/// </summary>
|
|
/// <param name="dto">Login-Daten von Apple</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<User>> LoginAppleAsync(LoginAppleDto dto, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<User>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
|
|
var json = JsonSerializer.Serialize(dto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/Account/LoginApple", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var userDto = await serverResult.Content.ReadFromJsonAsync<UserDto>(_jsonOptions, token);
|
|
|
|
var user = userDto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = user;
|
|
}
|
|
else
|
|
{
|
|
if (serverResult.StatusCode == HttpStatusCode.NotFound)
|
|
{
|
|
//Sonderlösung damit wir das Refreshtoken erhalten
|
|
var resposeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var appleResponseDto = JsonSerializer.Deserialize<AppleResponseDto>(resposeString);
|
|
result.ErrorCode = CommunicationErrors.Common_NotFound;
|
|
result.ErrorMessage = appleResponseDto.RefreshToken;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Login_Email_NotConfirmed:
|
|
result.ErrorMessage = Errors.Login_Email_NotConfirmed;
|
|
break;
|
|
case CommunicationErrors.Login_Invalid_Credentials:
|
|
result.ErrorMessage = Errors.Login_Invalid_Credentials;
|
|
break;
|
|
case CommunicationErrors.Login_LockedOut:
|
|
result.ErrorMessage = Errors.Login_LockedOut;
|
|
break;
|
|
case CommunicationErrors.Login_Assignment_Missing:
|
|
result.ErrorMessage = Errors.Login_Assignment_Missing;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Login_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Abmelden eines Benutzers.
|
|
/// Löscht alle Refreshtokens des Benutzers
|
|
/// </summary>
|
|
/// <param name="accessToken">Access-Token</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns></returns>
|
|
public async Task<CommunicationResult<bool>> LogoutAsync(string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/Account/Logout", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Login_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Zurücksetzen des Passworts eines Benutzers
|
|
/// </summary>
|
|
/// <param name="userName">Benutzername / Email</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> ResetPasswordAsync(string userName, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
|
|
var json = JsonSerializer.Serialize(userName, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/Account/ResetPassword", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Senden der E-Mail Bestätigung für einen Benutzer
|
|
/// </summary>
|
|
/// <param name="userName">Benutzername / Email</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> ResendConfirmationAsync(string userName, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
|
|
var json = JsonSerializer.Serialize(userName, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/Account/SendConfirmation", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Anmelden eines Benutzers mittels Refreshtoken
|
|
/// </summary>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="refreshToken">Refreshtoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>true wenn erfolgreich, false sonst</returns>
|
|
public async Task<CommunicationResult<TokenResponse>> RefreshTokenAsync(string accessToken, string refreshToken, CancellationToken token)
|
|
{
|
|
var appSettings = _settingsService.GetAppSettings();
|
|
|
|
var result = new CommunicationResult<TokenResponse>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
|
|
var dto = new RefreshTokenDto() { AccessToken = accessToken, RefreshToken = refreshToken };
|
|
var json = JsonSerializer.Serialize(dto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/Account/Refresh", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var refreshTokenDto = await serverResult.Content.ReadFromJsonAsync<RefreshTokenResponseDto>(_jsonOptions, token);
|
|
var tokenResponse = refreshTokenDto.ToDomain();
|
|
|
|
result.Success = true;
|
|
result.Value = tokenResponse;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.RefreshToken_NotFound:
|
|
result.ErrorMessage = Errors.RefreshToken_NotFound;
|
|
break;
|
|
case CommunicationErrors.RefreshToken_Expired:
|
|
result.ErrorMessage = Errors.RefreshToken_Expired;
|
|
break;
|
|
case CommunicationErrors.AccessToken_Empty:
|
|
result.ErrorMessage = Errors.AccessToken_Empty;
|
|
break;
|
|
case CommunicationErrors.RefreshToken_UserNotFound:
|
|
result.ErrorMessage = Errors.RefreshToken_UserNotFound;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Login_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
if (appSettings.LogConnection)
|
|
{
|
|
var infos = new Dictionary<string, string>
|
|
{
|
|
{ "_isOnline", _isOnline.ToString() },
|
|
{ "_lastOnlineCheck", _lastOnlineCheck?.ToString() },
|
|
{ "_networkAccess", Connectivity.Current.NetworkAccess.ToString() },
|
|
{ "OnlineCheckDelay", _lastOnlineCheck.HasValue ? (DateTimeOffset.UtcNow - _lastOnlineCheck).Value.Seconds.ToString() : "_lastOnlineCheck NULL" },
|
|
{ "ErrorCode", result.ErrorCode.ToString()},
|
|
{ "Errormessage", result.ErrorMessage}
|
|
};
|
|
await _appReportingService.TrackEventAsync("RefreshTokenAsync Flo", infos);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.ErrorCode = CommunicationErrors.Timeout;
|
|
result.ErrorMessage = ex.Message;
|
|
|
|
var error = $"{ex.Message} - {ex.StackTrace}";
|
|
if (appSettings.LogConnection)
|
|
{
|
|
var infos = new Dictionary<string, string>
|
|
{
|
|
{ "_isOnline", _isOnline.ToString() },
|
|
{ "_lastOnlineCheck", _lastOnlineCheck?.ToString() },
|
|
{ "_networkAccess", Connectivity.Current.NetworkAccess.ToString() },
|
|
{ "OnlineCheckDelay", _lastOnlineCheck.HasValue ? (DateTimeOffset.UtcNow - _lastOnlineCheck).Value.Seconds.ToString() : "_lastOnlineCheck NULL" },
|
|
{ "Errormessage", ex.Message}
|
|
};
|
|
await _appReportingService.TrackEventAsync("RefreshTokenAsync Catch", infos);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Prüfen ob ein Benutzer ein Passwort hat
|
|
/// </summary>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> HasPasswordAsync(string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/Account/HasPassword", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
var stringResult = await serverResult.Content.ReadAsStringAsync(token);
|
|
var success = bool.Parse(stringResult);
|
|
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = success;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Register_Password_Rules:
|
|
result.ErrorMessage = Errors.Register_Password_Rules;
|
|
break;
|
|
case CommunicationErrors.Register_Password_Pwned:
|
|
result.ErrorMessage = Errors.Register_Password_Pwned;
|
|
break;
|
|
case CommunicationErrors.Register_Password_Mismatch:
|
|
result.ErrorMessage = Errors.Register_Password_Mismatch;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Login_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Hinzufügen eines Passswortes zu einem Benutzer, wenn dieser keines hat
|
|
/// </summary>
|
|
/// <param name="userName">Benutzername</param>
|
|
/// <param name="password">Passwort das hinzugefügt werden soll</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> AddPasswordAsync(string userName, string password, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
|
|
var loginDto = new AddPasswordDto() { UserName = userName, Password = password };
|
|
var json = JsonSerializer.Serialize(loginDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/Account/AddPassword", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
var stringResult = await serverResult.Content.ReadAsStringAsync(token);
|
|
var success = bool.Parse(stringResult);
|
|
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = success;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Register_Password_Rules:
|
|
result.ErrorMessage = Errors.Register_Password_Rules;
|
|
break;
|
|
case CommunicationErrors.Register_Password_Pwned:
|
|
result.ErrorMessage = Errors.Register_Password_Pwned;
|
|
break;
|
|
case CommunicationErrors.Register_Password_Mismatch:
|
|
result.ErrorMessage = Errors.Register_Password_Mismatch;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Login_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ändern des Passwortes eines Benutzers
|
|
/// </summary>
|
|
/// <param name="userName">Benutzername</param>
|
|
/// <param name="password">Passwort das gesetzt werden soll</param>
|
|
/// <param name="oldPassword">Bisheriges Passwort</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> ChangePasswordAsync(string userName, string password, string oldPassword, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
|
|
var loginDto = new ChangePasswordDto() { UserName = userName, Password = password, OldPassword = oldPassword};
|
|
var json = JsonSerializer.Serialize(loginDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/Account/ChangePassword", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
var stringResult = await serverResult.Content.ReadAsStringAsync(token);
|
|
var success = bool.Parse(stringResult);
|
|
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = success;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Register_Password_Rules:
|
|
result.ErrorMessage = Errors.Register_Password_Rules;
|
|
break;
|
|
case CommunicationErrors.Register_Password_Pwned:
|
|
result.ErrorMessage = Errors.Register_Password_Pwned;
|
|
break;
|
|
case CommunicationErrors.Register_Password_Mismatch:
|
|
result.ErrorMessage = Errors.Register_Password_Mismatch;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Login_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Löschen des Accounts eines Benutzers
|
|
/// </summary>
|
|
/// <param name="userName">Benutzername</param>
|
|
/// <param name="userId">Id des Benutzers</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> DeleteAccountAsync(string userName, string userId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
|
|
var deleteAccountDto = new DeleteAccountDto() { UserName = userName, UserId = userId};
|
|
var json = JsonSerializer.Serialize(deleteAccountDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/Account/DeleteAccount", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
var stringResult = await serverResult.Content.ReadAsStringAsync(token);
|
|
var success = bool.Parse(stringResult);
|
|
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = success;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.DeleteAccount_NotPossible;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.DeleteAccount_NotPossible;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region App-User
|
|
|
|
/// <summary>
|
|
/// Holt den App-User für den aktuell angemeldeten Benutzer
|
|
/// </summary>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<AppUser>> GetAppUserAsync(string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<AppUser>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/Account/GetAppUser", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<AppUserDto>(_jsonOptions, token);
|
|
|
|
var appUser = dto.ToDomain();
|
|
|
|
result.Success = true;
|
|
result.Value = appUser;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Login_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holt den App-User für den aktuell angemeldeten Benutzer Sync
|
|
/// </summary>
|
|
/// <param name="lastUpdate">Wann wurden das letzte mal Daten erfolgreich geholt? Wenn null, dann alle Daten</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<AppUser>> GetAppUserSyncAsync(DateTimeOffset? lastUpdate, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<AppUser>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var lastUpdateString = HttpUtility.UrlEncode(lastUpdate.ToString());
|
|
if (lastUpdate.HasValue)
|
|
lastUpdateString = HttpUtility.UrlEncode(lastUpdate.Value.ToString("o"));
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/Account/GetAppUserSync?lastUpdate={lastUpdateString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = null;
|
|
if (serverResult.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<AppUserDto>(_jsonOptions, token);
|
|
|
|
var appUser = dto.ToDomain();
|
|
result.Value = appUser;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Login_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aktualisieren eines App-Users am Server
|
|
/// </summary>
|
|
/// <param name="appUserDto">App-User DTO</param>
|
|
/// <param name="photoFile">Foto-Datei</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <param name="photoFileName">Dateiname Photo</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> UpdateAppUserAsync(AppUserDto appUserDto, string photoFileName, byte[] photoFile, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(appUserDto, _jsonOptions);
|
|
var multipartContent = new MultipartFormDataContent();
|
|
multipartContent.Add(new StringContent(json, Encoding.UTF8, "application/json"), "model");
|
|
if (!string.IsNullOrEmpty(photoFileName) && photoFile != null)
|
|
{
|
|
multipartContent.Add(new ByteArrayContent(photoFile), "photoUpdateFile", photoFileName);
|
|
}
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/Account/Update", multipartContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Setzen des AppUser Types am Server.
|
|
/// Kann nur online erfolgen!
|
|
/// </summary>
|
|
/// <param name="setAppUserTypeDto">Dto für das Setzen des Typs</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> SetAppUserTypeAsync(SetAppUserTypeDto setAppUserTypeDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(setAppUserTypeDto, _jsonOptions);
|
|
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/Account/SetAppUserType", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Setzen des AppUser Types am Server. Wenn hundebesitzer Walker wird
|
|
/// Kann nur online erfolgen!
|
|
/// </summary>
|
|
/// <param name="setAppUserTypeDto">Dto für das Setzen des Typs</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<AppUser>> SetAppUserTypeAsync(SetAppUserTypeExDto setAppUserTypeDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<AppUser>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(setAppUserTypeDto, _jsonOptions);
|
|
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/Account/SetAppUserTypeEx", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
if (serverResult.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<AppUserDto>(_jsonOptions, token);
|
|
|
|
var appUser = dto.ToDomain();
|
|
result.Value = appUser;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Hinzufügen eines Payment Users am Server.
|
|
/// </summary>
|
|
/// <param name="addPaymentUserDto">DTO für das Hinzufeügen des Payment-Users</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<AppUser>> AddPaymentUserAsync(AddPaymentUserDto addPaymentUserDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<AppUser>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(addPaymentUserDto, _jsonOptions);
|
|
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/Account/AddPaymentUser", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
if (serverResult.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<AppUserDto>(_jsonOptions, token);
|
|
|
|
var appUser = dto.ToDomain();
|
|
result.Value = appUser;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Blockieren eines App-Users am Server
|
|
/// </summary>
|
|
/// <param name="blockDto">Dto für das Blockieren eines anderen App-Users</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> BlockAppUserAsync(BlockCreateDto blockDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(blockDto, _jsonOptions);
|
|
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/Account/BlockAppUser", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
if (serverResult.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<AppUserBlockDto>(_jsonOptions, token);
|
|
result.Value = dto != null;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Blockieren eines App-Users am Server aufheben
|
|
/// </summary>
|
|
/// <param name="unblockDto">Dto für das Aufheben der Blockierung eines anderen App-Users</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> UnblockAppUserAsync(BlockRemoveDto unblockDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(unblockDto, _jsonOptions);
|
|
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/Account/UnblockAppUser", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
if (serverResult.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
var success = (bool.Parse(await serverResult.Content.ReadAsStringAsync(token)));
|
|
result.Value = success;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen von blockierten App-Usern
|
|
/// </summary>
|
|
/// <param name="query">Abfrageobjekt</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>ListCommunicationResult</returns>
|
|
public async Task<ListCommunicationResult<List<AppUserBlockWithNames>>> GetBlockedAppUsersAsync(BlockedQueryDto query, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<AppUserBlockWithNames>>
|
|
{
|
|
Value = new List<AppUserBlockWithNames>()
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(query, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/account/GetBlockedAppUsers", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<ListResponseDto<AppUserBlockWithNamesDto>>(_jsonOptions, token);
|
|
|
|
var blockedAppUsers = listResponseDto.List.ToDomain();
|
|
result.Success = true;
|
|
result.Value = blockedAppUsers;
|
|
result.Total = listResponseDto.Total;
|
|
result.Skip = listResponseDto.Skip;
|
|
result.Take = listResponseDto.Take;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Melden eines App-Users
|
|
/// </summary>
|
|
/// <param name="reportDto">Dto für das Melden eines anderen App-Users</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> ReportAppUserAsync(AppUserReportDto reportDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(reportDto, _jsonOptions);
|
|
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/Account/ReportAppUser", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
if (serverResult.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
var success = (bool.Parse(await serverResult.Content.ReadAsStringAsync(token)));
|
|
result.Value = success;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Walker Profile
|
|
|
|
/// <summary>
|
|
/// Holt den das Walker Profil für den aktuell angemeldeten Benutzer
|
|
/// </summary>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<DogWalkerProfile>> GetWalkerProfileAsync(string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<DogWalkerProfile>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/Account/GetWalkerProfile", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<DogWalkerProfileDto>(_jsonOptions, token);
|
|
|
|
var walkerProfile = dto.ToDomain();
|
|
|
|
result.Success = true;
|
|
result.Value = walkerProfile;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Login_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holt das Walker Profil für den aktuell angemeldeten Benutzer Sync!
|
|
/// </summary>
|
|
/// <param name="lastUpdate">Wann wurden das letzte mal Daten erfolgreich geholt? Wenn null, dann alle Daten</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<DogWalkerProfile>> GetWalkerProfileSyncAsync(DateTimeOffset? lastUpdate, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<DogWalkerProfile>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var lastUpdateString = HttpUtility.UrlEncode(lastUpdate.ToString());
|
|
if (lastUpdate.HasValue)
|
|
lastUpdateString = HttpUtility.UrlEncode(lastUpdate.Value.ToString("o"));
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/Account/GetWalkerProfileSync?lastUpdate={lastUpdateString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = null;
|
|
if (serverResult.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<DogWalkerProfileDto>(_jsonOptions, token);
|
|
|
|
var walkerProfile = dto.ToDomain();
|
|
result.Value = walkerProfile;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Login_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aktualisieren eines Dogwalker Profils am Server
|
|
/// </summary>
|
|
/// <param name="walkerProfileDto">Profil DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> UpdateWalkerProfileAsync(DogWalkerProfileDto walkerProfileDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(walkerProfileDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/Account/UpdateWalkerProfile", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DogOwners
|
|
|
|
/// <summary>
|
|
/// Gibt Detailsinfos zu einem DogOwner zurück
|
|
/// </summary>
|
|
/// <param name="dogOwnerId">Id des DogOwners</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<DogOwnerInfo>> GetDogOwnerAsync(string dogOwnerId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<DogOwnerInfo>
|
|
{
|
|
Value = new DogOwnerInfo()
|
|
};
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var param = HttpUtility.UrlEncode(dogOwnerId);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/dogowners/GetDogOwner?dogOwnerId={param}", token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var responseDto = await serverResult.Content.ReadFromJsonAsync<DogOwnerInfoDto>(_jsonOptions, token);
|
|
|
|
var item = responseDto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = item;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DogWalkers
|
|
|
|
/// <summary>
|
|
/// Gibt Detailsinfos zu einem Dogwalker zurück
|
|
/// </summary>
|
|
/// <param name="dogWalkerId">Id des Dogwalkers</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<DogWalkerInfo>> GetDogWalkerAsync(string dogWalkerId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<DogWalkerInfo>
|
|
{
|
|
Value = new DogWalkerInfo()
|
|
};
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var param = HttpUtility.UrlEncode(dogWalkerId);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/dogwalkers/GetDogWalker?dogWalkerId={param}", token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var responseDto = await serverResult.Content.ReadFromJsonAsync<DogWalkerInfoDto>(_jsonOptions, token);
|
|
|
|
var item = responseDto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = item;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen von Dogwalkern vom Server.
|
|
/// </summary>
|
|
/// <param name="query">Abfrageobjekt</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>ListCommunicationResult</returns>
|
|
public async Task<ListCommunicationResult<List<DogWalkerInfo>>> GetDogWalkersAsync(DogWalkerQueryDto query, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<DogWalkerInfo>>
|
|
{
|
|
Value = new List<DogWalkerInfo>()
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(query, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/dogwalkers/GetDogWalkers", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<ListResponseDto<DogWalkerInfoDto>>(_jsonOptions, token);
|
|
|
|
var dogWalkers = listResponseDto.List.ToDomain();
|
|
result.Success = true;
|
|
result.Value = dogWalkers;
|
|
result.Total = listResponseDto.Total;
|
|
result.Skip = listResponseDto.Skip;
|
|
result.Take = listResponseDto.Take;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen von Dogwalkern vom Server. Als Lookup
|
|
/// </summary>
|
|
/// <param name="query">Abfrageobjekt</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>ListCommunicationResult</returns>
|
|
public async Task<ListCommunicationResult<List<DogWalkerLookup>>> GetDogWalkersLookupAsync(DogWalkerQueryDto query, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<DogWalkerLookup>>
|
|
{
|
|
Value = new List<DogWalkerLookup>()
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(query, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/dogwalkers/GetDogWalkersLookup", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<ListResponseDto<DogWalkerLookupDto>>(_jsonOptions, token);
|
|
|
|
var dogWalkers = listResponseDto.List.ToDomain();
|
|
result.Success = true;
|
|
result.Value = dogWalkers;
|
|
result.Total = listResponseDto.Total;
|
|
result.Skip = listResponseDto.Skip;
|
|
result.Take = listResponseDto.Take;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen der Walkingtimes vom Server
|
|
/// </summary>
|
|
/// <param name="dogWalkerId">Id des DogWalkers</param>
|
|
/// <param name="lastUpdate">Wann wurden das letzte mal Daten erfolgreich geholt? Wenn null, dann alle Daten</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<WalkingTime>>> GetWalkingTimesForSyncAsync(string dogWalkerId, DateTimeOffset? lastUpdate, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<WalkingTime>>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var param1 = HttpUtility.UrlEncode(dogWalkerId);
|
|
var lastUpdateString = HttpUtility.UrlEncode(lastUpdate.ToString());
|
|
if (lastUpdate.HasValue)
|
|
lastUpdateString = HttpUtility.UrlEncode(lastUpdate.Value.ToString("o"));
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/dogwalkers/GetWalkingTimesForSync?dogWalkerId={param1}&lastUpdate={lastUpdateString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<WalkingTimeDto>>(_jsonOptions, token);
|
|
|
|
var list = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = list;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Anlegen einer WalkingTime am Server
|
|
/// </summary>
|
|
/// <param name="walkingTimeDto">WalkingTime</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<CreateResponse<WalkingTime>>> CreateWalkingTimeAsync(WalkingTimeDto walkingTimeDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<CreateResponse<WalkingTime>>()
|
|
{
|
|
Success = false
|
|
};
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(walkingTimeDto, _jsonOptions);
|
|
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/dogwalkers/CreateWalkingTime", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var serverResponse = await serverResult.Content.ReadFromJsonAsync<CreateResponseDto<WalkingTimeDto>>(_jsonOptions, token);
|
|
|
|
var createResponse = new CreateResponse<WalkingTime>
|
|
{
|
|
Status = (CreateStatus)serverResponse.Status,
|
|
Value = serverResponse.Value.ToDomain()
|
|
};
|
|
|
|
result.Success = true;
|
|
result.Value = createResponse;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aktualisieren einer WalkingTime am Server
|
|
/// </summary>
|
|
/// <param name="walkingTimeDto">WalkingTime DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> UpdateWalkingTimeAsync(WalkingTimeDto walkingTimeDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(walkingTimeDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/dogwalkers/UpdateWalkingTime", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Löschen einer WalkingTime am Server
|
|
/// </summary>
|
|
/// <param name="walkingTimeDto">WalkingTime DTO</param>
|
|
/// <param name="appUserId">Id des App-Users</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> DeleteWalkingTimeAsync(WalkingTimeDto walkingTimeDto, string appUserId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(walkingTimeDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
var paramAppUserId = HttpUtility.UrlEncode(appUserId);
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/dogwalkers/DeleteWalkingTime?appUserId={paramAppUserId}", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt alle WalkingTimes eins Dogwalkers vom Server zurück
|
|
/// </summary>
|
|
/// <param name="dogWalkerId">ID des DogWalkers</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<WalkingTime>>> GetAllWalkingTimesAsync(string dogWalkerId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<WalkingTime>>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var parameter = HttpUtility.UrlEncode(dogWalkerId);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/dogwalkers/GetWalkingTimes?dogWalkerId={parameter}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<WalkingTimeDto>>(_jsonOptions, token);
|
|
|
|
var walkingTimes = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = walkingTimes;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region News & NewsCategories
|
|
|
|
/// <summary>
|
|
/// Holen der News-Kategorien vom Server.
|
|
/// </summary>
|
|
/// <param name="lastUpdate">Wann wurden das letzte mal Daten erfolgreich geholt? Wenn null, dann alle Daten</param>
|
|
/// <param name="language">Gewünschte Sprache</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<NewsCategory>>> GetNewsCategoriesAsync(DateTimeOffset? lastUpdate, string language, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<NewsCategory>>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var lastUpdateString = HttpUtility.UrlEncode(lastUpdate.ToString());
|
|
if(lastUpdate.HasValue)
|
|
lastUpdateString = HttpUtility.UrlEncode(lastUpdate.Value.ToString("o"));
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/news/GetCategories?lastUpdate={lastUpdateString}&language={language}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<NewsCategoryDto>>(_jsonOptions, token);
|
|
|
|
var categories = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = categories;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen von News vom Server.
|
|
/// </summary>
|
|
/// <param name="query">Abfrageobjekt</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<ListCommunicationResult<List<News>>> GetNewsAsync(NewsQueryDto query, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<News>>
|
|
{
|
|
Value = new List<News>()
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(query, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/news/GetNews", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<ListResponseDto<NewsDto>>(_jsonOptions, token);
|
|
|
|
var news = listResponseDto.List.ToDomain();
|
|
result.Success = true;
|
|
result.Value = news;
|
|
result.Total = listResponseDto.Total;
|
|
result.Skip = listResponseDto.Skip;
|
|
result.Take = listResponseDto.Take;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Lookup
|
|
|
|
/// <summary>
|
|
/// Gibt eine Liste von Dog- Ownern und Walkern basierend auf einem Filter zurück
|
|
/// </summary>
|
|
/// <param name="filter">Filter</param>
|
|
/// <param name="take">Anzahl max. Datensätze</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<AppUserLookup>>> LookupEntitiesAsync(string filter, int take, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<AppUserLookup>>
|
|
{
|
|
Value = new List<AppUserLookup>()
|
|
};
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var filterUrl = HttpUtility.UrlEncode(filter);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/lookup/Entities?filter={filterUrl}&take={take}", token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<List<AppUserLookupDto>>(_jsonOptions, token);
|
|
|
|
var items = listResponseDto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = items;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt eine Liste von Dogwalkern mit Distanz zur aktuellen Position zurück
|
|
/// </summary>
|
|
/// <param name="ignoreId">Id die ignoriert werden soll falls der Benutzer DogOwner und DogWalker ist</param>
|
|
/// <param name="lat">Breitengrad</param>
|
|
/// <param name="lng">Längengrad</param>
|
|
/// <param name="take">Anzahl Walker gewünscht</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<DogWalkerLookup>>> LookupDogWalkersAsync(string ignoreId, double lat, double lng, int take, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<DogWalkerLookup>>
|
|
{
|
|
Value = new List<DogWalkerLookup>()
|
|
};
|
|
|
|
var appSettings = _settingsService.GetAppSettings();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var latString = HttpUtility.UrlEncode(lat.ToString(CultureInfo.InvariantCulture));
|
|
var lngString = HttpUtility.UrlEncode(lng.ToString(CultureInfo.InvariantCulture));
|
|
var paramIgnoreId = HttpUtility.UrlEncode(ignoreId);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/lookup/DogWalkers?ignoreId={paramIgnoreId}&lat={latString}&lng={lngString}&take={take}", token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<List<DogWalkerLookupDto>>(_jsonOptions, token);
|
|
|
|
var items = listResponseDto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = items;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
if (appSettings.LogConnection)
|
|
{
|
|
var infos = new Dictionary<string, string>
|
|
{
|
|
{ "_isOnline", _isOnline.ToString() },
|
|
{ "_lastOnlineCheck", _lastOnlineCheck?.ToString() },
|
|
{ "_networkAccess", Connectivity.Current.NetworkAccess.ToString() },
|
|
{ "OnlineCheckDelay", _lastOnlineCheck.HasValue ? (DateTimeOffset.UtcNow - _lastOnlineCheck).Value.Seconds.ToString() : "_lastOnlineCheck NULL" },
|
|
{ "ErrorCode", result.ErrorCode.ToString()},
|
|
{ "Errormessage", result.ErrorMessage}
|
|
};
|
|
await _appReportingService.TrackEventAsync("LookupDogWalkersAsync Flo", infos);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
|
|
if (appSettings.LogConnection)
|
|
{
|
|
var infos = new Dictionary<string, string>
|
|
{
|
|
{ "_isOnline", _isOnline.ToString() },
|
|
{ "_lastOnlineCheck", _lastOnlineCheck?.ToString() },
|
|
{ "_networkAccess", Connectivity.Current.NetworkAccess.ToString() },
|
|
{ "OnlineCheckDelay", _lastOnlineCheck.HasValue ? (DateTimeOffset.UtcNow - _lastOnlineCheck).Value.Seconds.ToString() : "_lastOnlineCheck NULL" },
|
|
{ "Errormessage", ex.Message}
|
|
};
|
|
await _appReportingService.TrackEventAsync("LookupDogWalkersAsync", infos);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt Detailsinfos zu einem Dogwalker zurück
|
|
/// </summary>
|
|
/// <param name="dogWalkerId">Id des Dogwalkers</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<DogWalkerInfo>> LookupDogWalkerAsync(string dogWalkerId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<DogWalkerInfo>
|
|
{
|
|
Value = new DogWalkerInfo()
|
|
};
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var param = HttpUtility.UrlEncode(dogWalkerId);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/lookup/DogWalker?dogWalkerId={param}", token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var responseDto = await serverResult.Content.ReadFromJsonAsync<DogWalkerInfoDto>(_jsonOptions, token);
|
|
|
|
var item = responseDto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = item;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Messages
|
|
|
|
/// <summary>
|
|
/// Holt eine Liste der Konversationen eines Benutzers
|
|
/// </summary>
|
|
/// <param name="senderId">Id des Benutzers (DogOwner | DogWalker)</param>
|
|
/// <param name="lastUpdate">Letztes Update</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>Liste von Konversationen</returns>
|
|
public async Task<CommunicationResult<List<Conversation>>> GetConversationsAsync(string senderId, DateTimeOffset? lastUpdate, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<Conversation>>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var lastUpdateString = HttpUtility.UrlEncode(lastUpdate.ToString());
|
|
if (lastUpdate.HasValue)
|
|
lastUpdateString = HttpUtility.UrlEncode(lastUpdate.Value.ToString("o"));
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/messages/GetConversations?senderId={senderId}&lastUpdate={lastUpdateString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<ConversationDto>>(_jsonOptions, token);
|
|
|
|
var conversations = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = conversations;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holt eine Liste der Konversationen eines Benutzers mit Filter am Server.
|
|
/// Geblockte oder Gesperrte Benutzer werden nicht zurückgegeben.
|
|
/// </summary>
|
|
/// <param name="senderId">Id des Benutzers (DogOwner | DogWalker)</param>
|
|
/// <param name="filter">Filter</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>Liste von Konversationen</returns>
|
|
public async Task<CommunicationResult<List<Conversation>>> GetConversationsWithFilterAsync(string senderId, string filter, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<Conversation>>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var filterString = HttpUtility.UrlEncode(filter);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/messages/GetConversationsEx?senderId={senderId}&filter={filterString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<ConversationDto>>(_jsonOptions, token);
|
|
|
|
var conversations = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = conversations;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holt eine Konversationen eines Benutzers mit einem Ziel
|
|
/// </summary>
|
|
/// <param name="senderId">Id des Benutzers (DogOwner | DogWalker)</param>
|
|
/// <param name="receipientId">Id des Empfängers</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>Liste von Konversationen</returns>
|
|
public async Task<CommunicationResult<Conversation>> GetConversationByReceipientAsync(string senderId, string receipientId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<Conversation>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/messages/GetConversationByReceipient?senderId={senderId}&receipientId={receipientId}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<ConversationDto>(_jsonOptions, token);
|
|
|
|
var conversation = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = conversation;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Anlegen einer Konversation am Server
|
|
/// </summary>
|
|
/// <param name="conversationId">Gewünschte Id der Konversation</param>
|
|
/// <param name="senderId">Id des Senders</param>
|
|
/// <param name="receiverId">Id des Empfängers</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<CreateResponse<Conversation>>> CreateConversationAsync(string conversationId, string senderId, string receiverId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<CreateResponse<Conversation>>()
|
|
{
|
|
Success = false
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var createConversationDto = new CreateConversationDto()
|
|
{
|
|
Id = conversationId,
|
|
SenderId = senderId,
|
|
ReceiverId = receiverId,
|
|
};
|
|
var json = JsonSerializer.Serialize(createConversationDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/messages/CreateConversation", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var conversationDto = await serverResult.Content.ReadFromJsonAsync<CreateResponseDto<ConversationDto>>(_jsonOptions, token);
|
|
|
|
var createResponse = new CreateResponse<Conversation>
|
|
{
|
|
Status = (CreateStatus)conversationDto.Status,
|
|
Value = conversationDto.Value.ToDomain()
|
|
};
|
|
|
|
result.Success = true;
|
|
result.Value = createResponse;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holt eine Liste der offenen Nachrichten eines Benutzers
|
|
/// </summary>
|
|
/// <param name="senderId">Id des Benutzers (DogOwner | DogWalker)</param>
|
|
/// <param name="lastUpdate">Letztes Update</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>Liste von Konversationen</returns>
|
|
public async Task<CommunicationResult<List<Message>>> GetMessagesAsync(string senderId, DateTimeOffset? lastUpdate, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<Message>>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var lastUpdateString = HttpUtility.UrlEncode(lastUpdate.ToString());
|
|
if (lastUpdate.HasValue)
|
|
lastUpdateString = HttpUtility.UrlEncode(lastUpdate.Value.ToString("o"));
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/messages/GetMessages?senderId={senderId}&lastUpdate={lastUpdateString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<MessageDto>>(_jsonOptions, token);
|
|
|
|
var messages = dto.ToDomain();
|
|
foreach (var message in messages)
|
|
{
|
|
message.Direction = MessageDirection.In;
|
|
message.Read = false;
|
|
}
|
|
|
|
result.Success = true;
|
|
result.Value = messages;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holt eine Liste der offenen Nachrichten eines Benutzers für eine Konversation
|
|
/// </summary>
|
|
/// <param name="senderId">Id des Benutzers (DogOwner | DogWalker)</param>
|
|
/// <param name="conversationId">Id der Konversation</param>
|
|
/// <param name="lastUpdate">Letztes Update</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>Liste von Konversationen</returns>
|
|
public async Task<CommunicationResult<List<Message>>> GetMessagesAsync(string senderId, string conversationId, DateTimeOffset? lastUpdate, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<Message>>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var lastUpdateString = HttpUtility.UrlEncode(lastUpdate.ToString());
|
|
if (lastUpdate.HasValue)
|
|
lastUpdateString = HttpUtility.UrlEncode(lastUpdate.Value.ToString("o"));
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/messages/GetMessagesByConversation?senderId={senderId}&conversationId={conversationId}&lastUpdate={lastUpdateString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<MessageDto>>(_jsonOptions, token);
|
|
|
|
var messages = dto.ToDomain();
|
|
foreach (var message in messages)
|
|
{
|
|
message.Direction = MessageDirection.In;
|
|
message.Read = false;
|
|
}
|
|
|
|
result.Success = true;
|
|
result.Value = messages;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bestätigen des erfolgreichen Erhalts von Nachrichten für einen Benutzer
|
|
/// </summary>
|
|
/// <param name="senderId">Id des Benutzers (DogOwner | DogWalker)</param>
|
|
/// <param name="lastUpdate">Letztes Update</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> ConfirmMessagesAsync(string senderId, DateTimeOffset? lastUpdate, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var confirmation = new MessageConfirmationDto()
|
|
{
|
|
SenderId = senderId,
|
|
LastUpdate = lastUpdate,
|
|
ConversationId = string.Empty
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(confirmation, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
var serverResult = await _httpClient.PostAsync($"api/messages/ConfirmMessages", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bestätigen des erfolgreichen Erhalts von Nachrichten für einen Benutzer für eine Konversation
|
|
/// </summary>
|
|
/// <param name="senderId">Id des Benutzers (DogOwner | DogWalker)</param>
|
|
/// <param name="conversationId">Id der Konversation</param>
|
|
/// <param name="lastUpdate">Letztes Update</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> ConfirmMessagesAsync(string senderId, string conversationId, DateTimeOffset? lastUpdate, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var confirmation = new MessageConfirmationDto()
|
|
{
|
|
SenderId = senderId,
|
|
LastUpdate = lastUpdate,
|
|
ConversationId = conversationId
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(confirmation, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
var serverResult = await _httpClient.PostAsync($"api/messages/ConfirmMessagesByConversation", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Anlegen einer Nachricht am Server
|
|
/// </summary>
|
|
/// <param name="senderId">Id des Benutzers (DogOwner | DogWalker)</param>
|
|
/// <param name="receiverId">Id des Benutzers Empfänger</param>
|
|
/// <param name="message">Nachricht</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<CreateResponse<Message>>> AddMessageAsync(string senderId, string receiverId, Message message, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<CreateResponse<Message>>()
|
|
{
|
|
Success = false
|
|
};
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var messageDto = message.ToDto();
|
|
messageDto.SenderId = senderId;
|
|
messageDto.ReceiverId = receiverId;
|
|
|
|
var json = JsonSerializer.Serialize(messageDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
var serverResult = await _httpClient.PostAsync($"api/messages/AddMessage", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var messageResponse = await serverResult.Content.ReadFromJsonAsync<CreateResponseDto<MessageDto>>(_jsonOptions, token);
|
|
|
|
var createResponse = new CreateResponse<Message>
|
|
{
|
|
Status = (CreateStatus)messageResponse.Status,
|
|
Value = messageResponse.Value.ToDomain()
|
|
};
|
|
createResponse.Value.Direction = MessageDirection.Out;
|
|
|
|
result.Success = true;
|
|
result.Value = createResponse;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen der Systemnachrichten vom Server für Sync
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des AppUsers</param>
|
|
/// <param name="lastUpdate">Wann wurden das letzte mal Daten erfolgreich geholt? Wenn null, dann alle Daten</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<SystemMessage>>> GetSystemMessagesForSyncAsync(string appUserId, DateTimeOffset? lastUpdate, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<SystemMessage>>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var appUserIdString = HttpUtility.UrlEncode(appUserId);
|
|
var lastUpdateString = HttpUtility.UrlEncode(lastUpdate.ToString());
|
|
if (lastUpdate.HasValue)
|
|
lastUpdateString = HttpUtility.UrlEncode(lastUpdate.Value.ToString("o"));
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/messages/GetSystemMessagesForSync?appUserId={appUserIdString}&lastUpdate={lastUpdateString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<SystemMessageDto>>(_jsonOptions, token);
|
|
|
|
var list = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = list;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bestätigen des erfolgreichen Erhalts von SystemNachrichten für einen Benutzer
|
|
/// </summary>
|
|
/// <param name="senderId">Id des Benutzers (DogOwner | DogWalker)</param>
|
|
/// <param name="lastUpdate">Letztes Update</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> ConfirmSystemMessagesAsync(string senderId, DateTimeOffset? lastUpdate, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var confirmation = new SystemMessageConfirmationDto()
|
|
{
|
|
SenderId = senderId,
|
|
LastUpdate = lastUpdate
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(confirmation, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
var serverResult = await _httpClient.PostAsync($"api/messages/ConfirmSystemMessages", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Entfernen von Systemnachrichten vom Server für einen AppUser und eine bestimmte Kombination aus Key und Table
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des AppUsers</param>
|
|
/// <param name="appUserType">Typ des AppUsers</param>
|
|
/// <param name="key">Key</param>
|
|
/// <param name="table">Table</param>
|
|
/// <param name="created">Alter als dieses Datum</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> RemoveSystemMessagesAsync(string appUserId, AppUserType appUserType, string key, string table, DateTimeOffset? created, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var confirmation = new SystemMessageRemoveDto()
|
|
{
|
|
AppUserId = appUserId,
|
|
AppUserType = (AppUserTypeDto) appUserType,
|
|
Key = key,
|
|
Table = table,
|
|
Created = created.Value
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(confirmation, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
var serverResult = await _httpClient.PostAsync($"api/messages/RemoveSystemMessages", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Listings
|
|
|
|
/// <summary>
|
|
/// Holen der Branchen und Listungen Übersicht
|
|
/// </summary>
|
|
/// <param name="query">Abfrageobjekt</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<ListCommunicationResult<List<BranchWithListings>>> GetListingsOverviewAsync(QueryDto query, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<BranchWithListings>>
|
|
{
|
|
Value = new List<BranchWithListings>()
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(query, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/listings/GetOverview", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<ListResponseDto<BranchWithListingsDto>>(_jsonOptions, token);
|
|
|
|
var listings = listResponseDto.List.ToDomain();
|
|
result.Success = true;
|
|
result.Value = listings;
|
|
result.Total = listResponseDto.Total;
|
|
result.Skip = listResponseDto.Skip;
|
|
result.Take = listResponseDto.Take;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen von Listungen nahe dem Benutzer vom Server.
|
|
/// </summary>
|
|
/// <param name="query">Abfrageobjekt</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<ListCommunicationResult<List<Listing>>> GetListingsNearAsync(QueryDto query, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<Listing>>
|
|
{
|
|
Value = new List<Listing>()
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(query, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/listings/GetNearListings", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<ListResponseDto<ListingDto>>(_jsonOptions, token);
|
|
|
|
var listings = listResponseDto.List.ToDomain();
|
|
result.Success = true;
|
|
result.Value = listings;
|
|
result.Total = listResponseDto.Total;
|
|
result.Skip = listResponseDto.Skip;
|
|
result.Take = listResponseDto.Take;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt eine laufende Listung zurück
|
|
/// </summary>
|
|
/// <param name="id">Id der Listung</param>
|
|
/// <param name="language">gewünschte Sprache</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<Listing>> GetListingRunningAsync(string id, string language, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<Listing>
|
|
{
|
|
Value = null
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var parameterId = HttpUtility.UrlEncode(id);
|
|
var parameterLanguage = HttpUtility.UrlEncode(language);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/listings/GetRunningListing?id={parameterId}&language={parameterLanguage}", token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listingDto = await serverResult.Content.ReadFromJsonAsync<ListingDto>(_jsonOptions, token);
|
|
|
|
var listing = listingDto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = listing;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen von Listungen je Branche mit Geo-Einschränkungen
|
|
/// </summary>
|
|
/// <param name="query">Abfrageobjekt</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>ListCommunicationResult</returns>
|
|
public async Task<ListCommunicationResult<List<Listing>>> GetListingsByBranchAsync(ListingQueryDto query, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<Listing>>
|
|
{
|
|
Value = new List<Listing>()
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(query, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/listings/GetByBranch", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<ListResponseDto<ListingDto>>(_jsonOptions, token);
|
|
|
|
var listings = listResponseDto.List.ToDomain();
|
|
result.Success = true;
|
|
result.Value = listings;
|
|
result.Total = listResponseDto.Total;
|
|
result.Skip = listResponseDto.Skip;
|
|
result.Take = listResponseDto.Take;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Banners
|
|
|
|
/// <summary>
|
|
/// Abfragen eines zufälligen Banners für eine Platzierung
|
|
/// </summary>
|
|
/// <param name="query">Abfrageobjekt</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<Banner>> GetBannerForLocationAsync(BannerQueryDto query, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<Banner>
|
|
{
|
|
Value = null
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(query, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/banners/GetBanner", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var responseDto = await serverResult.Content.ReadFromJsonAsync<BannerDto>(_jsonOptions, token);
|
|
|
|
var banner = responseDto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = banner;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Hinzufügen von Klicks zu einem Banner
|
|
/// </summary>
|
|
/// <param name="dtoModel">Model für einen Klick für Banner</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>true wenn der Banner noch gültig ist, false sonst</returns>
|
|
public async Task<CommunicationResult<bool>> AddClicksAsync(BannerClickDto dtoModel, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>
|
|
{
|
|
Value = false
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(dtoModel, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/banners/ClickBanner", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var stringResult = await serverResult.Content.ReadAsStringAsync(token);
|
|
var responseDto = bool.Parse(stringResult);
|
|
|
|
result.Success = true;
|
|
result.Value = responseDto;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Hinzufügen von Views zu einem Banner
|
|
/// </summary>
|
|
/// <param name="dtoModel">Model für einen View für Banner</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>true wenn der Banner noch gültig ist, false sonst</returns>
|
|
public async Task<CommunicationResult<bool>> AddViewsAsync(BannerViewDto dtoModel, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>
|
|
{
|
|
Value = false
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(dtoModel, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/banners/ViewBanner", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var stringResult = await serverResult.Content.ReadAsStringAsync(token);
|
|
var responseDto = bool.Parse(stringResult);
|
|
|
|
result.Success = true;
|
|
result.Value = responseDto;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Advertisements
|
|
|
|
/// <summary>
|
|
/// Holen der Liste der Werbungs-Kategorien welche online sind
|
|
/// </summary>
|
|
/// <param name="language">Gewünschte Sprache</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<AdvertisementCategory>>> GetAdvertisementCategoriesOnlineAsync(string language, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<AdvertisementCategory>>
|
|
{
|
|
Value = new List<AdvertisementCategory>()
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var parameterLanguage = HttpUtility.UrlEncode(language);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/advertisements/GetCategoriesOnline?language={parameterLanguage}", token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var categoriesResponseDto = await serverResult.Content.ReadFromJsonAsync<List<AdvertisementCategoryDto>>(_jsonOptions, token);
|
|
|
|
var categories = categoriesResponseDto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = categories;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen von ablaufenden Werbungen mit Geo-Einschränkungen
|
|
/// </summary>
|
|
/// <param name="query">Abfrageobjekt</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<ListCommunicationResult<List<Advertisement>>> GetAdvertisementsNearEndAsync(QueryDto query, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<Advertisement>>
|
|
{
|
|
Value = new List<Advertisement>()
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(query, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/advertisements/GetAdvertisementsNearEnd", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<ListResponseDto<AdvertisementDto>>(_jsonOptions, token);
|
|
|
|
var advertisements = listResponseDto.List.ToDomain();
|
|
result.Success = true;
|
|
result.Value = advertisements;
|
|
result.Total = listResponseDto.Total;
|
|
result.Skip = listResponseDto.Skip;
|
|
result.Take = listResponseDto.Take;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt eine laufende Werbung zurück
|
|
/// </summary>
|
|
/// <param name="id">Id der Werbung</param>
|
|
/// <param name="language">gewünschte Sprache</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<Advertisement>> GetAdvertisementRunningAsync(string id, string language, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<Advertisement>
|
|
{
|
|
Value = null
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var parameterId = HttpUtility.UrlEncode(id);
|
|
var parameterLanguage = HttpUtility.UrlEncode(language);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/advertisements/GetRunningAdvertisement?id={parameterId}&language={parameterLanguage}", token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var advertisementDto = await serverResult.Content.ReadFromJsonAsync<AdvertisementDto>(_jsonOptions, token);
|
|
|
|
var advertisement = advertisementDto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = advertisement;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen von Werbungen je Kategorie mit Geo-Einschränkungen
|
|
/// </summary>
|
|
/// <param name="query">Abfrageobjekt</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>ListCommunicationResult</returns>
|
|
public async Task<ListCommunicationResult<List<Advertisement>>> GetAdvertisementsByCategoryAsync(AdvertisementQueryDto query, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<Advertisement>>
|
|
{
|
|
Value = new List<Advertisement>()
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(query, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/advertisements/GetAdvertisementsByCategory", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<ListResponseDto<AdvertisementDto>>(_jsonOptions, token);
|
|
|
|
var advertisements = listResponseDto.List.ToDomain();
|
|
result.Success = true;
|
|
result.Value = advertisements;
|
|
result.Total = listResponseDto.Total;
|
|
result.Skip = listResponseDto.Skip;
|
|
result.Take = listResponseDto.Take;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Dogs & Dogsraces
|
|
|
|
/// <summary>
|
|
/// Holen der Hunderassen vom Server.
|
|
/// </summary>
|
|
/// <param name="lastUpdate">Wann wurden das letzte mal Daten erfolgreich geholt? Wenn null, dann alle Daten</param>
|
|
/// <param name="language">Gewünschte Sprache</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<DogRace>>> GetDogRacesAsync(DateTimeOffset? lastUpdate, string language, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<DogRace>>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var lastUpdateString = HttpUtility.UrlEncode(lastUpdate.ToString());
|
|
if (lastUpdate.HasValue)
|
|
lastUpdateString = HttpUtility.UrlEncode(lastUpdate.Value.ToString("o"));
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/dogs/GetRaces?lastUpdate={lastUpdateString}&language={language}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<DogRaceDto>>(_jsonOptions, token);
|
|
|
|
var races = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = races;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen einer Hunderassen vom Server.
|
|
/// </summary>
|
|
/// <param name="id">Id der Hunderasse</param>
|
|
/// <param name="language">Gewünschte Sprache</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<DogRace>> GetDogRaceAsync(string id, string language, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<DogRace>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var parameter = HttpUtility.UrlEncode(id);
|
|
var parameter2 = HttpUtility.UrlEncode(language);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/dogs/GetRace?id={parameter}&language={parameter2}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<DogRaceDto>(_jsonOptions, token);
|
|
|
|
var dogRace = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = dogRace;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen der Hunde vom Server
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des AppUsers</param>
|
|
/// <param name="lastUpdate">Wann wurden das letzte mal Daten erfolgreich geholt? Wenn null, dann alle Daten</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<Dog>>> GetDogsAsync(string appUserId, DateTimeOffset? lastUpdate, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<Dog>>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var appUserIdString = HttpUtility.UrlEncode(appUserId);
|
|
var lastUpdateString = HttpUtility.UrlEncode(lastUpdate.ToString());
|
|
if (lastUpdate.HasValue)
|
|
lastUpdateString = HttpUtility.UrlEncode(lastUpdate.Value.ToString("o"));
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/dogs/GetDogs?appUserId={appUserIdString}&lastUpdate={lastUpdateString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<DogDto>>(_jsonOptions, token);
|
|
|
|
var dogs = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = dogs;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen der Hunde vom Server als MinInfo
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des AppUsers</param>
|
|
/// <param name="language">Gewünschte Sprache</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<DogMinInfo>>> GetDogsMinAsync(string appUserId, string language, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<DogMinInfo>>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var appUserIdString = HttpUtility.UrlEncode(appUserId);
|
|
var languageString = HttpUtility.UrlEncode(language);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/dogs/GetDogsMin?dogOwnerId={appUserIdString}&language={languageString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<DogMinInfoDto>>(_jsonOptions, token);
|
|
|
|
var dogs = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = dogs;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen eines Hundes vom Server
|
|
/// </summary>
|
|
/// <param name="dogId">Id des Hundes</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<Dog>> GetDogAsync(string dogId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<Dog>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var parameter = HttpUtility.UrlEncode(dogId);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/dogs/GetDog?dogId={parameter}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<DogDto>(_jsonOptions, token);
|
|
|
|
var dog = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = dog;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Anlegen eines Hundes am Server
|
|
/// </summary>
|
|
/// <param name="dogDto">Hund DTO</param>
|
|
/// <param name="photoFile">Foto-Datei</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <param name="photoFileName">Dateiname Photo</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<CreateResponse<Dog>>> AddDogAsync(DogDto dogDto, string photoFileName, byte[] photoFile, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<CreateResponse<Dog>>()
|
|
{
|
|
Success = false
|
|
};
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(dogDto, _jsonOptions);
|
|
var multipartContent = new MultipartFormDataContent();
|
|
multipartContent.Add(new StringContent(json, Encoding.UTF8, "application/json"), "model");
|
|
if (!string.IsNullOrEmpty(photoFileName) && photoFile != null)
|
|
{
|
|
multipartContent.Add(new ByteArrayContent(photoFile), "photoUpdateFile", photoFileName);
|
|
}
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/dogs/Add", multipartContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var serverResponse = await serverResult.Content.ReadFromJsonAsync<CreateResponseDto<DogDto>>(_jsonOptions, token);
|
|
|
|
var createResponse = new CreateResponse<Dog>
|
|
{
|
|
Status = (CreateStatus)serverResponse.Status,
|
|
Value = serverResponse.Value.ToDomain()
|
|
};
|
|
|
|
result.Success = true;
|
|
result.Value = createResponse;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aktualisieren eines Hundes am Server
|
|
/// </summary>
|
|
/// <param name="dogDto">Hund DTO</param>
|
|
/// <param name="photoFile">Foto-Datei</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <param name="photoFileName">Dateiname Photo</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> UpdateDogAsync(DogDto dogDto, string photoFileName, byte[] photoFile, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(dogDto, _jsonOptions);
|
|
var multipartContent = new MultipartFormDataContent();
|
|
multipartContent.Add(new StringContent(json, Encoding.UTF8, "application/json"), "model");
|
|
if (!string.IsNullOrEmpty(photoFileName) && photoFile != null)
|
|
{
|
|
multipartContent.Add(new ByteArrayContent(photoFile), "photoUpdateFile", photoFileName);
|
|
}
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/dogs/Update", multipartContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Löschen eines Hundes am Server
|
|
/// </summary>
|
|
/// <param name="dogDto">Hund DTO</param>
|
|
/// <param name="appUserId">Id des App-Users</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> DeleteDogAsync(DogDto dogDto, string appUserId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(dogDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
var paramAppUserId = HttpUtility.UrlEncode(appUserId);
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/dogs/Delete?appUserId={paramAppUserId}", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt die Anzahl öffentlicher Anfragen für einen Benutzer zurück
|
|
/// </summary>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<int>> CountPublicWalkRequestsAsync(string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<int>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/walks/CountPublicWalkRequests", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var countString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var count = int.Parse(countString);
|
|
|
|
result.Success = true;
|
|
result.Value = count;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Walks
|
|
|
|
/// <summary>
|
|
/// Holen der öffentlichen Anfragen vom Server
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des AppUsers</param>
|
|
/// <param name="lastUpdate">Wann wurden das letzte mal Daten erfolgreich geholt? Wenn null, dann alle Daten</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<PublicWalkRequest>>> GetPublicWalkRequestsForSyncAsync(string appUserId, DateTimeOffset? lastUpdate, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<PublicWalkRequest>>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var appUserIdString = HttpUtility.UrlEncode(appUserId);
|
|
var lastUpdateString = HttpUtility.UrlEncode(lastUpdate.ToString());
|
|
if (lastUpdate.HasValue)
|
|
lastUpdateString = HttpUtility.UrlEncode(lastUpdate.Value.ToString("o"));
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/walks/GetPublicWalkRequestsForSync?appUserId={appUserIdString}&lastUpdate={lastUpdateString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<PublicWalkRequestDto>>(_jsonOptions, token);
|
|
|
|
var list = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = list;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen der öffentlichen Anfragen vom Server für die letzten
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des AppUsers</param>
|
|
/// <param name="language">Gewünschte Sprache</param>
|
|
/// <param name="take">Anzahl Datensätze</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<PublicWalkRequestWithNames>>> GetPublicWalkRequestsLatestAsync(string appUserId, string language, int take, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<PublicWalkRequestWithNames>>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var appUserIdString = HttpUtility.UrlEncode(appUserId);
|
|
var paramLanguage = HttpUtility.UrlEncode(language);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/walks/GetPublicWalkRequestsLatest?appUserId={appUserIdString}&language={paramLanguage}&take={take}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<PublicWalkRequestWithNamesDto>>(_jsonOptions, token);
|
|
|
|
var list = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = list;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen von öffentlichen Anfragen vom Server.
|
|
/// </summary>
|
|
/// <param name="query">Abfrageobjekt</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<ListCommunicationResult<List<PublicWalkRequestWithNames>>> GetPublicWalkRequestsAsync(PublicWalkRequestQueryDto query, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<PublicWalkRequestWithNames>>
|
|
{
|
|
Value = new List<PublicWalkRequestWithNames>()
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(query, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/GetPublicWalkRequests", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<ListResponseDto<PublicWalkRequestWithNamesDto>>(_jsonOptions, token);
|
|
|
|
var listings = listResponseDto.List.ToDomain();
|
|
result.Success = true;
|
|
result.Value = listings;
|
|
result.Total = listResponseDto.Total;
|
|
result.Skip = listResponseDto.Skip;
|
|
result.Take = listResponseDto.Take;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen von öffentlichen Anfragen vom Server - erweitert
|
|
/// </summary>
|
|
/// <param name="query">Abfrageobjekt</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<ListCommunicationResult<List<PublicWalkRequestWithNames>>> GetPublicWalkRequestsExAsync(PublicWalkRequestQueryExDto query, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<PublicWalkRequestWithNames>>
|
|
{
|
|
Value = new List<PublicWalkRequestWithNames>()
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(query, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/GetPublicWalkRequestsEx", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<ListResponseDto<PublicWalkRequestWithNamesDto>>(_jsonOptions, token);
|
|
|
|
var listings = listResponseDto.List.ToDomain();
|
|
result.Success = true;
|
|
result.Value = listings;
|
|
result.Total = listResponseDto.Total;
|
|
result.Skip = listResponseDto.Skip;
|
|
result.Take = listResponseDto.Take;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen von öffentlichen Anfragen vom Server mit einem Antwortstatus für einen DogWalker
|
|
/// </summary>
|
|
/// <param name="query">Abfrageobjekt</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<ListCommunicationResult<List<PublicWalkRequestWithNamesAndResponseStatus>>> GetPublicWalkRequestsWithResponseStatusAsync(PublicWalkRequestAndResponseStatusQueryDto query, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<PublicWalkRequestWithNamesAndResponseStatus>>
|
|
{
|
|
Value = new List<PublicWalkRequestWithNamesAndResponseStatus>()
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(query, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/GetPublicWalkRequestsAndResponseStatus", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<ListResponseDto<PublicWalkRequestWithNamesAndResponseStatusDto>>(_jsonOptions, token);
|
|
|
|
var listings = listResponseDto.List.ToDomain();
|
|
result.Success = true;
|
|
result.Value = listings;
|
|
result.Total = listResponseDto.Total;
|
|
result.Skip = listResponseDto.Skip;
|
|
result.Take = listResponseDto.Take;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen von öffentlichen Anfragen vom Server mit einem Antwortstatus für einen DogWalker mit erweiterten Suchparametern
|
|
/// </summary>
|
|
/// <param name="query">Abfrageobjekt</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<ListCommunicationResult<List<PublicWalkRequestWithNamesAndResponseStatus>>> GetPublicWalkRequestsWithResponseStatusExAsync(PublicWalkRequestAndResponseStatusQueryExDto query, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<PublicWalkRequestWithNamesAndResponseStatus>>
|
|
{
|
|
Value = new List<PublicWalkRequestWithNamesAndResponseStatus>()
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(query, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/GetPublicWalkRequestsAndResponseStatusEx", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<ListResponseDto<PublicWalkRequestWithNamesAndResponseStatusDto>>(_jsonOptions, token);
|
|
|
|
var listings = listResponseDto.List.ToDomain();
|
|
result.Success = true;
|
|
result.Value = listings;
|
|
result.Total = listResponseDto.Total;
|
|
result.Skip = listResponseDto.Skip;
|
|
result.Take = listResponseDto.Take;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen einer öffntlichen Anfrage vom Server.
|
|
/// </summary>
|
|
/// <param name="id">Id der Anfrage</param>
|
|
/// <param name="language">Gewünschte Sprache</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<PublicWalkRequestWithNames>> GetPublicWalkRequestWithNamesAsync(string id, string language, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<PublicWalkRequestWithNames>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var param = HttpUtility.UrlEncode(id);
|
|
var param2 = HttpUtility.UrlEncode(language);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/walks/GetPublicWalkRequests?id={param}&language={param2}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<PublicWalkRequestWithNamesDto>(_jsonOptions, token);
|
|
|
|
var request = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = request;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Anlegen einer öffentlichen Anfrage am Server
|
|
/// </summary>
|
|
/// <param name="requestDto">Öffentliche Anfrage</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<CreateResponse<PublicWalkRequest>>> CreatePublicWalkRequestAsync(PublicWalkRequestCreateDto requestDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<CreateResponse<PublicWalkRequest>>()
|
|
{
|
|
Success = false
|
|
};
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(requestDto, _jsonOptions);
|
|
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/CreatePublicWalkRequest", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var serverResponse = await serverResult.Content.ReadFromJsonAsync<CreateResponseDto<PublicWalkRequestDto>>(_jsonOptions, token);
|
|
|
|
var createResponse = new CreateResponse<PublicWalkRequest>
|
|
{
|
|
Status = (CreateStatus)serverResponse.Status,
|
|
Value = serverResponse.Value.ToDomain()
|
|
};
|
|
|
|
result.Success = true;
|
|
result.Value = createResponse;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aktualisieren einer öffentlichen Anfrage am Server
|
|
/// </summary>
|
|
/// <param name="requestDto">Anfrage DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> UpdatePublicWalkRequestAsync(PublicWalkRequestDto requestDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(requestDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/UpdatePublicWalkRequest", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Löschen einer öffentlichen Anfrage am Server
|
|
/// </summary>
|
|
/// <param name="requestDto">Anfrage DTO</param>
|
|
/// <param name="appUserId">Id des App-Users</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> DeletePublicWalkRequestAsync(PublicWalkRequestDto requestDto, string appUserId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(requestDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
var paramAppUserId = HttpUtility.UrlEncode(appUserId);
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/DeletePublicWalkRequest?appUserId={paramAppUserId}", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Auswählen eines Angebotes zu einer öffentlichen Anfrage am Server
|
|
/// </summary>
|
|
/// <param name="requestDto">Anfrage DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<Walk>> AcceptPublicWalkRequestAsync(PublicWalkRequestAcceptDto requestDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<Walk>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(requestDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/AcceptPublicWalkRequest", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<WalkDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = dto.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stornieren einer öffentlichen Anfrage am Server
|
|
/// </summary>
|
|
/// <param name="requestDto">Anfrage DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> CancelPublicWalkRequestAsync(PublicWalkRequestCancelDto requestDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(requestDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/CancelPublicWalkRequest", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen der Antworten zu öffentlichen Anfragen vom Server
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des AppUsers</param>
|
|
/// <param name="lastUpdate">Wann wurden das letzte mal Daten erfolgreich geholt? Wenn null, dann alle Daten</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<PublicWalkResponse>>> GetPublicWalkResponsesForSyncAsync(string appUserId, DateTimeOffset? lastUpdate, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<PublicWalkResponse>>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var appUserIdString = HttpUtility.UrlEncode(appUserId);
|
|
var lastUpdateString = HttpUtility.UrlEncode(lastUpdate.ToString());
|
|
if (lastUpdate.HasValue)
|
|
lastUpdateString = HttpUtility.UrlEncode(lastUpdate.Value.ToString("o"));
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/walks/GetPublicWalkResponseForWalker?appUserId={appUserIdString}&lastUpdate={lastUpdateString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<PublicWalkResponseDto>>(_jsonOptions, token);
|
|
|
|
var list = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = list;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen einer Antworten zu öffentlichen Anfragen vom Server
|
|
/// </summary>
|
|
/// <param name="publicWalkResponseId">Id der Antwort zur öffentlichen Anfrage</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<PublicWalkResponse>> GetPublicWalkResponseAsync(string publicWalkResponseId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<PublicWalkResponse>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var param = HttpUtility.UrlEncode(publicWalkResponseId);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/walks/GetPublicWalkResponse?publicWalkResponseId={param}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<PublicWalkResponseDto>(_jsonOptions, token);
|
|
|
|
var response = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = response;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen einer Antworten zu öffentlichen Anfragen vom Server
|
|
/// </summary>
|
|
/// <param name="publicWalkResponseId">Id der Antwort zur öffentlichen Anfrage</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<PublicWalkResponseWithNames>> GetPublicWalkResponseWithNamesAsync(string publicWalkResponseId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<PublicWalkResponseWithNames>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var param = HttpUtility.UrlEncode(publicWalkResponseId);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/walks/GetPublicWalkResponseWithNames?publicWalkResponseId={param}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<PublicWalkResponseWithNamesDto>(_jsonOptions, token);
|
|
|
|
var response = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = response;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen einer Antworten zu öffentlichen Anfragen vom Server
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des AppUsers</param>
|
|
/// <param name="publicWalkRequestId">Id der öffentlichen Anfrage</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<PublicWalkResponse>> GetPublicWalkResponseForWalkerAsync(string appUserId, string publicWalkRequestId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<PublicWalkResponse>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var param = HttpUtility.UrlEncode(appUserId);
|
|
var param2 = HttpUtility.UrlEncode(publicWalkRequestId);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/walks/GetPublicWalkResponseForWalker?appUserId={param}&publicWalkRequestId={param2}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<PublicWalkResponseDto>(_jsonOptions, token);
|
|
|
|
var response = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = response;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Anlegen einer Antwort zu einer öffentlichen Anfrage am Server
|
|
/// </summary>
|
|
/// <param name="responseDto">Antwort zur Öffentliche Anfrage</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<CreateResponse<PublicWalkResponse>>> CreatePublicWalkResponseAsync(PublicWalkResponseDto responseDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<CreateResponse<PublicWalkResponse>>()
|
|
{
|
|
Success = false,
|
|
Value = new CreateResponse<PublicWalkResponse>()
|
|
{
|
|
Status = CreateStatus.Error,
|
|
Value = null
|
|
}
|
|
};
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(responseDto, _jsonOptions);
|
|
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/CreatePublicWalkResponse", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var serverResponse = await serverResult.Content.ReadFromJsonAsync<CreateResponseDto<PublicWalkResponseDto>>(_jsonOptions, token);
|
|
|
|
if (serverResponse.Status == CreateStatusDto.Success)
|
|
{
|
|
result.Success = true;
|
|
result.Value.Status = (CreateStatus)serverResponse.Status;
|
|
result.Value.Value = serverResponse.Value.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
result.Success = false;
|
|
result.Value.Status = (CreateStatus)serverResponse.Status;
|
|
result.Value.Value = null;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aktualisieren einer Antwort zu einer öffentlichen Anfrage am Server
|
|
/// </summary>
|
|
/// <param name="responseDto">Anfrage DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> UpdatePublicWalkResponseAsync(PublicWalkResponseDto responseDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(responseDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/UpdatePublicWalkResponse", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Löschen einer Antwort zu einer öffentlichen Anfrage am Server
|
|
/// </summary>
|
|
/// <param name="responseDto">Anfrage DTO</param>
|
|
/// <param name="appUserId">Id des App-Users</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> DeletePublicWalkResponseAsync(PublicWalkResponseDto responseDto, string appUserId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(responseDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
var paramAppUserId = HttpUtility.UrlEncode(appUserId);
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/DeletePublicWalkResponse?appUserId={paramAppUserId}", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen von Antworten zu einer öffentlichen Anfrage vom Server.
|
|
/// </summary>
|
|
/// <param name="query">Abfrageobjekt</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<ListCommunicationResult<List<PublicWalkResponseWithNames>>> GetPublicWalkresponsesAsync(PublicWalkResponseQueryDto query, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<PublicWalkResponseWithNames>>
|
|
{
|
|
Value = new List<PublicWalkResponseWithNames>()
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(query, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/GetPublicWalkResponses", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<ListResponseDto<PublicWalkResponseWithNamesDto>>(_jsonOptions, token);
|
|
|
|
var listings = listResponseDto.List.ToDomain();
|
|
result.Success = true;
|
|
result.Value = listings;
|
|
result.Total = listResponseDto.Total;
|
|
result.Skip = listResponseDto.Skip;
|
|
result.Take = listResponseDto.Take;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ablehnen eines Angebotes zu einer öffentlichen Anfrage am Server
|
|
/// </summary>
|
|
/// <param name="requestDto">Anfrage DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> DeclinePublicWalkResponseAsync(PublicWalkResponseDeclineDto requestDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(requestDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/DeclinePublicWalkResponse", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bearbeiten eines bereits gestellten Angebotes für eine offene Anfrage
|
|
/// </summary>
|
|
/// <param name="requestDto">Anfrage DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> EditPublicWalkResponseAsync(PublicWalkResponseEditDto requestDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(requestDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/EditPublicWalkResponse", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
case CommunicationErrors.Common_Entity_Changed:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
case CommunicationErrors.Common_Relation_Changed:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stornieren eines bereits gestellten Angebotes für eine offene Anfrage
|
|
/// </summary>
|
|
/// <param name="requestDto">Anfrage DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> CancelPublicWalkResponseAsync(PublicWalkResponseCancelDto requestDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(requestDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/CancelPublicWalkResponse", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
case CommunicationErrors.Common_Entity_Changed:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
case CommunicationErrors.Common_Relation_Changed:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen der Walsk vom Server
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des AppUsers</param>
|
|
/// <param name="lastUpdate">Wann wurden das letzte mal Daten erfolgreich geholt? Wenn null, dann alle Daten</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<Walk>>> GetWalksForSyncAsync(string appUserId, DateTimeOffset? lastUpdate, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<Walk>>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var appUserIdString = HttpUtility.UrlEncode(appUserId);
|
|
var lastUpdateString = HttpUtility.UrlEncode(lastUpdate.ToString());
|
|
if (lastUpdate.HasValue)
|
|
lastUpdateString = HttpUtility.UrlEncode(lastUpdate.Value.ToString("o"));
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/walks/GetWalksForSync?appUserId={appUserIdString}&lastUpdate={lastUpdateString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<WalkDto>>(_jsonOptions, token);
|
|
|
|
var list = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = list;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Anlegen eines Walks Anfrage am Server
|
|
/// </summary>
|
|
/// <param name="walkDto">Walk</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<CreateResponse<Walk>>> CreateWalkAsync(WalkDto walkDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<CreateResponse<Walk>>()
|
|
{
|
|
Success = false
|
|
};
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(walkDto, _jsonOptions);
|
|
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/CreateWalk", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var serverResponse = await serverResult.Content.ReadFromJsonAsync<CreateResponseDto<WalkDto>>(_jsonOptions, token);
|
|
|
|
var createResponse = new CreateResponse<Walk>
|
|
{
|
|
Status = (CreateStatus)serverResponse.Status,
|
|
Value = serverResponse.Value.ToDomain()
|
|
};
|
|
|
|
result.Success = true;
|
|
result.Value = createResponse;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aktualisieren eines Walks am Server
|
|
/// </summary>
|
|
/// <param name="walkDto">Walk DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> UpdateWalkAsync(WalkDto walkDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(walkDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/UpdateWalk", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Löschen eines Walks am Server
|
|
/// </summary>
|
|
/// <param name="walkDto">Walk DTO</param>
|
|
/// <param name="appUserId">Id des App-Users</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> DeleteWalkAsync(WalkDto walkDto, string appUserId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(walkDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
var paramAppUserId = HttpUtility.UrlEncode(appUserId);
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/DeleteWalk?appUserId={paramAppUserId}", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen von Walks mit Namen vom Server.
|
|
/// </summary>
|
|
/// <param name="query">Abfrageobjekt</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>ListCommunicationResult</returns>
|
|
public async Task<ListCommunicationResult<List<WalkWithNames>>> GetWalksWithNamesAsync(WalksQueryDto query, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<WalkWithNames>>
|
|
{
|
|
Value = new List<WalkWithNames>()
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(query, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/GetWalks", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<ListResponseDto<WalkWithNamesDto>>(_jsonOptions, token);
|
|
|
|
var listings = listResponseDto.List.ToDomain();
|
|
result.Success = true;
|
|
result.Value = listings;
|
|
result.Total = listResponseDto.Total;
|
|
result.Skip = listResponseDto.Skip;
|
|
result.Take = listResponseDto.Take;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt eine Liste der nächsten Walks, laufende, nicht abgeschlossene, nicht bezahlte usw. für einen Hundebesitzer zurück.
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des App-Users</param>
|
|
/// <param name="date">Datum ab dem gesucht</param>
|
|
/// <param name="language">Gewünschte Sprache</param>
|
|
/// <param name="skip">Datensätze auslassen</param>
|
|
/// <param name="take">Datensätze nehmen</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>ListCommunicationResult</returns>
|
|
public async Task<ListCommunicationResult<List<WalkWithNames>>> GetNextWalksOwnerAsync(string appUserId, DateTimeOffset date, string language, int take, int skip, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<WalkWithNames>>
|
|
{
|
|
Value = new List<WalkWithNames>()
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var query = new WalksNextQueryDto()
|
|
{
|
|
AppUserId = appUserId,
|
|
Date = date,
|
|
Language = language,
|
|
Skip = skip,
|
|
Take = take
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(query, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/GetNextWalksOwner", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<ListResponseDto<WalkWithNamesDto>>(_jsonOptions, token);
|
|
|
|
var listings = listResponseDto.List.ToDomain();
|
|
result.Success = true;
|
|
result.Value = listings;
|
|
result.Total = listResponseDto.Total;
|
|
result.Skip = listResponseDto.Skip;
|
|
result.Take = listResponseDto.Take;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt eine Liste der nächsten Walks, laufende, nicht abgeschlossene, nicht bezahlte usw. für einen Walker zurück.
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des App-Users</param>
|
|
/// <param name="date">Datum ab dem gesucht</param>
|
|
/// <param name="language">Gewünschte Sprache</param>
|
|
/// <param name="skip">Datensätze auslassen</param>
|
|
/// <param name="take">Datensätze nehmen</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>ListCommunicationResult</returns>
|
|
public async Task<ListCommunicationResult<List<WalkWithNames>>> GetNextWalksWalkerAsync(string appUserId, DateTimeOffset date, string language, int take, int skip, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<WalkWithNames>>
|
|
{
|
|
Value = new List<WalkWithNames>()
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var query = new WalksNextQueryDto()
|
|
{
|
|
AppUserId = appUserId,
|
|
Date = date,
|
|
Language = language,
|
|
Skip = skip,
|
|
Take = take
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(query, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/GetNextWalksWalker", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<ListResponseDto<WalkWithNamesDto>>(_jsonOptions, token);
|
|
|
|
var listings = listResponseDto.List.ToDomain();
|
|
result.Success = true;
|
|
result.Value = listings;
|
|
result.Total = listResponseDto.Total;
|
|
result.Skip = listResponseDto.Skip;
|
|
result.Take = listResponseDto.Take;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen von Walks mit Namen vom Server.
|
|
/// Sondersituation: Walker bekommen keine Walks unter dem Status Authorized zurück
|
|
/// </summary>
|
|
/// <param name="query">Abfrageobjekt</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>ListCommunicationResult</returns>
|
|
public async Task<ListCommunicationResult<List<WalkWithNames>>> GetWalksWithNamesWalkerAsync(WalksQueryDto query, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<WalkWithNames>>
|
|
{
|
|
Value = new List<WalkWithNames>()
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(query, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/GetWalksWalker", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<ListResponseDto<WalkWithNamesDto>>(_jsonOptions, token);
|
|
|
|
var listings = listResponseDto.List.ToDomain();
|
|
result.Success = true;
|
|
result.Value = listings;
|
|
result.Total = listResponseDto.Total;
|
|
result.Skip = listResponseDto.Skip;
|
|
result.Take = listResponseDto.Take;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen eines Walks mit Namen vom Server
|
|
/// </summary>
|
|
/// <param name="walkId">ID des Walks</param>
|
|
/// <param name="language">Gewünschte Sprache</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<WalkWithNames>> GetWalkWithNamesAsync(string walkId, string language, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<WalkWithNames>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var parameter = HttpUtility.UrlEncode(walkId);
|
|
var parameter2 = HttpUtility.UrlEncode(language);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/walks/GetWalkWithNames?walkId={parameter}&language={parameter2}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<WalkWithNamesDto>(_jsonOptions, token);
|
|
|
|
var walk = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = walk;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt einen Walk zurück, welcher einer öffentlichen Anfrage zugeordnet ist
|
|
/// </summary>
|
|
/// <param name="publicWalkRequestId">ID der öffentlichen Anfrage</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<Walk>> GetWalkByPublicRequestAsync(string publicWalkRequestId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<Walk>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var parameter = HttpUtility.UrlEncode(publicWalkRequestId);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/walks/GetWalkByPublicRequest?publicWalkRequestId={parameter}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<WalkDto>(_jsonOptions, token);
|
|
|
|
var walk = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = walk;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stornieren eines Walks am Server
|
|
/// </summary>
|
|
/// <param name="requestDto">Anfrage DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> CancelWalkAsync(WalkCancelDto requestDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(requestDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/CancelWalk", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Starten eines Walks am Server
|
|
/// </summary>
|
|
/// <param name="requestDto">Anfrage DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> StartWalkAsync(WalkStartDto requestDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(requestDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/StartWalk", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// abschließen eines Walks am Server
|
|
/// </summary>
|
|
/// <param name="requestDto">Anfrage DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> CompleteWalkAsync(WalkCompleteDto requestDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(requestDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/CompleteWalkEx", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bestätigen eines Walks am Server
|
|
/// </summary>
|
|
/// <param name="requestDto">Anfrage DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<Walk>> ConfirmWalkAsync(WalkConfirmDto requestDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<Walk>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(requestDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/ConfirmWalk", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
|
|
var serverResponse = await serverResult.Content.ReadFromJsonAsync<WalkDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = serverResponse.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bestätigen eines Walks am Server mit Rating
|
|
/// </summary>
|
|
/// <param name="requestDto">Anfrage DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<Walk>> ConfirmWalkWithRatingAsync(WalkConfirmWithRatingDto requestDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<Walk>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(requestDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/ConfirmWalkWithRating", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
|
|
var serverResponse = await serverResult.Content.ReadFromJsonAsync<WalkDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = serverResponse.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Setzen des Zahlungsstatus eines Walks am Server
|
|
/// </summary>
|
|
/// <param name="requestDto">Anfrage DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> SetWalkPaymentStatusAsync(WalkPaymentStatusDto requestDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(requestDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/SetPaymentStatus", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Prüfen ob ein Walk für einen Zeitraum gebucht werden kann
|
|
/// </summary>
|
|
/// <param name="requestDto">Anfrage DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> IsWalkPossibleAsync(WalkPossibleDto requestDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(requestDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/IsWalkPossible", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
var success = (bool.Parse(await serverResult.Content.ReadAsStringAsync(token)));
|
|
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = success;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Anlegen eines Walks wenn DIREKT! buchen möglich ist.
|
|
/// Wird online versucht und erst dann lokal gespeichert
|
|
/// </summary>
|
|
/// <param name="requestDto">Anfrage DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<CreateResponse<Walk>>> CreateWalkDirectAsync(WalkCreateDto requestDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<CreateResponse<Walk>>()
|
|
{
|
|
Success = false
|
|
};
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(requestDto, _jsonOptions);
|
|
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/CreateWalkDirect", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var serverResponse = await serverResult.Content.ReadFromJsonAsync<CreateResponseDto<WalkDto>>(_jsonOptions, token);
|
|
|
|
var createResponse = new CreateResponse<Walk>
|
|
{
|
|
Status = (CreateStatus)serverResponse.Status,
|
|
Value = serverResponse.Value.ToDomain()
|
|
};
|
|
|
|
result.Success = true;
|
|
result.Value = createResponse;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
case CommunicationErrors.Walk_NotPossible:
|
|
result.ErrorMessage = Errors.Walk_NotPossible;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Anlegen eines Walks als Anfrage
|
|
/// Wird online versucht und erst dann lokal gespeichert
|
|
/// </summary>
|
|
/// <param name="requestDto">Anfrage DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<CreateResponse<Walk>>> CreateWalkRequestAsync(WalkCreateDto requestDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<CreateResponse<Walk>>()
|
|
{
|
|
Success = false
|
|
};
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(requestDto, _jsonOptions);
|
|
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/CreateWalkRequest", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var serverResponse = await serverResult.Content.ReadFromJsonAsync<CreateResponseDto<WalkDto>>(_jsonOptions, token);
|
|
|
|
var createResponse = new CreateResponse<Walk>
|
|
{
|
|
Status = (CreateStatus)serverResponse.Status,
|
|
Value = serverResponse.Value.ToDomain()
|
|
};
|
|
|
|
result.Success = true;
|
|
result.Value = createResponse;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
case CommunicationErrors.Walk_NotPossible:
|
|
result.ErrorMessage = Errors.Walk_NotPossible;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Akzeptieren eines Walks am Server
|
|
/// </summary>
|
|
/// <param name="requestDto">Anfrage DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> AcceptWalkAsync(WalkAcceptDto requestDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(requestDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/AcceptWalk", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ablehnen eines Walks am Server
|
|
/// </summary>
|
|
/// <param name="requestDto">Anfrage DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> DeclineWalkAsync(WalkDeclineDto requestDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(requestDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/DeclineWalk", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reklamieren eines Walks am Server
|
|
/// </summary>
|
|
/// <param name="requestDto">Anfrage DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<Walk>> ComplainWalkAsync(WalkComplaintCreateDto requestDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<Walk>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(requestDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/walks/CreateWalkComplaint", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<WalkDto>(_jsonOptions, token);
|
|
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = dto.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Walk_NotCompleted:
|
|
result.ErrorMessage = Errors.Walk_NotCompleted;
|
|
break;
|
|
case CommunicationErrors.Walk_NotFound:
|
|
result.ErrorMessage = Errors.Walk_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen einer Reklamation zu einem Walk
|
|
/// </summary>
|
|
/// <param name="walkId">ID des Walks</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<WalkComplaint>> GetWalkComplaintAsync(string walkId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<WalkComplaint>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var parameter = HttpUtility.UrlEncode(walkId);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/walks/GetWalkComplaint?walkId={parameter}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<WalkComplaintDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = dto.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Ratings
|
|
|
|
/// <summary>
|
|
/// Holen der Ratings vom Server
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des AppUsers</param>
|
|
/// <param name="lastUpdate">Wann wurden das letzte mal Daten erfolgreich geholt? Wenn null, dann alle Daten</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<Rating>>> GetRatingsForSyncAsync(string appUserId, DateTimeOffset? lastUpdate, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<Rating>>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var appUserIdString = HttpUtility.UrlEncode(appUserId);
|
|
var lastUpdateString = HttpUtility.UrlEncode(lastUpdate.ToString());
|
|
if (lastUpdate.HasValue)
|
|
lastUpdateString = HttpUtility.UrlEncode(lastUpdate.Value.ToString("o"));
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/ratings/GetRatingsForSync?appUserId={appUserIdString}&lastUpdate={lastUpdateString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<RatingDto>>(_jsonOptions, token);
|
|
|
|
var list = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = list;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt ein Rating basierend auf Abfragekriterien zurück
|
|
/// </summary>
|
|
/// <param name="ratingCheckDto">Rating check DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<Rating>> GetRatingExAsync(RatingCheckQueryDto ratingCheckDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<Rating>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(ratingCheckDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/ratings/GetRatingEx", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<RatingDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = dto.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt ein Rating basierend auf der ID zurück
|
|
/// </summary>
|
|
/// <param name="ratingId">Id des Ratings</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<RatingWithNames>> GetRatingAsync(string ratingId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<RatingWithNames>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var ratingIdString = HttpUtility.UrlEncode(ratingId);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/ratings/GetRating?ratingId={ratingIdString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = null;
|
|
if (serverResult.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<RatingWithNamesDto>(_jsonOptions, token);
|
|
|
|
var rating = dto.ToDomain();
|
|
result.Value = rating;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Login_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Anlegen eines Ratings am Server
|
|
/// </summary>
|
|
/// <param name="ratingDto">Rating</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<CreateResponse<Rating>>> CreateRatingAsync(RatingDto ratingDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<CreateResponse<Rating>>()
|
|
{
|
|
Success = false
|
|
};
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(ratingDto, _jsonOptions);
|
|
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/ratings/CreateRating", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var serverResponse = await serverResult.Content.ReadFromJsonAsync<CreateResponseDto<RatingDto>>(_jsonOptions, token);
|
|
|
|
var createResponse = new CreateResponse<Rating>
|
|
{
|
|
Status = (CreateStatus)serverResponse.Status,
|
|
Value = serverResponse.Value.ToDomain()
|
|
};
|
|
|
|
result.Success = true;
|
|
result.Value = createResponse;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aktualisieren eines Ratings am Server
|
|
/// </summary>
|
|
/// <param name="ratingDto">Rating DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> UpdateRatingAsync(RatingDto ratingDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(ratingDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/ratings/UpdateRating", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Löschen eines Ratings am Server
|
|
/// </summary>
|
|
/// <param name="ratingDto">Rating DTO</param>
|
|
/// <param name="appUserId">Id des App-Users</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> DeleteRatingAsync(RatingDto ratingDto, string appUserId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(ratingDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
var paramAppUserId = HttpUtility.UrlEncode(appUserId);
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/ratings/DeleteRating?appUserId={paramAppUserId}", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Prüfen ob bereits ein Rating vorhanden ist
|
|
/// </summary>
|
|
/// <param name="ratingCheckDto">Rating check DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> HasRatedAsync(RatingCheckQueryDto ratingCheckDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(ratingCheckDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/ratings/HasRated", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
var success = (bool.Parse(await serverResult.Content.ReadAsStringAsync(token)));
|
|
|
|
SetIsOnline(true);
|
|
result.Success = success;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Prüfen ob ein Rating vorgenommen werden kann
|
|
/// </summary>
|
|
/// <param name="ratingCheckDto">Rating check DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> CanRateAsync(RatingCheckQueryDto ratingCheckDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(ratingCheckDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/ratings/CanRate", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
var success = (bool.Parse(await serverResult.Content.ReadAsStringAsync(token)));
|
|
|
|
SetIsOnline(true);
|
|
result.Success = success;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen von Ratings mit Namen vom Server.
|
|
/// </summary>
|
|
/// <param name="query">Abfrageobjekt</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>ListCommunicationResult</returns>
|
|
public async Task<ListCommunicationResult<List<RatingWithNames>>> GetRatingsWithNamesAsync(RatingsQueryDto query, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<RatingWithNames>>
|
|
{
|
|
Value = new List<RatingWithNames>()
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(query, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/ratings/GetRatings", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<ListResponseDto<RatingWithNamesDto>>(_jsonOptions, token);
|
|
|
|
var listings = listResponseDto.List.ToDomain();
|
|
result.Success = true;
|
|
result.Value = listings;
|
|
result.Total = listResponseDto.Total;
|
|
result.Skip = listResponseDto.Skip;
|
|
result.Take = listResponseDto.Take;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Feedback
|
|
|
|
/// <summary>
|
|
/// Anlegen eines Feedbacks am Server
|
|
/// </summary>
|
|
/// <param name="dto">Feedback</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<CreateResponse<AppFeedback>>> CreateFeedbackAsync(AppFeedbackCreateDto dto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<CreateResponse<AppFeedback>>()
|
|
{
|
|
Success = false
|
|
};
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(dto, _jsonOptions);
|
|
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/feedback/CreateFeedback", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var serverResponse = await serverResult.Content.ReadFromJsonAsync<CreateResponseDto<AppFeedbackDto>>(_jsonOptions, token);
|
|
|
|
var createResponse = new CreateResponse<AppFeedback>
|
|
{
|
|
Status = (CreateStatus)serverResponse.Status,
|
|
Value = serverResponse.Value.ToDomain()
|
|
};
|
|
|
|
result.Success = true;
|
|
result.Value = createResponse;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Favourites
|
|
|
|
/// <summary>
|
|
/// Holen der Favoriten vom Server
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des AppUsers</param>
|
|
/// <param name="lastUpdate">Wann wurden das letzte mal Daten erfolgreich geholt? Wenn null, dann alle Daten</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<Favourite>>> GetFavouritesForSyncAsync(string appUserId, DateTimeOffset? lastUpdate, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<Favourite>>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var appUserIdString = HttpUtility.UrlEncode(appUserId);
|
|
var lastUpdateString = HttpUtility.UrlEncode(lastUpdate.ToString());
|
|
if (lastUpdate.HasValue)
|
|
lastUpdateString = HttpUtility.UrlEncode(lastUpdate.Value.ToString("o"));
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/favourites/GetFavouritesForSync?appUserId={appUserIdString}&lastUpdate={lastUpdateString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<FavouriteDto>>(_jsonOptions, token);
|
|
|
|
var list = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = list;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Anlegen eines Favoriten am Server
|
|
/// </summary>
|
|
/// <param name="favouriteDto">Favorit</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<CreateResponse<Favourite>>> CreateFavouriteAsync(FavouriteDto favouriteDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<CreateResponse<Favourite>>()
|
|
{
|
|
Success = false
|
|
};
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(favouriteDto, _jsonOptions);
|
|
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/favourites/CreateFavourite", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var serverResponse = await serverResult.Content.ReadFromJsonAsync<CreateResponseDto<FavouriteDto>>(_jsonOptions, token);
|
|
|
|
var createResponse = new CreateResponse<Favourite>
|
|
{
|
|
Status = (CreateStatus)serverResponse.Status,
|
|
Value = serverResponse.Value.ToDomain()
|
|
};
|
|
|
|
result.Success = true;
|
|
result.Value = createResponse;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aktualisieren eines Favoriten am Server
|
|
/// </summary>
|
|
/// <param name="favouriteDto">Favorit DTO</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> UpdateFavouriteAsync(FavouriteDto favouriteDto, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(favouriteDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/favourites/UpdateFavourite", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Löschen eines Favoriten am Server
|
|
/// </summary>
|
|
/// <param name="favouriteDto">Favorit DTO</param>
|
|
/// <param name="appUserId">Id des App-Users</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> DeleteFavouriteAsync(FavouriteDto favouriteDto, string appUserId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(favouriteDto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
var paramAppUserId = HttpUtility.UrlEncode(appUserId);
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/favourites/DeleteFavourite?appUserId={paramAppUserId}", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen der Favoriten für einen Benutzer. Wird mit einem Objekt-Typen verwendet
|
|
/// </summary>
|
|
/// <param name="query">Abfrageobjekt</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<FavouriteListItem>>> GetFavouritesListAsync(FavouriteListQueryDto query, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<FavouriteListItem>>
|
|
{
|
|
Value = new List<FavouriteListItem>()
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(query, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/favourites/GetFavouritesList", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<List<FavouriteListItemDto>>(_jsonOptions, token);
|
|
|
|
var favourites = listResponseDto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = favourites;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Pushnotifications
|
|
|
|
/// <summary>
|
|
/// Registrieren / Aktualisieren eines Gerätes für Pushnotifications
|
|
/// </summary>
|
|
/// <param name="deviceInstallation">Geräte-Informationen</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> RegisterPushnotificationsAsync(DeviceInstallationDto deviceInstallation, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(deviceInstallation, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/pushnotifications/Register", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Pushnotification_Register_Failed:
|
|
result.ErrorMessage = Errors.Pushnotification_Register_Failed;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deregistrieren eines Gerätes für Pushnotifications
|
|
/// </summary>
|
|
/// <param name="installationId">Id der Installation</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> UnregisterPushnotificationsAsync(string installationId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
var parameterId = HttpUtility.UrlEncode(installationId);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/pushnotifications/Unregister?installationId={parameterId}", token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Pushnotification_Delete_Failed:
|
|
result.ErrorMessage = Errors.Pushnotification_Delete_Failed;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Wallets
|
|
|
|
/// <summary>
|
|
/// Holen der Wallets eines AppUsers vom Server
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des AppUsers</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<Wallet>>> GetWalletsAsync(string appUserId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<Wallet>>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var appUserIdString = HttpUtility.UrlEncode(appUserId);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/payments/GetWallets?appUserId={appUserIdString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<WalletDto>>(_jsonOptions, token);
|
|
|
|
var list = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = list;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt den Saldo eines Wallets zurück
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des App-Users</param>
|
|
/// <param name="walletType">Typ des Wallets</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<long>> GetWalletBalanceAsync(string appUserId, WalletType walletType, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<long>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var appUserIdString = HttpUtility.UrlEncode(appUserId);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/payments/GetWalletBalance?appUserId={appUserIdString}&walletType={walletType}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var balance = long.Parse(await serverResult.Content.ReadAsStringAsync(token));
|
|
|
|
result.Success = true;
|
|
result.Value = balance;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Bankkonten
|
|
|
|
/// <summary>
|
|
/// Holt ein Bankkonto für einen App-User vom Server
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des App-Users</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<BankAccount>> GetBankAccountsAsync(string appUserId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<BankAccount>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var appUserIdString = HttpUtility.UrlEncode(appUserId);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/payments/GetBankAccount?appUserId={appUserIdString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<BankAccountDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = dto.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.BankAccount_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Anlegen oder Bearbeiten eines Bankkontos
|
|
/// </summary>
|
|
/// <param name="bankAccount">Bankkonto</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult mit einem AppUser der die entsprechende BankId gesetzt hat</returns>
|
|
public async Task<CommunicationResult<AppUser>> CreateOrUpdateBankAccountAsync(BankAccountDto bankAccount, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<AppUser>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(bankAccount, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/payments/CreateOrUpdateBankAccount", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<AppUserDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = dto.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.BankAccount_CreateOrUpdate_Unchanged:
|
|
result.ErrorMessage = Errors.BankAccount_CreateOrUpdate_Unchanged;
|
|
break;
|
|
case CommunicationErrors.BankAccount_CreateOrUpdate_Failed:
|
|
result.ErrorMessage = Errors.BankAccount_CreateOrUpdate_Failed;
|
|
break;
|
|
case CommunicationErrors.BankAccount_Iban_Invalid:
|
|
result.ErrorMessage = Errors.BankAccount_Iban_Invalid;
|
|
break;
|
|
case CommunicationErrors.BankAccount_Bic_Invalid:
|
|
result.ErrorMessage = Errors.BankAccount_Bic_Invalid;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Transaktionsgebühren
|
|
|
|
/// <summary>
|
|
/// Holen der Transaktionsgebühren vom Server.
|
|
/// </summary>
|
|
/// <param name="lastUpdate">Wann wurden das letzte mal Daten erfolgreich geholt? Wenn null, dann alle Daten</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<TransactionFee>>> GetTransactionFeesAsync(DateTimeOffset? lastUpdate, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<TransactionFee>>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var lastUpdateString = HttpUtility.UrlEncode(lastUpdate.ToString());
|
|
if (lastUpdate.HasValue)
|
|
lastUpdateString = HttpUtility.UrlEncode(lastUpdate.Value.ToString("o"));
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/payments/GetTransactionFees?lastUpdate={lastUpdateString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<TransactionFeeDto>>(_jsonOptions, token);
|
|
|
|
var races = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = races;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Payment
|
|
|
|
/// <summary>
|
|
/// Authorisierung der Bezahlung eines Walks mit dem Guthaben eines Wallets
|
|
/// Das Geld wird vom Guthabenkonto auf das Transaktions-Konto gelegt
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des App-Users</param>
|
|
/// <param name="walkId">Id des Walks</param>
|
|
/// <param name="ammount">Zu zahlender Bertrag</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<Walk>> AuthorizeWalkWithCreditAsync(string appUserId, string walkId, decimal ammount, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<Walk>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var model = new PayWalkWithCreditDto()
|
|
{
|
|
AppUserId = appUserId,
|
|
WalkId = walkId,
|
|
Ammount = ammount
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(model, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/payments/AuthorizeWithCredit", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<WalkDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = dto.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Walk_PaymentStatus_Invalid:
|
|
result.ErrorMessage = Errors.Walk_PaymentStatus_Invalid;
|
|
break;
|
|
case CommunicationErrors.Walk_Cancelled:
|
|
result.ErrorMessage = Errors.Walk_Cancelled;
|
|
break;
|
|
case CommunicationErrors.Walk_NotFound:
|
|
result.ErrorMessage = Errors.Walk_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Authorisierung der Bezahlung eines Walks komplett mit einem Gutschein
|
|
/// </summary>
|
|
/// <param name="voucherId">Id des Gutscheins</param>
|
|
/// <param name="voucherCode">Code des Gutscheins</param>
|
|
/// <param name="appUserId">Id des App-Users</param>
|
|
/// <param name="walkId">Id des Walks</param>
|
|
/// <param name="ammount">Zu zahlender Bertrag</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<Walk>> AuthorizeWalkWithVoucherAsync(string voucherId, string voucherCode, string appUserId, string walkId, decimal ammount, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<Walk>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var model = new PayWalkWithVoucherDto()
|
|
{
|
|
VoucherId = voucherId,
|
|
Code = voucherCode,
|
|
AppUserId = appUserId,
|
|
WalkId = walkId,
|
|
Ammount = ammount
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(model, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/payments/AuthorizeWithVoucher", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<WalkDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = dto.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Walk_VoucherInvalid:
|
|
result.ErrorMessage = Errors.Walk_Voucher_Invalid;
|
|
break;
|
|
case CommunicationErrors.Walk_PaymentStatus_Invalid:
|
|
result.ErrorMessage = Errors.Walk_PaymentStatus_Invalid;
|
|
break;
|
|
case CommunicationErrors.Walk_Cancelled:
|
|
result.ErrorMessage = Errors.Walk_Cancelled;
|
|
break;
|
|
case CommunicationErrors.Walk_NotFound:
|
|
result.ErrorMessage = Errors.Walk_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Einzahlen einer Summe auf das Transaktions-Konto eines App-Users mit Bezug auf einen Walk.
|
|
/// Es können gebühren sofort auf das Transaktions-Konto des Mandanten abgeführt werden
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des App-Users</param>
|
|
/// <param name="walkId">Id des Walks</param>
|
|
/// <param name="ammount">Zu zahlender Bertrag</param>
|
|
/// <param name="fees">Anfallende Gebühren</param>
|
|
/// <param name="fromCredit">Betrag der zusätzlich vom Guthabenkonto bezahlt werden muss</param>
|
|
/// <param name="payInType">Typ der Einzahlung</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult mit dem ReturnUrl, wenn erfolgreich</returns>
|
|
public async Task<CommunicationResult<string>> PayInAsync(string appUserId, string walkId, decimal ammount, decimal fees, decimal fromCredit, PayInType payInType, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<string>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var model = new PayInDto()
|
|
{
|
|
AppUserId = appUserId,
|
|
WalkId = walkId,
|
|
Ammount = ammount,
|
|
Fees = fees,
|
|
FromCredit = fromCredit,
|
|
PayInType = payInType.ToDto()
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(model, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/payments/PayIn", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<PayInResponseDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = dto.Url;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.PayIn_Failed:
|
|
result.ErrorMessage = Errors.PayIn_Failed;
|
|
break;
|
|
case CommunicationErrors.Walk_PaymentStatus_Invalid:
|
|
result.ErrorMessage = Errors.Walk_PaymentStatus_Invalid;
|
|
break;
|
|
case CommunicationErrors.Walk_Cancelled:
|
|
result.ErrorMessage = Errors.Walk_Cancelled;
|
|
break;
|
|
case CommunicationErrors.Walk_NotFound:
|
|
result.ErrorMessage = Errors.Walk_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region KYC
|
|
|
|
/// <summary>
|
|
/// Holen der letzten KYC-Dokumente eines App-Users
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des App-Users</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult mit dem aktuell gültigen KYC-Dokument oder null, wenn keines vorhanden</returns>
|
|
public async Task<CommunicationResult<IdentityDocument>> GetLatestKycDocumentAsync(string appUserId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<IdentityDocument>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var appUserIdString = HttpUtility.UrlEncode(appUserId);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/payments/GetKycDocumentLatest?appUserId={appUserIdString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<IdentityDocumentDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = dto.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Kyc_NoDocument:
|
|
result.ErrorMessage = Errors.Kyc_NoDocument;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// KYC-Dokument für einen App-User erstellen mit einer Seite
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des App-Users</param>
|
|
/// <param name="source">Dokument-Quelle</param>
|
|
/// <param name="fileOneName">Dateiname</param>
|
|
/// <param name="fileOne">Datei als byte-Array</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult mit dem aktuell erstellten KYC-Dokument</returns>
|
|
public async Task<CommunicationResult<IdentityDocument>> CreateKycDocumentAsync(string appUserId, IdentityDocumentSource source, string fileOneName, byte[] fileOne, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<IdentityDocument>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var model = new IdentityDocumentCreateDto()
|
|
{
|
|
AppUserId = appUserId,
|
|
Source = source.ToDto()
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(model, _jsonOptions);
|
|
var multipartContent = new MultipartFormDataContent();
|
|
multipartContent.Add(new StringContent(json, Encoding.UTF8, "application/json"), "model");
|
|
if (!string.IsNullOrEmpty(fileOneName) && fileOne != null)
|
|
{
|
|
multipartContent.Add(new ByteArrayContent(fileOne), "files", fileOneName);
|
|
}
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/payments/CreatKycDocument", multipartContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<IdentityDocumentDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = dto.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Kyc_CreationFailed:
|
|
result.ErrorMessage = Errors.Kyc_CreationFailed;
|
|
break;
|
|
case CommunicationErrors.Kyc_NoFiles:
|
|
result.ErrorMessage = Errors.Kyc_NoFiles;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// KYC-Dokument für einen App-User erstellen mit zwei Seiten
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des App-Users</param>
|
|
/// <param name="source">Dokument-Quelle</param>
|
|
/// <param name="fileOneName">Dateiname Datei 1</param>
|
|
/// <param name="fileOne">Datei 1 als byte-Array</param>
|
|
/// <param name="fileTwoName">Dateiname Datei 2</param>
|
|
/// <param name="fileTwo">Datei 2 als byte-Array</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult mit dem aktuell erstellten KYC-Dokument</returns>
|
|
public async Task<CommunicationResult<IdentityDocument>> CreateKycDocumentAsync(string appUserId, IdentityDocumentSource source, string fileOneName, byte[] fileOne, string fileTwoName, byte[] fileTwo, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<IdentityDocument>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var model = new IdentityDocumentCreateDto()
|
|
{
|
|
AppUserId = appUserId,
|
|
Source = source.ToDto()
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(model, _jsonOptions);
|
|
var multipartContent = new MultipartFormDataContent();
|
|
multipartContent.Add(new StringContent(json, Encoding.UTF8, "application/json"), "model");
|
|
if (!string.IsNullOrEmpty(fileOneName) && fileOne != null)
|
|
{
|
|
multipartContent.Add(new ByteArrayContent(fileOne), "files", fileOneName);
|
|
}
|
|
if (!string.IsNullOrEmpty(fileTwoName) && fileTwo != null)
|
|
{
|
|
multipartContent.Add(new ByteArrayContent(fileTwo), "files", fileTwoName);
|
|
}
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/payments/CreatKycDocument", multipartContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<IdentityDocumentDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = dto.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Kyc_CreationFailed:
|
|
result.ErrorMessage = Errors.Kyc_CreationFailed;
|
|
break;
|
|
case CommunicationErrors.Kyc_NoFiles:
|
|
result.ErrorMessage = Errors.Kyc_NoFiles;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Payouts
|
|
|
|
/// <summary>
|
|
/// Holen der Auszahlungen vom Server
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des AppUsers</param>
|
|
/// <param name="lastUpdate">Wann wurden das letzte mal Daten erfolgreich geholt? Wenn null, dann alle Daten</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<Payout>>> GetPayoutsForSyncAsync(string appUserId, DateTimeOffset? lastUpdate, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<Payout>>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var appUserIdString = HttpUtility.UrlEncode(appUserId);
|
|
var lastUpdateString = HttpUtility.UrlEncode(lastUpdate.ToString());
|
|
if (lastUpdate.HasValue)
|
|
lastUpdateString = HttpUtility.UrlEncode(lastUpdate.Value.ToString("o"));
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/payments/GetPayoutsForSync?appUserId={appUserIdString}&lastUpdate={lastUpdateString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<PayoutDto>>(_jsonOptions, token);
|
|
|
|
var list = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = list;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen von Auszahlungen vom Server.
|
|
/// </summary>
|
|
/// <param name="query">Abfrageobjekt</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>ListCommunicationResult</returns>
|
|
public async Task<ListCommunicationResult<List<Payout>>> GetPayoutsAsync(PayoutQueryDto query, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new ListCommunicationResult<List<Payout>>
|
|
{
|
|
Value = new List<Payout>()
|
|
};
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var json = JsonSerializer.Serialize(query, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/payments/GetPayouts", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var listResponseDto = await serverResult.Content.ReadFromJsonAsync<ListResponseDto<PayoutDto>>(_jsonOptions, token);
|
|
|
|
var listings = listResponseDto.List.ToDomain();
|
|
result.Success = true;
|
|
result.Value = listings;
|
|
result.Total = listResponseDto.Total;
|
|
result.Skip = listResponseDto.Skip;
|
|
result.Take = listResponseDto.Take;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Erstellen einer Auszahlung
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des App-Users</param>
|
|
/// <param name="ammount">Betrag der ausgezahlt werden soll</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<Payout>> CreatePayoutAsync(string appUserId, decimal ammount, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<Payout>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var model = new PayoutCreateDto()
|
|
{
|
|
AppUserId = appUserId,
|
|
Ammount = ammount
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(model, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/payments/CreatePayout", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<PayoutDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = dto.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.PayOut_Failed:
|
|
result.ErrorMessage = Errors.PayOut_Failed;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt eine Auszahlung eines App-Users zurück
|
|
/// </summary>
|
|
/// <param name="appUserId">Id des App-Users</param>
|
|
/// <param name="payoutId">Id der Auszahlung</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<Payout>> GetPayoutAsync(string appUserId, string payoutId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<Payout>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var appUserIdString = HttpUtility.UrlEncode(appUserId);
|
|
var payoutIdString = HttpUtility.UrlEncode(payoutId);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/payments/GetPayout?appUserId={appUserIdString}&payoutId={payoutIdString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<PayoutDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = dto.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.PayOut_NotFound:
|
|
result.ErrorMessage = Errors.PayOut_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region AppVersion
|
|
|
|
/// <summary>
|
|
/// Holen der aktuellen Version am Server für die gewählte Plattform
|
|
/// </summary>
|
|
/// <param name="platform">Plattform</param>
|
|
/// <param name="language">Sprache</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<AppVersionCheck>> CheckCurrentAppVersionAsync(PlatformDto platform, string language, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<AppVersionCheck>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var languageString = HttpUtility.UrlEncode(language);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/status/CheckAppVersion?platform={platform}&language={languageString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<AppVersionCheckDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = dto.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen der aktuellen Version am Server für die gewählte Plattform
|
|
/// </summary>
|
|
/// <param name="platform">Plattform</param>
|
|
/// <param name="language">Sprache</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<AppVersion>> GetCurrentAppVersionAsync(PlatformDto platform, string language, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<AppVersion>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var languageString = HttpUtility.UrlEncode(language);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/status/AppVersion?platform={platform}&language={languageString}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<AppVersionDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = dto.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Vouchers - Gutscheine
|
|
|
|
/// <summary>
|
|
/// Validieren eines Gutschein-Codes für einen AppUser
|
|
/// </summary>
|
|
/// <param name="voucherCode">Gutscheincode</param>
|
|
/// <param name="appUserId">Id des AppUsers</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<CheckVoucherCodeResult>> CheckVoucherCodeAsync(string voucherCode, string appUserId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<CheckVoucherCodeResult>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var model = new CheckVoucherCodeDto()
|
|
{
|
|
Code = voucherCode,
|
|
AppUserId = appUserId
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(model, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/vouchers/CheckVoucherCode", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<CheckVoucherCodeResultDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = dto.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Versucht einen Gutscheincode mit Hilfe eines QR-Codes zu holen
|
|
/// </summary>
|
|
/// <param name="qrCode">QR-Code in Text</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<string>> GetVoucherCodeByQrCode(string qrCode, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<string>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var model = new GetVoucherByQrCodeDto()
|
|
{
|
|
QrCode = qrCode
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(model, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/vouchers/GetVoucherCodeByQrCode", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<VoucherByQrCodeResultDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = dto.Code;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Versucht einen Gutschein zu reservieren
|
|
/// </summary>
|
|
/// <param name="voucherId">Id des Gutscheins</param>
|
|
/// <param name="code">Code des Gutscheins</param>
|
|
/// <param name="appUserId">Id des AppUsers</param>
|
|
/// <param name="walkId">Id des Walks</param>
|
|
/// <param name="ammount">Betrag - kann kleiner Gutscheinwert sein</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<ReserveVoucherResult>> ReserveVoucherAsync(string voucherId, string code, string appUserId, string walkId, decimal ammount, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<ReserveVoucherResult>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var model = new ReserveVoucherDto()
|
|
{
|
|
VoucherId = voucherId,
|
|
Code = code,
|
|
AppUserId = appUserId,
|
|
WalkId = walkId,
|
|
Ammount = ammount
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(model, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/vouchers/ReserveVoucher", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<ReserveVoucherResultDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = dto.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stornieren eines Gutscheins
|
|
/// </summary>
|
|
/// <param name="voucherId">Id des Gutscheins</param>
|
|
/// <param name="appUserId">Id des AppUsers</param>
|
|
/// <param name="walkId">Id des Walks</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<bool>> CancelVoucherAsync(string voucherId, string appUserId, string walkId, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<bool>(){Value = false};
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var model = new CancelVoucherDto()
|
|
{
|
|
VoucherId = voucherId,
|
|
AppUserId = appUserId,
|
|
WalkId = walkId
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(model, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/vouchers/CancelVoucher", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
|
|
result.Success = true;
|
|
result.Value = true;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Abos - Subscriptions
|
|
|
|
/// <summary>
|
|
/// Gibt eine Liste von verfügbaren Abos zurück
|
|
/// </summary>
|
|
/// <param name="appMode">AppMode - Hundebesitzer oder Walker</param>
|
|
/// <param name="language">Sprache</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<Subscription>>> GetSubscriptionsAsync(AppMode appMode, string language, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<Subscription>>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/subscriptions/GetAll?appMode={appMode}&language={language}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<SubscriptionDto>>(_jsonOptions, token);
|
|
|
|
var subscriptions = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = subscriptions;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt eine Liste von gebuchten Abos zurück
|
|
/// </summary>
|
|
/// <param name="language">Sprache</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<AppUserSubscription>>> GetMySubscriptionsAsync(string language, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<AppUserSubscription>>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/subscriptions/GetMy?language={language}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<AppUserSubscriptionDto>>(_jsonOptions, token);
|
|
|
|
var subscriptions = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = subscriptions;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt eine Liste von gebuchten und aktiven Abos zurück
|
|
/// </summary>
|
|
/// <param name="language">Sprache</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<List<AppUserSubscription>>> GetMyActiveSubscriptionsAsync(string language, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<List<AppUserSubscription>>();
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var serverResult = await _httpClient.GetAsync($"api/subscriptions/GetMy/active?language={language}", token).ConfigureAwait(false);
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var dto = await serverResult.Content.ReadFromJsonAsync<List<AppUserSubscriptionDto>>(_jsonOptions, token);
|
|
|
|
var subscriptions = dto.ToDomain();
|
|
result.Success = true;
|
|
result.Value = subscriptions;
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Erstellen einer Abo-Buchung
|
|
/// </summary>
|
|
/// <param name="appUserId">AppUserId</param>
|
|
/// <param name="subscriptionId">Id des Abos</param>
|
|
/// <param name="language">Sprache</param>
|
|
/// <param name="inAppBillingPurchase">InAppBillingPurchase serialisiert als JSON</param>
|
|
/// <param name="expirationDateToSet">Optional: Ablaufdatum das gesetzt werden soll</param>
|
|
/// <param name="platform">Plattform auf der das Abo erstellt wird</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<CreateResponse<AppUserSubscription>>> CreateSubscriptionAsync(string appUserId, string subscriptionId, string language, string inAppBillingPurchase, DateTime? expirationDateToSet, Platform platform, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<CreateResponse<AppUserSubscription>>()
|
|
{
|
|
Success = false,
|
|
Value = new CreateResponse<AppUserSubscription>()
|
|
{
|
|
Status = CreateStatus.Error,
|
|
Value = null
|
|
}
|
|
};
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var dto = new AppUserCreateSubscriptionDto()
|
|
{
|
|
AppUserId = appUserId,
|
|
SubscriptionId = subscriptionId,
|
|
Language = language,
|
|
InAppBillingPurchaseJson = inAppBillingPurchase,
|
|
ExpirationDateToSet = expirationDateToSet,
|
|
Platform = platform.ToDto()
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(dto, _jsonOptions);
|
|
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/subscriptions/Create", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var serverResponse = await serverResult.Content.ReadFromJsonAsync<CreateResponseDto<AppUserSubscriptionDto>>(_jsonOptions, token);
|
|
|
|
if (serverResponse.Status == CreateStatusDto.Success)
|
|
{
|
|
result.Success = true;
|
|
result.Value.Status = (CreateStatus)serverResponse.Status;
|
|
result.Value.Value = serverResponse.Value.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
result.Success = false;
|
|
result.Value.Status = (CreateStatus)serverResponse.Status;
|
|
result.Value.Value = null;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Wechseln eines Abos in der Gruppe für eine Abo-Buchung
|
|
/// </summary>
|
|
/// <param name="bookingId">Id der Abo-Buchung</param>
|
|
/// <param name="appUserId">AppUserId</param>
|
|
/// <param name="subscriptionId">Id des Abos auf das gechselt werden soll</param>
|
|
/// <param name="language">Sprache</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<AppUserSubscription>> SwitchSubscriptionAsync(long bookingId, string appUserId, string subscriptionId, string language, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<AppUserSubscription>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var dto = new AppUserSwitchSubscriptionDto()
|
|
{
|
|
BookingId = bookingId,
|
|
AppUserId = appUserId,
|
|
SubscriptionId = subscriptionId,
|
|
Language = language
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(dto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/subscriptions/Switch", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var serverResponse = await serverResult.Content.ReadFromJsonAsync<AppUserSubscriptionDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = serverResponse.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stornieren einer Abo-Buchung
|
|
/// </summary>
|
|
/// <param name="bookingId">Abo-Buchungs ID</param>
|
|
/// <param name="appUserId">AppUserId</param>
|
|
/// <param name="language">Sprache</param>
|
|
/// <param name="platform">Plattform auf der das Abo erstellt wurde</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<AppUserSubscription>> CancelSubscriptionAsync(long bookingId, string appUserId, string language, Platform platform, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<AppUserSubscription>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var dto = new AppUserCancelSubscriptionDto()
|
|
{
|
|
BookingId = bookingId,
|
|
AppUserId = appUserId,
|
|
Language = language,
|
|
Platform = platform.ToDto()
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(dto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/subscriptions/Cancel", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var serverResponse = await serverResult.Content.ReadFromJsonAsync<AppUserSubscriptionDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = serverResponse.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verlängern einer Abo-Buchung
|
|
/// </summary>
|
|
/// <param name="bookingId">Abo-Buchungs ID</param>
|
|
/// <param name="appUserId">AppUserId</param>
|
|
/// <param name="language">Sprache</param>
|
|
/// <param name="platform">Plattform auf der das Abo erstellt wurde</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<AppUserSubscription>> RenewSubscriptionAsync(long bookingId, string appUserId, string language, Platform platform, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<AppUserSubscription>();
|
|
|
|
try
|
|
{
|
|
SetClientTime();
|
|
SetAccessToken(accessToken);
|
|
|
|
var dto = new AppUserRenewSubscriptionDto()
|
|
{
|
|
BookingId = bookingId,
|
|
AppUserId = appUserId,
|
|
Language = language,
|
|
Platform = platform.ToDto()
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(dto, _jsonOptions);
|
|
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
var serverResult = await _httpClient.PostAsync($"api/subscriptions/Renew", stringContent, token).ConfigureAwait(false);
|
|
|
|
if (serverResult.IsSuccessStatusCode)
|
|
{
|
|
SetIsOnline(true);
|
|
var serverResponse = await serverResult.Content.ReadFromJsonAsync<AppUserSubscriptionDto>(_jsonOptions, token);
|
|
|
|
result.Success = true;
|
|
result.Value = serverResponse.ToDomain();
|
|
}
|
|
else
|
|
{
|
|
var errorCodeString = await serverResult.Content.ReadAsStringAsync(token);
|
|
var errorCode = (CommunicationErrors)Enum.Parse(typeof(CommunicationErrors), errorCodeString);
|
|
result.ErrorCode = errorCode;
|
|
switch (errorCode)
|
|
{
|
|
case CommunicationErrors.Common_NotFound:
|
|
result.ErrorMessage = Errors.Common_NotFound;
|
|
break;
|
|
case CommunicationErrors.Common_Api_HeaderMissing:
|
|
result.ErrorMessage = Errors.Api_HeaderMissing;
|
|
break;
|
|
case CommunicationErrors.Common_Model_Invalid:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
break;
|
|
default:
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
#if DEBUG
|
|
result.ErrorMessage = $"{ex.Message} - {ex.StackTrace}";
|
|
#else
|
|
result.ErrorMessage = Errors.Common_Undefined;
|
|
#endif
|
|
result.ErrorCode = CommunicationErrors.Undefined;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Private
|
|
|
|
/// <summary>
|
|
/// Setzt den Status des Communicationservice auf Online.
|
|
/// Wird von Methoden verwendet wenn diese erfolgreich kommunizieren konnten
|
|
/// </summary>
|
|
/// <param name="isOnline">true wenn online, false sonst</param>
|
|
private void SetIsOnline(bool isOnline)
|
|
{
|
|
_isOnline = isOnline;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Setzt das Access-Token für den HTTP-Client
|
|
/// </summary>
|
|
/// <param name="token">Access token</param>
|
|
private void SetAccessToken(string token)
|
|
{
|
|
var authHeader = new AuthenticationHeaderValue("bearer", token);
|
|
_httpClient.DefaultRequestHeaders.Authorization = authHeader;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Fügt die Zeit des Clients in den HTTP-Header
|
|
/// </summary>
|
|
private void SetClientTime()
|
|
{
|
|
_httpClient.DefaultRequestHeaders.Remove("clientTime");
|
|
_httpClient.DefaultRequestHeaders.Add("clientTime", DateTimeOffset.UtcNow.ToString("O"));
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|