diff --git a/Project-Unite/ACL.cs b/Project-Unite/ACL.cs index dc12487..73636c7 100644 --- a/Project-Unite/ACL.cs +++ b/Project-Unite/ACL.cs @@ -28,6 +28,13 @@ namespace Project_Unite return hpr.Raw(CommonMark.CommonMarkConverter.Convert(hpr.Encode(md))); } + public static bool IsFollowed(string you, string fId) + { + var db = new ApplicationDbContext(); + var uid = db.Users.FirstOrDefault(x => x.UserName == you).Id; + return db.Follows.FirstOrDefault(x => x.Follower == uid && x.Followed == fId) != null; + } + public static IHtmlString UserLink(this HtmlHelper hpr, string userId) { using(var db = new ApplicationDbContext()) diff --git a/Project-Unite/Models/IdentityModels.cs b/Project-Unite/Models/IdentityModels.cs index 8d368ed..83ea777 100644 --- a/Project-Unite/Models/IdentityModels.cs +++ b/Project-Unite/Models/IdentityModels.cs @@ -12,6 +12,13 @@ using Microsoft.AspNet.Identity.EntityFramework; namespace Project_Unite.Models { + public class UserFollow + { + public string Id { get; set; } + public string Follower { get; set; } + public string Followed { get; set; } + } + // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more. public class ApplicationUser : IdentityUser { @@ -98,6 +105,24 @@ namespace Project_Unite.Models return db.UserPosts.Where(x => x.UserId == this.Id).ToArray(); } } + + public UserFollow[] Followed + { + get + { + var db = new ApplicationDbContext(); + return db.Follows.Where(x => x.Follower == this.Id).ToArray(); + } + } + + public UserFollow[] Followers + { + get + { + var db = new ApplicationDbContext(); + return db.Follows.Where(x => x.Followed == this.Id).ToArray(); + } + } } public class BannedIP @@ -124,6 +149,7 @@ namespace Project_Unite.Models return new ApplicationDbContext(); } + public DbSet Follows { get; set; } public DbSet UserPosts { get; set; } public DbSet ForumPostEdits { get; set; } public DbSet Likes { get; set; } diff --git a/Project-Unite/Views/Profiles/ViewProfile.cshtml b/Project-Unite/Views/Profiles/ViewProfile.cshtml index bee2ed9..b5ed038 100644 --- a/Project-Unite/Views/Profiles/ViewProfile.cshtml +++ b/Project-Unite/Views/Profiles/ViewProfile.cshtml @@ -14,6 +14,20 @@ + +

User stats