From cc3fe23fc8dfa7f793faf236487389878f54e602 Mon Sep 17 00:00:00 2001 From: Aron Ridgway Date: Tue, 29 Jun 2021 20:03:09 +0100 Subject: [PATCH 1/3] up to 7 Todo list --- .../TodoItems/TodoItemEditFieldsFactory.cs | 2 +- Todo/Models/TodoItems/TodoItemCreateFields.cs | 5 +- Todo/Models/TodoItems/TodoItemEditFields.cs | 6 +- .../ApplicationDbContextConvenience.cs | 7 ++- Todo/Views/TodoList/Detail.cshtml | 57 +++++++++++-------- Todo/wwwroot/css/site.css | 5 ++ Todo/wwwroot/js/site.js | 8 +++ 7 files changed, 60 insertions(+), 30 deletions(-) diff --git a/Todo/EntityModelMappers/TodoItems/TodoItemEditFieldsFactory.cs b/Todo/EntityModelMappers/TodoItems/TodoItemEditFieldsFactory.cs index 6d3e893b..1b35f05c 100644 --- a/Todo/EntityModelMappers/TodoItems/TodoItemEditFieldsFactory.cs +++ b/Todo/EntityModelMappers/TodoItems/TodoItemEditFieldsFactory.cs @@ -3,7 +3,7 @@ namespace Todo.EntityModelMappers.TodoItems { - public class TodoItemEditFieldsFactory + public static class TodoItemEditFieldsFactory { public static TodoItemEditFields Create(TodoItem todoItem) { diff --git a/Todo/Models/TodoItems/TodoItemCreateFields.cs b/Todo/Models/TodoItems/TodoItemCreateFields.cs index dfaed4af..7e2c93fa 100644 --- a/Todo/Models/TodoItems/TodoItemCreateFields.cs +++ b/Todo/Models/TodoItems/TodoItemCreateFields.cs @@ -1,4 +1,6 @@ -using Todo.Data.Entities; + +using System.ComponentModel.DataAnnotations; +using Todo.Data.Entities; namespace Todo.Models.TodoItems { @@ -7,6 +9,7 @@ public class TodoItemCreateFields public int TodoListId { get; set; } public string Title { get; set; } public string TodoListTitle { get; set; } + [Display(Name ="Responsible Party")] public string ResponsiblePartyId { get; set; } public Importance Importance { get; set; } = Importance.Medium; diff --git a/Todo/Models/TodoItems/TodoItemEditFields.cs b/Todo/Models/TodoItems/TodoItemEditFields.cs index 43c970ef..e1eb6974 100644 --- a/Todo/Models/TodoItems/TodoItemEditFields.cs +++ b/Todo/Models/TodoItems/TodoItemEditFields.cs @@ -1,4 +1,5 @@ -using Todo.Data.Entities; +using System.ComponentModel.DataAnnotations; +using Todo.Data.Entities; namespace Todo.Models.TodoItems { @@ -9,6 +10,7 @@ public class TodoItemEditFields public string TodoListTitle { get; set; } public int TodoItemId { get; set; } public bool IsDone { get; set; } + [Display(Name = "Responsible Party")] public string ResponsiblePartyId { get; set; } public Importance Importance { get; set; } @@ -22,7 +24,7 @@ public TodoItemEditFields(int todoListId, string todoListTitle, int todoItemId, Title = title; IsDone = isDone; ResponsiblePartyId = responsiblePartyId; - Importance = Importance.Medium; + Importance = Importance; } } } \ No newline at end of file diff --git a/Todo/Services/ApplicationDbContextConvenience.cs b/Todo/Services/ApplicationDbContextConvenience.cs index 3549d4b3..04466c7f 100644 --- a/Todo/Services/ApplicationDbContextConvenience.cs +++ b/Todo/Services/ApplicationDbContextConvenience.cs @@ -10,8 +10,11 @@ public static class ApplicationDbContextConvenience public static IQueryable RelevantTodoLists(this ApplicationDbContext dbContext, string userId) { return dbContext.TodoLists.Include(tl => tl.Owner) - .Include(tl => tl.Items) - .Where(tl => tl.Owner.Id == userId); + .Include(tl => tl.Items) + .ThenInclude(ti => ti.ResponsibleParty) + .Where(w => w.Items + .Any(w => w.ResponsiblePartyId == userId) + || w.Owner.Id == userId); } public static TodoList SingleTodoList(this ApplicationDbContext dbContext, int todoListId) diff --git a/Todo/Views/TodoList/Detail.cshtml b/Todo/Views/TodoList/Detail.cshtml index 650f0bc2..791dda81 100644 --- a/Todo/Views/TodoList/Detail.cshtml +++ b/Todo/Views/TodoList/Detail.cshtml @@ -14,12 +14,21 @@