notifications page

This commit is contained in:
Michael 2017-05-18 16:33:27 -04:00
parent 1d8b307bb5
commit e4a501c026
3 changed files with 46 additions and 1 deletions

View file

@ -111,6 +111,19 @@ private set
}
}
public ActionResult MarkAllRead()
{
var db = new ApplicationDbContext();
string uid = User.Identity.GetUserId();
var unread = db.Notifications.Where(x => x.IsRead == false && x.UserId == uid);
foreach(var u in unread.ToArray())
{
u.IsRead = true;
}
db.SaveChanges();
return Redirect(Url.Action("Index", "Manage") + "#t_notifications");
}
public ActionResult Notification(string id, string url)
{
var db = new ApplicationDbContext();

View file

@ -95,6 +95,38 @@
<h4>Send me notifications through email when I'm inactive</h4>
<p>Check this option to allow us to email you when you receive a notification and you haven't logged in for a week.</p> @Html.CheckBoxFor(Model=>Model.EmailOnNotifications)
@{
var notes = Model.Notifications.Where(x=>x.IsRead==false).OrderByDescending(x=>x.Timestamp);
}
<h3>Unread Notifications</h3>
@if (notes.Count() > 0)
{
<p>Below is a list of all unread notifications.</p>
<ul class="nav nav-tabs">
<li><a href="@Url.Action("MarkAllRead")"><span class="glyphicon glyphicon-book"></span> Mark all read</a></li>
</ul>
<div class="row">
<strong>Notification</strong>
</div>
@foreach(var note in notes)
{
<div class="row">
@if (!string.IsNullOrWhiteSpace(note.AvatarUrl))
{
<img src="@note.AvatarUrl" height="128" width="128" class="avatar" />
}
<h5>@note.Title</h5>
<p>@note.Description</p>
<a href="@note.ActionUrl" class="btn btn-default">Read</a>
</div>
}
}
else
{
<p>You have no notifications.</p>
}
</div>
<div class="tab-pane fade in" id="t_privacy">
<h2>Privacy &amp; Security</h2>

View file

@ -15,7 +15,7 @@
<ul class="dropdown-menu">
<li class="dropdown-header">Notifications (@Html.NotificationCount(User.Identity.Name) unread)</li>
@Html.GetLatestUnread(User.Identity.Name)
<li>@Html.ActionLink("View all", "Notifications", "Manage")</li>
<li><a href="@Url.Action("Index", "Manage")#t_notifications">View all</a></li>
</ul>
</li>
<li class="dropdown"><a href="#" data-toggle="dropdown" class="dropdown-toggle"><span class="glyphicon glyphicon-user"></span> @Html.UserName(User.Identity.GetUserId()) <span class="caret"></span></a>