150 lines
6.2 KiB
C#
150 lines
6.2 KiB
C#
using gehGassi.Core.Interfaces;
|
|
using gehGassi.Domain.Advertisements;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using gehGassi.Domain.Dogs;
|
|
using gehGassi.Domain.Common;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace gehGassi.Core.Services
|
|
{
|
|
/// <summary>
|
|
/// Service der die Verwaltung von Appversionen realisiert
|
|
/// </summary>
|
|
public class AppVersionService : ServiceBase<AppVersion>, IAppVersionService
|
|
{
|
|
private readonly IRepository<AppVersionWithNames> _namesRepository;
|
|
|
|
/// <summary>
|
|
/// Erstellt eine Instanz
|
|
/// </summary>
|
|
/// <param name="unitOfWork">Instanz einer IUnitOfWork</param>
|
|
public AppVersionService(IUnitOfWork unitOfWork) : base(unitOfWork)
|
|
{
|
|
_namesRepository = unitOfWork.GetRepository<AppVersionWithNames>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt eine gefilterte Liste von Appversionen zurück
|
|
/// </summary>
|
|
/// <param name="filter">Filterbegriff der in bestimmten Feldern gesucht wird</param>
|
|
/// <returns>List betroffener AppVersionen</returns>
|
|
public IQueryable<AppVersion> Filter(string filter)
|
|
{
|
|
return Repository.Query(c => c.ReleaseTitleLocalized.Contains(filter) || c.Version.Contains(filter));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Erstellen einer Appversion
|
|
/// </summary>
|
|
/// <returns>Listung</returns>
|
|
public AppVersion Create()
|
|
{
|
|
var item = new AppVersion()
|
|
{
|
|
Major = 1,
|
|
Minor = 0,
|
|
Version = "1.0",
|
|
IsCurrent = false,
|
|
IsMandatory = false,
|
|
Platform = Domain.Common.Platform.Android,
|
|
Build = null,
|
|
Revision = null,
|
|
ReleaseDate = DateTimeOffset.UtcNow,
|
|
LastUpdate = DateTimeOffset.UtcNow,
|
|
Created = DateTimeOffset.UtcNow
|
|
};
|
|
return item;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt eine gefilterte Liste von Appversionen zurück.
|
|
/// </summary>
|
|
/// <param name="filter">Filterbegriff der in bestimmten Feldern gesucht wird</param>
|
|
/// <returns>List betroffener Appversionen</returns>
|
|
public async Task<List<AppVersion>> SearchAsync(string filter)
|
|
{
|
|
return (await Repository.FindAsync(c => c.ReleaseTitleLocalized.Contains(filter) || c.Version.Contains(filter))).ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt eine gefilterte Liste von Appversionen mit Namen zurück in einer gewählten Sprache
|
|
/// </summary>
|
|
/// <param name="filter">Filterbegriff der in bestimmten Feldern gesucht wird</param>
|
|
/// <param name="language">Gewünschte Sprache</param>
|
|
/// <param name="fallback">Fallback Sprache</param>
|
|
/// <returns>Liste betroffener Appversionen</returns>
|
|
public IQueryable<AppVersionWithNames> FilterWithNames(string filter, string language, string fallback)
|
|
{
|
|
language = language.ToUpperInvariant();
|
|
fallback = fallback.ToUpperInvariant();
|
|
|
|
var baseQuery = _namesRepository.QueryStoredProcedure("SELECT * FROM tv_AppVersionsWithNames({0},{1})", c => c.ReleaseTitle.Contains(filter) || c.Version.Contains(filter), language, fallback);
|
|
|
|
return baseQuery;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt zurück ob eine Versionsnummer für eine Plattform bereits existiert
|
|
/// </summary>
|
|
/// <param name="platform">Plattform</param>
|
|
/// <param name="version">Versionsnummer die geprüft werden soll</param>
|
|
/// <param name="ignoreId">ID die ignoriert werden soll</param>
|
|
/// <returns>true wenn eine existiert, false sonst</returns>
|
|
public async Task<bool> VersionExistsAsync(Platform platform, string version, int ignoreId)
|
|
{
|
|
var count = await Repository.CountAsync(c => c.Platform == platform && c.Version == version && c.Id != ignoreId).ConfigureAwait(false);
|
|
return count > 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt zurück ob eine Plattform eine aktuelle Version hat
|
|
/// </summary>
|
|
/// <param name="platform">Plattform</param>
|
|
/// <param name="ignoreId">ID die ignoriert werden soll</param>
|
|
/// <returns>true wenn eine existiert, false sonst</returns>
|
|
public async Task<bool> HasCurrentAsync(Platform platform, int ignoreId)
|
|
{
|
|
var count = await Repository.CountAsync(c => c.Platform == platform && c.IsCurrent && c.Id != ignoreId).ConfigureAwait(false);
|
|
return count > 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Zurücksetzen der aktuellen Version einer Plattform. Es kann nur einen geben :)
|
|
/// </summary>
|
|
/// <param name="platform">Plattform</param>
|
|
/// <param name="userName">Benutzer der die Änderung vornimmt</param>
|
|
/// <returns>Task</returns>
|
|
public async Task ResetCurrentAsync(Platform platform, string userName)
|
|
{
|
|
var current = await Repository.FirstOrDefaultAsync(c => c.Platform == platform && c.IsCurrent).ConfigureAwait(false);
|
|
if (current != null)
|
|
{
|
|
current.IsCurrent = false;
|
|
await CommitAsync(userName).ConfigureAwait(false);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gibt die aktuelle Version einer Plattform zurück
|
|
/// </summary>
|
|
/// <param name="platform">Plattform</param>
|
|
/// <param name="language">Gewünschte Sprache</param>
|
|
/// <param name="fallback">Fallback Sprache</param>
|
|
/// <returns>Aktuelle Version oder null, wenn keine vorhanden</returns>
|
|
public async Task<AppVersionWithNames> GetCurrentwithNamesAsync(Platform platform, string language, string fallback)
|
|
{
|
|
language = language.ToUpperInvariant();
|
|
fallback = fallback.ToUpperInvariant();
|
|
|
|
var baseQuery = _namesRepository.QueryStoredProcedure("SELECT * FROM tv_AppVersionsWithNames({0},{1})", c => c.Platform == platform && c.IsCurrent, language, fallback);
|
|
|
|
var current = await baseQuery.FirstOrDefaultAsync().ConfigureAwait(false);
|
|
return current;
|
|
}
|
|
}
|
|
}
|