Skip to content

Commit 2c98b22

Browse files
committed
Updated implementation
1 parent 1db8730 commit 2c98b22

File tree

8 files changed

+82
-33
lines changed

8 files changed

+82
-33
lines changed

4-WebApp-your-API/4-3-AnyOrg/ToDoListClient/Controllers/ToDoListController.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public ToDoListController(IToDoListService todoListService)
2323
// GET: TodoList
2424
public async Task<ActionResult> Index()
2525
{
26+
TempData["SignedInUser"] = User.GetDisplayName();
2627
return View(await _todoListService.GetAsync());
2728
}
2829

@@ -40,6 +41,7 @@ public async Task<IActionResult> Create()
4041
Text = u
4142
}).ToList();
4243
TempData["TenantId"] = HttpContext.User.GetTenantId();
44+
TempData["AssignedBy"] = HttpContext.User.GetDisplayName();
4345
return View(todo);
4446
}
4547
catch (WebApiMsalUiRequiredException ex)
@@ -51,7 +53,7 @@ public async Task<IActionResult> Create()
5153
// POST: TodoList/Create
5254
[HttpPost]
5355
[ValidateAntiForgeryToken]
54-
public async Task<ActionResult> Create([Bind("Title,Owner,TenantId")] ToDoItem todo)
56+
public async Task<ActionResult> Create([Bind("Title,AssignedTo,AssignedBy,TenantId")] ToDoItem todo)
5557
{
5658
await _todoListService.AddAsync(todo);
5759
return RedirectToAction("Index");
@@ -73,7 +75,7 @@ public async Task<ActionResult> Edit(int id)
7375
// POST: TodoList/Edit/5
7476
[HttpPost]
7577
[ValidateAntiForgeryToken]
76-
public async Task<ActionResult> Edit(int id, [Bind("Id,Title,Owner,TenantId")] ToDoItem todo)
78+
public async Task<ActionResult> Edit(int id, [Bind("Id,Title,AssignedTo,AssignedBy,TenantId")] ToDoItem todo)
7779
{
7880
await _todoListService.EditAsync(todo);
7981
return RedirectToAction("Index");
@@ -95,7 +97,7 @@ public async Task<ActionResult> Delete(int id)
9597
// POST: TodoList/Delete/5
9698
[HttpPost]
9799
[ValidateAntiForgeryToken]
98-
public async Task<ActionResult> Delete(int id, [Bind("Id,Title,Owner")] ToDoItem todo)
100+
public async Task<ActionResult> Delete(int id, [Bind("Id,Title,AssignedTo")] ToDoItem todo)
99101
{
100102
await _todoListService.DeleteAsync(id);
101103
return RedirectToAction("Index");

4-WebApp-your-API/4-3-AnyOrg/ToDoListClient/Models/ToDoItem.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ public class ToDoItem
1111

1212
public string Title { get; set; }
1313

14-
public string Owner { get; set; }
14+
public string AssignedTo { get; set; }
15+
16+
public string AssignedBy { get; set; }
17+
1518
public string TenantId { get; set; }
1619
}
1720
}

4-WebApp-your-API/4-3-AnyOrg/ToDoListClient/Views/ToDoList/Create.cshtml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@
1010
<div class="row">
1111
<div class="col-md-4">
1212
<form asp-action="Create">
13-
<input type="hidden" asp-for="TenantId" value="@((string)TempData["TenantId"])"/>
13+
<input type="hidden" asp-for="TenantId" value="@((string)TempData["TenantId"])" />
14+
<input type="hidden" asp-for="AssignedBy" value="@((string)TempData["AssignedBy"])" />
1415
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
1516
<div class="form-group">
1617
<label asp-for="Title" class="control-label"></label>
1718
<input asp-for="Title" class="form-control" />
1819
<span asp-validation-for="Title" class="text-danger"></span>
1920
</div>
2021
<div class="form-group">
21-
<label asp-for="Owner" class="control-label"></label>
22+
<label asp-for="AssignedTo" class="control-label"></label>
2223

23-
<select class="form-control" asp-for="Owner" asp-items="@((List<SelectListItem>)TempData["UsersDropDown"])"></select>
24+
<select class="form-control" asp-for="AssignedTo" asp-items="@((List<SelectListItem>)TempData["UsersDropDown"])"></select>
2425

2526
</div>
2627
<div class="form-group">

4-WebApp-your-API/4-3-AnyOrg/ToDoListClient/Views/ToDoList/Delete.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
@Html.DisplayFor(model => model.Title)
1919
</dd>
2020
<dt class="col-sm-2">
21-
@Html.DisplayNameFor(model => model.Owner)
21+
@Html.DisplayNameFor(model => model.AssignedTo)
2222
</dt>
2323
<dd class="col-sm-10">
24-
@Html.DisplayFor(model => model.Owner)
24+
@Html.DisplayFor(model => model.AssignedTo)
2525
</dd>
2626
</dl>
2727

4-WebApp-your-API/4-3-AnyOrg/ToDoListClient/Views/ToDoList/Edit.cshtml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@
99
<form asp-action="Edit">
1010
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
1111
<input type="hidden" asp-for="Id" />
12-
<input type="hidden" asp-for="TenantId"/>
12+
<input type="hidden" asp-for="TenantId" />
13+
<input type="hidden" asp-for="AssignedBy"/>
1314
<div class="form-group">
1415
<label asp-for="Title" class="control-label"></label>
1516
<input asp-for="Title" class="form-control" />
1617
<span asp-validation-for="Title" class="text-danger"></span>
1718
</div>
1819
<div class="form-group">
19-
<label asp-for="Owner" class="control-label"></label>
20-
<input asp-for="Owner" class="form-control" readonly="readonly"/>
21-
<span asp-validation-for="Owner" class="text-danger"></span>
20+
<label asp-for="AssignedTo" class="control-label"></label>
21+
<input asp-for="AssignedTo" class="form-control" readonly="readonly" />
22+
<span asp-validation-for="AssignedTo" class="text-danger"></span>
2223
</div>
2324
<div class="form-group">
2425
<input type="submit" value="Save" class="btn btn-primary" />

4-WebApp-your-API/4-3-AnyOrg/ToDoListClient/Views/ToDoList/Index.cshtml

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
<p>
1010
<a asp-action="Create">Create New</a>
1111
</p>
12-
<table class="table">
12+
<p> Tasks assigned to signed-in User</p>
13+
<table class="table table-bordered">
1314
<thead>
1415
<tr>
1516
<th>
@@ -19,31 +20,69 @@
1920
@Html.DisplayNameFor(model => model.Title)
2021
</th>
2122
<th>
22-
@Html.DisplayNameFor(model => model.Owner)
23+
@Html.DisplayNameFor(model => model.AssignedBy)
24+
</th>
25+
</tr>
26+
</thead>
27+
<tbody>
28+
@foreach (var item in Model)
29+
{
30+
if (item.AssignedTo == TempData["SignedInUser"].ToString())
31+
{
32+
<tr>
33+
<td>
34+
@Html.DisplayFor(modelItem => item.Id)
35+
</td>
36+
<td>
37+
@Html.DisplayFor(modelItem => item.Title)
38+
</td>
39+
<td>
40+
@Html.DisplayFor(modelItem => item.AssignedBy)
41+
</td>
42+
</tr>
43+
}
44+
}
45+
</tbody>
46+
</table>
47+
<p>Tasks created by signed-in User</p>
48+
<table class="table table-bordered">
49+
<thead>
50+
<tr>
51+
<th>
52+
@Html.DisplayNameFor(model => model.Id)
53+
</th>
54+
<th>
55+
@Html.DisplayNameFor(model => model.Title)
56+
</th>
57+
<th>
58+
@Html.DisplayNameFor(model => model.AssignedTo)
2359
</th>
2460
<th>
2561
Actions
2662
</th>
2763
</tr>
2864
</thead>
2965
<tbody>
30-
@foreach (var item in Model)
66+
@foreach (var item2 in Model)
3167
{
32-
<tr>
33-
<td>
34-
@Html.DisplayFor(modelItem => item.Id)
35-
</td>
36-
<td>
37-
@Html.DisplayFor(modelItem => item.Title)
38-
</td>
39-
<td>
40-
@Html.DisplayFor(modelItem => item.Owner)
41-
</td>
42-
<td>
43-
@Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
44-
@Html.ActionLink("Delete", "Delete", new { id = item.Id })
45-
</td>
46-
</tr>
68+
if (item2.AssignedBy == TempData["SignedInUser"].ToString())
69+
{
70+
<tr>
71+
<td>
72+
@Html.DisplayFor(modelItem => item2.Id)
73+
</td>
74+
<td>
75+
@Html.DisplayFor(modelItem => item2.Title)
76+
</td>
77+
<td>
78+
@Html.DisplayFor(modelItem => item2.AssignedTo)
79+
</td>
80+
<td>
81+
@Html.ActionLink("Edit", "Edit", new { id = item2.Id }) |
82+
@Html.ActionLink("Delete", "Delete", new { id = item2.Id })
83+
</td>
84+
</tr>
85+
}
4786
}
4887
</tbody>
4988
</table>

4-WebApp-your-API/4-3-AnyOrg/TodoListService/Controllers/TodoListController.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public async Task<ActionResult<IEnumerable<TodoItem>>> GetTodoItems()
4040
{
4141
HttpContext.VerifyUserHasAnyAcceptedScope(scopeRequiredByApi);
4242
string userTenantId = HttpContext.User.GetTenantId();
43+
var signedInUser = HttpContext.User.GetDisplayName();
4344
try
4445
{
4546
Microsoft.Graph.User user = new User();
@@ -49,7 +50,8 @@ public async Task<ActionResult<IEnumerable<TodoItem>>> GetTodoItems()
4950
{
5051
throw;
5152
}
52-
return await _context.TodoItems.Where(x => x.TenantId == userTenantId).ToListAsync();
53+
return await _context.TodoItems.Where
54+
(x => x.TenantId == userTenantId && (x.AssignedTo == signedInUser || x.Assignedby== signedInUser)).ToListAsync();
5355
}
5456

5557
// GET: api/TodoItems/5

4-WebApp-your-API/4-3-AnyOrg/TodoListService/Models/TodoItem.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ public class TodoItem
1111

1212
public string Title { get; set; }
1313

14-
public string Owner { get; set; }
14+
public string AssignedTo { get; set; }
15+
public string Assignedby { get; set; }
1516
public string TenantId { get; set; }
1617
}
1718
}

0 commit comments

Comments
 (0)