Skip to content
This repository was archived by the owner on Nov 23, 2024. It is now read-only.

Commit ba2522e

Browse files
committed
Implement dashboard status page
1 parent cbfc832 commit ba2522e

File tree

8 files changed

+134
-11
lines changed

8 files changed

+134
-11
lines changed

Diff for: src/Web/Web/BadgeTypeExtensions.cs

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Linq;
4-
using System.Resources;
53
using CodeMooc.Web.Resources;
64

75
namespace CodeMooc.Web {
@@ -22,6 +20,13 @@ public static class BadgeTypeExtensions {
2220
{ "sponsor", BadgeType.Sponsor },
2321
};
2422

23+
private static readonly Dictionary<BadgeType, string> _reverseNames;
24+
25+
static BadgeTypeExtensions() {
26+
_reverseNames = new Dictionary<BadgeType, string>(from p in _routeNames.Keys
27+
select new KeyValuePair<BadgeType, string>(_routeNames[p], p));
28+
}
29+
2530
private static readonly int[] _widths = new int[] {
2631
250,
2732
640,
@@ -80,6 +85,10 @@ public static string GetEvidence(this BadgeType badgeType, int year) {
8085
return BadgeEvidenceDescriptions.ResourceManager.GetString($"{badgeType}{year}");
8186
}
8287

88+
public static string GetPathToken(this BadgeType badgeType) {
89+
return _reverseNames[badgeType];
90+
}
91+
8392
}
8493

8594
}

Diff for: src/Web/Web/Controllers/DashboardController.cs

+25-4
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,37 @@ public IActionResult ShowDonations() {
7575
where e.RegistrationId == model.LoggedUser.Id
7676
select e)
7777
.Include(e => e.AssociatedDonations)
78-
.Single();
79-
80-
model.Donations = emails.AssociatedDonations;
78+
.ToList();
79+
model.Donations = emails.SelectMany(e => e.AssociatedDonations).ToList();
8180

8281
return View("Donations", model);
8382
}
8483

8584
[HttpGet("stato")]
8685
public IActionResult ShowAssociationStatus() {
87-
return null;
86+
var model = GetViewModel<DashboardStatusViewModel>();
87+
if(model == null) {
88+
return Forbid();
89+
}
90+
91+
model.IsRegistrationConfirmed = model.LoggedUser.ConfirmationTimestamp.HasValue;
92+
93+
var emails = (from e in Database.Emails
94+
where e.RegistrationId == model.LoggedUser.Id
95+
select e)
96+
.Include(e => e.AssociatedBadges)
97+
.ToList();
98+
99+
model.Emails = emails;
100+
model.PrimaryEmail = emails.Where(e => e.IsPrimary).Single();
101+
102+
model.Badges = emails.SelectMany(e => e.AssociatedBadges).ToList();
103+
104+
model.IsAssociateForCurrentYear = model.Badges.Any(b => b.Year.Year == DateTime.Now.Year && b.Type == BadgeType.Member);
105+
106+
model.ConfirmationEmailAddress = RegisterController.RegistrationFromAddress;
107+
108+
return View("Status", model);
88109
}
89110

90111
[HttpGet("cv-upload")]

