summaryrefslogtreecommitdiff
path: root/Project-Unite/Models/IdentityModels.cs
blob: f86452718d3027f4f3c894875abb4a412bbddf2d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
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<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> 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<Role>();
                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<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("DefaultConnection", throwIfV1Schema: false)
        {
            
        }

        public DbSet<WikiPage> WikiPages { get; set; }
        public DbSet<WikiCategory> WikiCategories { get; set; }

        public void DeleteObject(object obj)
        {
            ((IObjectContextAdapter)this).ObjectContext.DeleteObject(obj);
        }

        

        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }

        public DbSet<Bug> Bugs { get; set; }
        public DbSet<BugTag> BugTags { get; set; }
        public DbSet<BlogPost> BlogPosts { get; set; }
        public DbSet<ReadPost> ReadPosts { get; set; }
        public DbSet<Download> Downloads { get; set; }
        public DbSet<DatabaseBackup> Backups { get; set; }
        public DbSet<AssetBackup> AssetBackups { get; set; }
        public DbSet<Avatar> UserAvatars { get; set; }
        public DbSet<Skin> Skins { get; set; }
        public DbSet<Configuration> Configs { get; set; }
        public DbSet<ShiftoriumUpgrade> ShiftoriumUpgrades { get; set; }
        public DbSet<Notification> Notifications { get; set; }
        public DbSet<UserFollow> Follows { get; set; }
        public DbSet<UserPost> UserPosts { get; set; }
        public DbSet<ForumPostEdit> ForumPostEdits { get; set; }
        public DbSet<Like> Likes { get; set; }
        public DbSet<ForumPermission> ForumPermissions { get; set; }
        public DbSet<BannedIP> BannedIPs { get; set; }
        public DbSet<AuditLog> AuditLogs { get; set; }
        public System.Data.Entity.DbSet<Project_Unite.Models.Role> IdentityRoles { get; set; }
        public DbSet<ForumCategory> ForumCategories { get; set; }
        public DbSet<ForumTopic> ForumTopics { get; set; }
        public DbSet<ForumPoll> ForumPolls { get; set; }
        public DbSet<ForumPollOption> ForumPollOptions { get; set; }
        public DbSet<ForumPollVote> ForumPollVotes { get; set; }
        public DbSet<ForumPost> ForumPosts { get; set; }
        public DbSet<Story> Stories { get; set; }
        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; }
        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; }
    }
}