Unread posts backend.

This commit is contained in:
Michael 2017-03-27 15:47:54 -04:00
parent fd5302fca4
commit 93734dd552
3 changed files with 24 additions and 0 deletions
Project-Unite

View file

@ -67,6 +67,11 @@ namespace Project_Unite
return hpr.Raw(CommonMark.CommonMarkConverter.Convert(hpr.Encode(md)));
}
public static int UnreadPostsCount(string username)
{
return new ApplicationDbContext().Users.FirstOrDefault(x => x.UserName == username).UnreadPosts.Length;
}
public static bool IsFollowed(string you, string fId)
{
var db = new ApplicationDbContext();

View file

@ -39,6 +39,16 @@ namespace Project_Unite.Models
}
public ForumPost[] UnreadPosts
{
get
{
var db = new ApplicationDbContext();
var posts = db.ForumPosts.Where(x => db.ReadPosts.FirstOrDefault(y => y.UserId == this.Id && y.PostId == x.Id) == null);
return posts.ToArray();
}
}
public Role HighestRole
{
get
@ -204,6 +214,7 @@ namespace Project_Unite.Models
return new ApplicationDbContext();
}
public DbSet<ReadPost> ReadPosts { get; set; }
public DbSet<Download> Downloads { get; set; }
public DbSet<DatabaseBackup> Backups { get; set; }
public DbSet<AssetBackup> AssetBackups { get; set; }
@ -230,6 +241,13 @@ namespace Project_Unite.Models
public DbSet<View> Views { get; set; }
}
public class ReadPost
{
public string Id { get; set; }
public string PostId { get; set; }
public string UserId { get; set; }
}
public class UserPost
{
public string Id { get; set; }

View file

@ -7,6 +7,7 @@
<ul class="nav navbar-nav navbar-right" style="margin-right:15px;">
<li>@Html.NewestUser()</li>
<li><a href="@Url.Action("ViewUnread", "Forum")"><span class="glyphicon glyphicon-star-empty"></span> @ACL.UnreadPostsCount(User.Identity.Name) unread posts</a></li>
<li class="dropdown"><a href="#" data-toggle="dropdown" class="dropdown-toggle"><span class="glyphicon glyphicon-bullhorn"></span> @Html.NotificationCount(User.Identity.GetUserId())</a>
<ul class="dropdown-menu">
<li class="dropdown-header">Notifications (@Html.NotificationCount(User.Identity.Name) unread)</li>