2023-02-19 00:43:43 +01:00
|
|
|
|
using PrivaPub.Models.Data;
|
|
|
|
|
using PrivaPub.StaticServices;
|
2023-02-18 08:52:17 +01:00
|
|
|
|
|
2023-02-19 00:43:43 +01:00
|
|
|
|
namespace PrivaPub.Services.ClientToServer.Public
|
2023-02-18 08:52:17 +01:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
2023-02-19 00:43:43 +01:00
|
|
|
|
public async Task<IEnumerable<Language>> GetLanguages(CancellationToken cancellationToken)
|
2023-02-18 08:52:17 +01:00
|
|
|
|
{
|
|
|
|
|
return (await DbEntities.Languages
|
|
|
|
|
.Match(l => AppConfigurationService.AppConfiguration.SupportedLanguages.Contains(l.International2Code))
|
2023-02-19 00:43:43 +01:00
|
|
|
|
.ExecuteAsync(cancellationToken)).OrderBy(l => l.NativeName).ToArray();
|
2023-02-18 08:52:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|