using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Data.Entity; using System.Data.Entity.Infrastructure; using System.Linq; using System.Security.Claims; using System.Threading.Tasks; using System.Web; using System.Web.Mvc; using Microsoft.AspNet.Identity; 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; } } public class UploadImageViewModel { [Required(ErrorMessage = "Please select an image to upload.")] [DataType(DataType.Upload)] public HttpPostedFileBase Image { 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 { public async Task GenerateUserIdentityAsync(UserManager manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here return userIdentity; } public ForumPost[] UnreadPosts { get { var db = new ApplicationDbContext(); var posts = db.ForumPosts.Where(x => db.ForumTopics.FirstOrDefault(z=>z.Id==x.Parent).IsUnlisted == false && db.ReadPosts.FirstOrDefault(y => y.UserId == this.Id && y.PostId == x.Id) == null); return posts.ToArray(); } } public Role HighestRole { get { var roleList = new List(); foreach (var role in this.Roles) { roleList.Add(new ApplicationDbContext().Roles.First(r => r.Id == role.RoleId) as Role); } return roleList.OrderByDescending(x => x.Priority).First(); } } public int StoryPosition { get; set; } public string Language { get; set; } public int MajorVersion { get; set; } public int MinorVersion { get; set; } public int Revision { get; set; } public ShiftoriumUpgrade[] Upgrades { get { var db = new ApplicationDbContext(); return db.ShiftoriumUpgrades.Where(x => x.UserId == this.Id).ToArray(); } } public bool IsPatreon { get; set; } public int ShiftnetSubscription { get; set; } public int LastMonthPaid { get; set; } public Story[] Stories { get { return new ApplicationDbContext().Stories.Where(x => x.UserId == this.Id).ToArray(); } } public string LastKnownIPAddress { get; set; } public DateTime JoinedAt { get; set; } public DateTime LastLogin { get; set; } public bool IsBanned { get; set; } public bool IsMuted { get; set; } public DateTime BannedAt { get; set; } public DateTime MutedAt { get; set; } public string BannedBy { get; set; } public string MutedBy { get; set; } public int PostCount { get { using(var db = new ApplicationDbContext()) { return db.ForumPosts.Where(x=>x.AuthorId == this.Id).Count(); } } } public int TopicCount { get { using (var db = new ApplicationDbContext()) { return db.ForumTopics.Where(x => x.AuthorId == this.Id).Count(); } } } public long Codepoints { get; set; } [AllowHtml] public string Bio { get; set; } public string BannerUrl { get; set; } public string AvatarUrl { get; set; } public string DisplayName { get; set; } public string FullName { get; set; } public string Website { get; set; } public string YoutubeUrl { get; set; } public string SystemName { get; set; } public string Interests { get; set; } public string Hobbies { get; set; } public UserPost[] Posts { get { var db = new ApplicationDbContext(); return db.UserPosts.Where(x => x.UserId == this.Id).ToArray(); } } public Notification[] Notifications { get { var db = new ApplicationDbContext(); return db.Notifications.Where(x => x.UserId == this.Id).ToArray(); } } public int UnreadNotifications { get { return Notifications.Where(x => x.IsRead == false).Count(); } } 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 { public string Id { get; set; } public string Address { get; set; } } public class ApplicationDbContext : IdentityDbContext { public ApplicationDbContext() : base("DefaultConnection", throwIfV1Schema: false) { } public DbSet WikiPages { get; set; } public DbSet WikiCategories { get; set; } public void DeleteObject(object obj) { ((IObjectContextAdapter)this).ObjectContext.DeleteObject(obj); } public static ApplicationDbContext Create() { return new ApplicationDbContext(); } public DbSet Bugs { get; set; } public DbSet BugTags { get; set; } public DbSet BlogPosts { get; set; } public DbSet ReadPosts { get; set; } public DbSet Downloads { get; set; } public DbSet Backups { get; set; } public DbSet AssetBackups { get; set; } public DbSet UserAvatars { get; set; } public DbSet Skins { get; set; } public DbSet Configs { get; set; } public DbSet ShiftoriumUpgrades { get; set; } public DbSet Notifications { get; set; } public DbSet Follows { get; set; } public DbSet UserPosts { get; set; } public DbSet ForumPostEdits { get; set; } public DbSet Likes { get; set; } public DbSet ForumPermissions { get; set; } public DbSet BannedIPs { get; set; } public DbSet AuditLogs { get; set; } public System.Data.Entity.DbSet IdentityRoles { get; set; } public DbSet ForumCategories { get; set; } public DbSet ForumTopics { get; set; } public DbSet ForumPolls { get; set; } public DbSet ForumPollOptions { get; set; } public DbSet ForumPollVotes { get; set; } public DbSet ForumPosts { get; set; } public DbSet Stories { get; set; } 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; } public string UserId { get; set; } [MaxLength(1000, ErrorMessage ="Your post can't have more than 1000 characters.")] [AllowHtml] [MinLength(20, ErrorMessage ="To prevent spam, you must have at least 20 characters in your post.")] public string PostContents { get; set; } public DateTime PostedAt { get; set; } public Like[] Likes { get { return new ApplicationDbContext().Likes.Where(l => l.Topic == this.Id).Where(x => x.IsDislike == false).ToArray(); } } public Like[] Dislikes { get { return new ApplicationDbContext().Likes.Where(l => l.Topic == this.Id).Where(x => x.IsDislike == true).ToArray(); } } } public class ShiftoriumUpgrade { public string Id { get; set; } public string UserId { get; set; } public string EngineUpgradeId { get; set; } } public class Story { public string Id { get; set; } public string UserId { get; set; } public string EngineStoryId { get; set; } } public class Avatar { public string Id { get; set; } public string UserId { get; set; } public string AvatarUrl { get; set; } public DateTime UploadedAt { get; set; } } public class DatabaseBackup { public string Id { get; set; } public DateTime Timestamp { get; set; } public string UserId { get; set; } public string DownloadUrl { get; set; } } public class AssetBackup { public string Id { get; set; } public DateTime Timestamp { get; set; } public string UserId { get; set; } public string DownloadUrl { get; set; } } }