From 6957bf7ddcae41d2731af1c941a37ca4407a0a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pawelec?= Date: Sun, 5 Dec 2021 13:19:22 +0100 Subject: [PATCH] #6. get lists where user is responsible party in one of the tasks. Log sql to console as traces. --- Todo/Services/ApplicationDbContextConvenience.cs | 2 +- Todo/Startup.cs | 14 +++++++++----- Todo/appsettings.Development.json | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Todo/Services/ApplicationDbContextConvenience.cs b/Todo/Services/ApplicationDbContextConvenience.cs index 3549d4b3..0a25d735 100644 --- a/Todo/Services/ApplicationDbContextConvenience.cs +++ b/Todo/Services/ApplicationDbContextConvenience.cs @@ -11,7 +11,7 @@ public static IQueryable RelevantTodoLists(this ApplicationDbContext d { return dbContext.TodoLists.Include(tl => tl.Owner) .Include(tl => tl.Items) - .Where(tl => tl.Owner.Id == userId); + .Where(tl => tl.Owner.Id == userId || tl.Items.Any(item => item.ResponsiblePartyId == userId)); } public static TodoList SingleTodoList(this ApplicationDbContext dbContext, int todoListId) diff --git a/Todo/Startup.cs b/Todo/Startup.cs index dbcc90f9..62cdca10 100644 --- a/Todo/Startup.cs +++ b/Todo/Startup.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Authorization; +using System; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Hosting; @@ -8,6 +9,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; namespace Todo { @@ -31,8 +33,10 @@ public void ConfigureServices(IServiceCollection services) }); services.AddDbContext(options => - options.UseSqlite( - Configuration.GetConnectionString("DefaultConnection"))); + { + options.LogTo(Console.WriteLine, LogLevel.Trace); + options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")); + }); services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = false) .AddEntityFrameworkStores(); @@ -53,7 +57,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseRouting(); app.UseWebOptimizer(); - + if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); @@ -78,4 +82,4 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) }); } } -} +} \ No newline at end of file diff --git a/Todo/appsettings.Development.json b/Todo/appsettings.Development.json index a2880cbf..a2319b7e 100644 --- a/Todo/appsettings.Development.json +++ b/Todo/appsettings.Development.json @@ -1,7 +1,7 @@ { "Logging": { "LogLevel": { - "Default": "Debug", + "Default": "Trace", "System": "Information", "Microsoft": "Information" }