Skip to content

Commit

Permalink
Merge pull request #28 from joeseggie/develop
Browse files Browse the repository at this point in the history
Fixing the sorting of the mail by date.
  • Loading branch information
joeseggie committed Mar 18, 2021
2 parents e22e7d9 + bdd499f commit 406a5f6
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 26 deletions.
11 changes: 5 additions & 6 deletions MailManager.Web/Controllers/CorrespondanceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,16 @@ IMailService mailService
{
ViewData["CurrentSort"] = sort;
var correspondances = _correspondanceService.GetCorrespondances()
.OrderByDescending(correspondance => correspondance.Logged)
.Select(correspondance => new CorrespondanceListViewModel
{
Details = correspondance.Details,
Id = correspondance.Id,
Logged = correspondance.Logged.ToString("dd MMMM yyyy"),
Logged = correspondance.Logged,
MailId = correspondance.MailId,
Office = correspondance.Office,
From = correspondance.Mail.From,
Subject = correspondance.Mail.Subject,
Received = correspondance.Mail.Received.ToString("dd MMMM yyyy")
Received = correspondance.Mail.Received
});

if (!string.IsNullOrWhiteSpace(search))
Expand Down Expand Up @@ -78,7 +77,7 @@ IMailService mailService
break;
case "office":
correspondances = correspondances.OrderBy(m => m.Office);
ViewData["sort"] = "officedesc";
ViewData["sort"] = "office_desc";
break;
case "office_desc":
correspondances = correspondances.OrderByDescending(m => m.Office);
Expand Down Expand Up @@ -200,12 +199,12 @@ public IActionResult PrintAll(string search)
{
Details = correspondance.Details,
Id = correspondance.Id,
Logged = correspondance.Logged.ToString("dd MMMM yyyy"),
Logged = correspondance.Logged,
MailId = correspondance.MailId,
Office = correspondance.Office,
From = correspondance.Mail.From,
Subject = correspondance.Mail.Subject,
Received = correspondance.Mail.Received.ToString("dd MMMM yyyy")
Received = correspondance.Mail.Received
});

if (!string.IsNullOrWhiteSpace(search))
Expand Down
20 changes: 14 additions & 6 deletions MailManager.Web/Controllers/MailController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ IActionPointService actionPointService
{
ViewData["CurrentSort"] = sort;
var model = _mailService.GetMail()
.OrderBy(m => m.Received)
.Select(m => new MailListViewModel
{
Id = m.Id,
ReferenceNumber = m.ReferenceNumber,
Details = m.Details,
From = m.From,
Received = m.Received.ToString("dd MMMM yyyy"),
Received = m.Received,
Subject = m.Subject,
To = m.To
});
Expand All @@ -74,6 +73,7 @@ IActionPointService actionPointService
ViewData["FromSortParam"] = string.IsNullOrWhiteSpace(sort) ? "from_desc" : "";
ViewData["ToSortParam"] = sort == "to" ? "to_desc" : "to";
ViewData["SubjectSortParam"] = sort == "subject" ? "subject_desc" : "subject";
ViewData["ReceivedSortParam"] = sort == "received" ? "received_desc" : "received";
switch (sort)
{
case "from_desc":
Expand All @@ -90,12 +90,20 @@ IActionPointService actionPointService
break;
case "subject":
model = model.OrderBy(m => m.Subject);
ViewData["sort"] = "subjectdesc";
ViewData["sort"] = "subject_desc";
break;
case "subject_desc":
model = model.OrderByDescending(m => m.Subject);
ViewData["sort"] = "subject";
break;
case "received":
model = model.OrderBy(m => m.Received);
ViewData["sort"] = "received_desc";
break;
case "received_desc":
model = model.OrderByDescending(m => m.Received);
ViewData["sort"] = "received";
break;
default:
model = model.OrderBy(m => m.From);
break;
Expand Down Expand Up @@ -156,7 +164,7 @@ public async Task<IActionResult> Details(Guid id)
{
Details = c.Details,
Id = c.Id,
Logged = c.Logged.ToString("dd/MM/yyyy"),
Logged = c.Logged,
MailId = c.MailId,
Office = c.Office
}).ToListAsync();
Expand Down Expand Up @@ -238,7 +246,7 @@ public async Task<IActionResult> Print(Guid id)
{
Details = c.Details,
Id = c.Id,
Logged = c.Logged.ToString("dd/MM/yyyy"),
Logged = c.Logged,
MailId = c.MailId,
Office = c.Office
}).ToListAsync();
Expand Down Expand Up @@ -279,7 +287,7 @@ public async Task<IActionResult> PrintAll(string search)
ReferenceNumber = m.ReferenceNumber,
Details = m.Details,
From = m.From,
Received = m.Received.ToString("dd MMMM yyyy"),
Received = m.Received,
Subject = m.Subject,
To = m.To
})
Expand Down
4 changes: 2 additions & 2 deletions MailManager.Web/Models/CorrespondanceListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class CorrespondanceListViewModel