Diff for: src/Web/Web/Controllers/RegisterController.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ namespace CodeMooc.Web.Controllers {
1515
[Route("iscrizione")]
1616
public class RegisterController : Controller {
1717

18+
public const string RegistrationFromAddress = "[email protected]";
19+
1820
protected DataContext Database { get; }
1921
protected ILogger<RegisterController> Logger { get; }
2022

@@ -54,7 +56,7 @@ private async Task SendConfirmationEmail(Data.Registration user, Data.Email emai
5456

5557
Logger.LogTrace(LoggingEvents.Email, "SMTP host {0}:{1} username {2} SSL {3}", client.Host, client.Port, credentials.UserName, client.EnableSsl);
5658

57-
var noReplyAddress = new MailAddress("[email protected]", "CodeMOOC.net");
59+
var noReplyAddress = new MailAddress(RegistrationFromAddress, "CodeMOOC.net");
5860
var msg = new MailMessage {
5961
From = noReplyAddress,
6062
Subject = "Verifica indirizzo e-mail",

Diff for: src/Web/Web/Data/Badge.cs

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public class Badge {
1919

2020
public string EvidenceToken { get; set; }
2121

22+
[ForeignKey(nameof(Email))]
23+
public Email Address { get; set; }
24+
2225
}
2326

2427
}

Diff for: src/Web/Web/Data/BadgeTypeConverter.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Linq;
4-
using System.Threading.Tasks;
53
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
64

75
namespace CodeMooc.Web.Data {

Diff for: src/Web/Web/Data/Email.cs

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public class Email {
3030
[InverseProperty(nameof(Donation.Address))]
3131
public List<Donation> AssociatedDonations { get; set; }
3232

33+
[InverseProperty(nameof(Badge.Address))]
34+
public List<Badge> AssociatedBadges { get; set; }
35+
3336
}
3437

3538
}

Diff for: src/Web/Web/Model/DashboardStatusViewModel.cs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using CodeMooc.Web.Data;
6+
7+
namespace CodeMooc.Web.Model {
8+
9+
public class DashboardStatusViewModel : DashboardBaseViewModel {
10+
11+
public IList<Email> Emails { get; set; }
12+
public Email PrimaryEmail { get; set; }
13+
14+
public bool IsAssociateForCurrentYear { get; set; }
15+
16+
public bool IsRegistrationConfirmed { get; set; }
17+
18+
public IList<Badge> Badges { get; set; }
19+
20+
public string ConfirmationEmailAddress { get; set; }
21+
22+
}
23+
24+
}

Diff for: src/Web/Web/Views/Dashboard/Status.cshtml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
@using CodeMooc.Web
2+
@using CodeMooc.Web.Model
3+
@model DashboardStatusViewModel
4+
@{
5+
Layout = "Main";
6+
ViewData["Title"] = "Stato";
7+
}
8+
9+
<div class="container">
10+
<h1 class="text-center">Stato</h1>
11+
12+
<div class="col-12 col-sm-8 offset-sm-2 col-md-6 offset-md-3">
13+
14+
<p>◀&nbsp;@Html.ActionLink("Torna al pannello di controllo", "Index")</p>
15+
16+
<h2>Indirizzi e-mail</h2>
17+
18+
<p>Indirizzi e-mail associati al tuo account:</p>
19+
<ul>
20+
@foreach (var e in Model.Emails) {
21+
<li>
22+
@e.Address @if (e.IsPrimary) {
23+
<span>(Primario)</span>
24+
}
25+
</li>
26+
}
27+
</ul>
28+
29+
<h2>Registrazione</h2>
30+
31+
@if (Model.IsRegistrationConfirmed) {
32+
<p>La tua registrazione è stata confermata correttamente.</p>
33+
}
34+
else {
35+
<p class="warning">La tua registrazione non è confermata!</p>
36+
<p class="help">
37+
Verifica di aver ricevuto una e-mail di conferma dall'indirizzo <i>@Model.ConfirmationEmailAddress</i> (controlla anche nella cartella dello spam).
38+
Se così non fosse, contatta <i>associazione@codemooc.net</i> scrivendo un'e-mail dall'indirizzo <i>@Model.PrimaryEmail.Address</i>.
39+
</p>
40+
}
41+
42+
<h2>Badge e iscrizione</h2>
43+
44+
@if (Model.Badges.Count == 0) {
45+
<p><i>Nessun badge emesso.</i></p>
46+
}
47+
else {
48+
<ul>
49+
@foreach (var badge in Model.Badges) {
50+
<li>
51+
@badge.Type.GetName(badge.Year.Year) (@Html.ActionLink("vedi", "ShowEvidenceYear", "Badge", new { type = badge.Type.GetPathToken(), year = badge.Year.Year, token = badge.EvidenceToken }, null))
52+
</li>
53+
}
54+
</ul>
55+
}
56+
57+
@if(Model.IsAssociateForCurrentYear) {
58+
<p>Risulti correttamente iscritto/a all'associazione CodeMOOC.net per il corrente anno. Grazie!</p>
59+
}
60+
61+
</div>
62+
63+
</div>

0 commit comments

Comments
 (0)