I have a table injected from the DB that I have set up for CRUD.
ID EID Task entrydate Level
1 1 Demographics 2017-02-23 2
2 0 Demographics 2017-02-23 2
3 1 Progress Notes 2017-03-06 2
4 1 Demographics 2017-03-06 3
5 1 Assessments 2017-03-06 3
6 1 Assessments 2017-01-25 1
However, to display the data in a way that will make sense to the clients, I need to list the level data in columns by entrydate.
ID EId Task 25 Jan 2017 23 Feb 2017 06 Mar 2017
1 1 Demographics NULL 2 NULL
2 0 Demographics NULL 2 NULL
3 1 Progress Notes NULL NULL 2
4 1 Demographics NULL NULL 3
5 1 Assessments NULL NULL 3
6 1 Assessments 1 NULL NULL
I've been working on using LINQ in both the controller and in the view to create the correct table in the view.
Controller:
public IActionResult Index(int id)
{
HttpContext.Session.SetInt32("EmployeeID", id);
var model = db.EmployeeTask
.Where(h => h.EmployeeId == id)
.OrderByDescending(h => h.Entrydate);
return View(model);
}
View page:
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.KeyTask)
</th>
@foreach (var group in Model.GroupBy(item => item.Entrydate))
{
<th>
@group.Key.Date
</th>
}
<th></th>
</tr>
</thead>
<tbody>
@foreach (var group in Model.GroupBy(item => item.KeyTask)) {
<tr>
<td>
@group.Key
</td>
@foreach (var item in group)
{
<td>
@Html.DisplayFor(modelItem => item.Acceptable)
</td>
}
</tr>
}
</tbody>
</table>
By my results, I am almost there.
I am missing something as the data from acceptance is not matching with the entrydate columns. Am I on the right path or have I gone as far as LINQ will take me and need to try another approach?

EntryDate