SocialPub/PrivaPub/Services/ClientToServer/Public/DataService.cs
2023-02-19 00:43:43 +01:00

37 lines
1.5 KiB
C#

using PrivaPub.Models.Data;
using PrivaPub.StaticServices;
namespace PrivaPub.Services.ClientToServer.Public
{
public class DataService : IDataService
{
readonly DbEntities DbEntities;
readonly AppConfigurationService AppConfigurationService;
public DataService(DbEntities dbCollections, AppConfigurationService appConfigurationService)
{
DbEntities = dbCollections;
AppConfigurationService = appConfigurationService;
}
public string GetCurrentVersion() =>
AppConfigurationService.AppConfiguration.Version;
public async Task<IEnumerable<Language>> GetLanguages(CancellationToken cancellationToken)
{
return (await DbEntities.Languages
.Match(l => AppConfigurationService.AppConfiguration.SupportedLanguages.Contains(l.International2Code))
.ExecuteAsync(cancellationToken)).OrderBy(l => l.NativeName).ToArray();
}
public async Task<bool> IsValidLanguageId(string languageId)
{
var anyLanguageWithId = await DbEntities.Languages.Match(l => l.ID == languageId).ExecuteAnyAsync();
if (!anyLanguageWithId)
return false;
var language2Code = (await DbEntities.Languages
.Match(l => l.ID == languageId).ExecuteFirstAsync())?.International2Code;
return AppConfigurationService.AppConfiguration.SupportedLanguages.Contains(language2Code);
}
}
}