54 lines
1.8 KiB
C#
54 lines
1.8 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using ModelsLib;
|
|
|
|
public class ConfigAppServices
|
|
{
|
|
private readonly IDbContextFactory<PhotoShareDbContext> _factory;
|
|
|
|
public ConfigAppServices(IDbContextFactory<PhotoShareDbContext> factory)
|
|
{
|
|
_factory = factory;
|
|
}
|
|
|
|
public async Task FillConfigTableWithDataPerDefault()
|
|
{
|
|
using var db = _factory.CreateDbContext();
|
|
|
|
db.ConfigDb.AddRange(
|
|
new ParametersDb("InstaQrCode", "/Images/qr.png"),
|
|
new ParametersDb("InstaLink", "https://www.instagram.com/helrira/"),
|
|
new ParametersDb("TitlePseudo", "Kévin"),
|
|
new ParametersDb("SubTitle1", "Passionné par la photo depuis 2025, je me spécialise dans le portrait avec modèles pour capturer l'essence et l'émotion de chaque rencontre."),
|
|
new ParametersDb("SubTitle2", "J'aime que chaque séance soit cadrée tout en gardant une part de surprise, de non prévu et surtout un bon moment pour chacun."),
|
|
new ParametersDb("Credentials", "Kévin Harlay(Helrira)")
|
|
);
|
|
|
|
await db.SaveChangesAsync();
|
|
}
|
|
public async Task<bool> HasAnyParametersAsync()
|
|
{
|
|
using var db = _factory.CreateDbContext();
|
|
return await db.ConfigDb.AnyAsync();
|
|
}
|
|
|
|
|
|
public async Task<EntityHome> readParametersApplication()
|
|
{
|
|
using var db = _factory.CreateDbContext();
|
|
|
|
var confDb = await db.ConfigDb
|
|
.AsNoTracking()
|
|
.ToDictionaryAsync(p => p.Key, p => p.Value);
|
|
|
|
return new EntityHome
|
|
{
|
|
InstaQrCode = confDb["InstaQrCode"],
|
|
InstaLink = confDb["InstaLink"],
|
|
TitlePseudo = confDb["TitlePseudo"],
|
|
SubTitle1 = confDb["SubTitle1"],
|
|
SubTitle2 = confDb["SubTitle2"],
|
|
Credentials = confDb["Credentials"]
|
|
};
|
|
}
|
|
}
|