public Guid MailId { get; set; }

public string Logged { get; set; }
public DateTime Logged { get; set; }

public string Office { get; set; }

Expand All @@ -18,6 +18,6 @@ public class CorrespondanceListViewModel

public string Subject { get; set; }

public string Received { get; set; }
public DateTime Received { get; set; }
}
}
2 changes: 1 addition & 1 deletion MailManager.Web/Models/MailListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public class MailListViewModel

public string Details { get; set; }

public string Received { get; set; }
public DateTime Received { get; set; }
}
}
16 changes: 8 additions & 8 deletions MailManager.Web/Views/Correspondance/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
<thead class="thead-light">
<tr>
<th class="col-2">
<a asp-action="index" asp-controller="correspondance" asp-route-search="@ViewData["CurrentFilter"]" asp-route-sort="@ViewData["FromSortParam"]" asp-route-currentfilter="@ViewData["CurrentFilter"]">From</a>
From
</th>
<th class="col-2">
<a asp-action="index" asp-controller="correspondance" asp-route-search="@ViewData["CurrentFilter"]" asp-route-sort="@ViewData["ToSortParam"]" asp-route-currentfilter="@ViewData["CurrentFilter"]">Received</a>
Received
</th>
<th class="col-4">
<a asp-action="index" asp-controller="mail" asp-route-search="@ViewData["CurrentFilter"]" asp-route-sort="@ViewData["SubjectSortParam"]" asp-route-currentfilter="@ViewData["CurrentFilter"]">Subject</a>
Subject
</th>
<th class="col-2">
Sent to
</th>
<a asp-action="index" asp-controller="correspondance" asp-route-search="@ViewData["CurrentFilter"]" asp-route-sort="@ViewData["OfficeSortParam"]" asp-route-currentfilter="@ViewData["CurrentFilter"]">Sent to</a>
</th>
<th class="col-2">
Sent
<a asp-action="index" asp-controller="correspondance" asp-route-search="@ViewData["CurrentFilter"]" asp-route-sort="@ViewData["LoggedSortParam"]" asp-route-currentfilter="@ViewData["CurrentFilter"]">Sent</a>
</th>
</tr>
</thead>
Expand All @@ -42,10 +42,10 @@
{
<tr class="clickable-row" data-href='@Url.Action("details", "mail", new { controller="Mail", id=mail.MailId})'>
<td class="col-2">@mail.From</td>
<td class="col-2">@mail.Received</td>
<td class="col-2">@mail.Received.ToString("dd MMMM yyyy")</td>
<td class="col-4">@mail.Subject</td>
<td class="col-2">@mail.Office</td>
<td class="col-2">@mail.Logged</td>
<td class="col-2">@mail.Logged.ToString("dd MMMM yyyy")</td>
</tr>
}
}
Expand Down
6 changes: 4 additions & 2 deletions MailManager.Web/Views/Mail/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
<th class="col-4">
<a asp-action="index" asp-controller="mail" asp-route-search="@ViewData["CurrentFilter"]" asp-route-sort="@ViewData["SubjectSortParam"]" asp-route-currentfilter="@ViewData["CurrentFilter"]">Subject</a>
</th>
<th class="col-2">Received</th>
<th class="col-2">
<a asp-action="index" asp-controller="mail" asp-route-search="@ViewData["CurrentFilter"]" asp-route-sort="@ViewData["ReceivedSortParam"]" asp-route-currentfilter="@ViewData["CurrentFilter"]">Received</a>
</th>
<th class="col-2">Ref. No.</th>
</tr>
</thead>
Expand All @@ -33,7 +35,7 @@
<td class="col-2">@mail.From</td>
<td class="col-2">@mail.To</td>
<td class="col-4">@mail.Subject</td>
<td class="col-2">@mail.Received</td>
<td class="col-2">@mail.Received.ToString("dd MMMM yyyy")</td>
<td class="col-2">@mail.ReferenceNumber</td>
</tr>
}
Expand Down
2 changes: 1 addition & 1 deletion MailManager.Web/Views/Mail/PrintAll.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<td class="col-2">@mail.From</td>
<td class="col-2">@mail.To</td>
<td class="col-4">@mail.Subject</td>
<td class="col-2">@mail.Received</td>
<td class="col-2">@mail.Received.ToString("dd MMMM yyyy")</td>
<td class="col-2">@mail.ReferenceNumber</td>
</tr>
}
Expand Down

0 comments on commit 406a5f6

Please sign in to comment.