From 38d4f4bd39d3396b2ab3284602e7a22b71eb6320 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 12 Nov 2023 12:04:40 +0100 Subject: [PATCH] New service in CommandLineDbClient: ListLanguages --- .../ManageDB/ListLanguages.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 MemCheck.CommandLineDbClient/ManageDB/ListLanguages.cs diff --git a/MemCheck.CommandLineDbClient/ManageDB/ListLanguages.cs b/MemCheck.CommandLineDbClient/ManageDB/ListLanguages.cs new file mode 100644 index 00000000..813d0365 --- /dev/null +++ b/MemCheck.CommandLineDbClient/ManageDB/ListLanguages.cs @@ -0,0 +1,32 @@ +using MemCheck.Database; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using System; +using System.Threading.Tasks; + +namespace MemCheck.CommandLineDbClient.ManageDB; + +internal sealed class ListLanguages : ICmdLinePlugin +{ + #region Fields + private readonly ILogger logger; + private readonly MemCheckDbContext dbContext; + #endregion + public ListLanguages(IServiceProvider serviceProvider) + { + dbContext = serviceProvider.GetRequiredService(); + logger = serviceProvider.GetRequiredService>(); + } + public void DescribeForOpportunityToCancel() + { + logger.LogInformation("Will list languages"); + } + public async Task RunAsync() + { + var languages = await dbContext.CardLanguages.ToListAsync(); + + foreach (var language in languages) + logger.LogInformation($"Language '{language.Name}' has id {language.Id}"); + } +}