From 93734dd552b9c95da23b517ea1f65854f22c68f6 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 27 Mar 2017 15:47:54 -0400 Subject: [PATCH] Unread posts backend. --- Project-Unite/ACL.cs | 5 +++++ Project-Unite/Models/IdentityModels.cs | 18 ++++++++++++++++++ .../Views/Shared/_LoginPartial.cshtml | 1 + 3 files changed, 24 insertions(+) diff --git a/Project-Unite/ACL.cs b/Project-Unite/ACL.cs index 88e2fc2..ca356f9 100644 --- a/Project-Unite/ACL.cs +++ b/Project-Unite/ACL.cs @@ -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(); diff --git a/Project-Unite/Models/IdentityModels.cs b/Project-Unite/Models/IdentityModels.cs index bb55d50..6cfb821 100644 --- a/Project-Unite/Models/IdentityModels.cs +++ b/Project-Unite/Models/IdentityModels.cs @@ -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 ReadPosts { get; set; } public DbSet Downloads { get; set; } public DbSet Backups { get; set; } public DbSet AssetBackups { get; set; } @@ -230,6 +241,13 @@ namespace Project_Unite.Models public DbSet 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; } diff --git a/Project-Unite/Views/Shared/_LoginPartial.cshtml b/Project-Unite/Views/Shared/_LoginPartial.cshtml index 3e20d00..8f7aabf 100644 --- a/Project-Unite/Views/Shared/_LoginPartial.cshtml +++ b/Project-Unite/Views/Shared/_LoginPartial.cshtml @@ -7,6 +7,7 @@