summaryrefslogtreecommitdiff
path: root/Project-Unite/Models/ForumCategory.cs
blob: 96c826eb76afba93a9991a72eedac512cfc063c5 (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
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Project_Unite.Models
{
    public class ForumCategory
    {
        [Key]
        [Column(Order = 0)]
        public string Id { get; set; }

        public virtual ForumCategory[] Children
        {
            get
            {
                var db = new ApplicationDbContext();
                return db.ForumCategories.Where(x => x.Parent == this.Id).ToArray();
            }
        }

        public string Name { get; set; }

        public string Description { get; set; }

        public string LinkUrl { get; set; }

        public ForumTopic[] Topics
        {
            get
            {
                return new ApplicationDbContext().ForumTopics.Where(x => x.Parent == this.Id).ToArray();
            }
        }

        public virtual string Parent { get; set; }

        public int AdminPermission { get; set; }
        public int DeveloperPermission { get; set; }
        public int ModeratorPermission { get; set; }
        public int MemberPermission { get; set; }

        public bool VisibleToGuests { get; set; }
    }

    public class ForumPost
    {
        public string Id { get; set; }
        
        public string Subject { get; set; }

        [Required]
        public string Parent { get; set; }

        public string AuthorId { get; set; }
        [AllowHtml]
        public string Body { get; set; }
        public DateTime PostedAt { get; set; }

        public virtual ForumPostEdit[] EditHistory
        {
            get
            {
                return new ApplicationDbContext().ForumPostEdits.Where(e => e.Parent == this.Id).ToArray();
            }
        }
    }

    public class ForumPostEdit
    {
        public string Id { get; set; }
        [Required]
        public string Parent { get; set; }

        public string UserId { get; set; }
        public string EditReason { get; set; }
        [AllowHtml]
        public string PreviousState { get; set; }
        public DateTime EditedAt { get; set; }
    }

    public class ForumTopic
    {
        public string Id { get; set; }
        [Required]
        public virtual string Parent { 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 string Discriminator { get; set; }

        public bool IsLocked { get; set; }

        public int Priority
        {
            get
            {
                int priority = 0;
                if (IsSticky)
                    priority = 1;
                if (IsAnnounce)
                    priority = 2;
                if (IsSticky && IsAnnounce)
                    priority = 3;
                return priority;
            }
        }

        public DateTime StartedAt { get; set; }
        public string Subject { get; set; }
        public bool ShouldShow
        {
            get
            {
                if (IsUnlisted == true)
                    return HttpContext.Current.User?.Identity?.IsModerator() == true;
                return true;
            }
        }
        public string AuthorId { get; set; }
        public bool IsSticky { get; set; }
        public bool IsAnnounce { get; set; }
        public bool IsUnlisted { get; set; }
        public bool IsGlobal { get; set; }

        public virtual ForumPost[] Posts
        {
            get
            {
                return new ApplicationDbContext().ForumPosts.Where(x => x.Parent == this.Id).ToArray();
            }
        }

        public virtual ForumPoll Poll { get; set; }


    }

    public class Like
    {
        public string Id { get; set; }

        [Required]
        public string User { get; set; }

        public DateTime LikedAt { get; set; }

        [Required]
        public string Topic { get; set; }
        public bool IsDislike { get; set; }
    }

    public class EditPostViewModel
    {
        public string Id { get; set; }
        [AllowHtml]
        public string Contents { get; set; }
        public string EditReason { get; set; }
    }

    public class ForumPoll
    {
        public string Id { get; set; }
        public string Description { get; set; }

        [Required]
        public virtual List<ForumPollOption> Options { get; set; }
        public bool IsActive { get; set; }
        public bool AllowMultivote { get; set; }
        public bool AllowVoteChanges { get; set; }

        [Required]
        public virtual ForumTopic Parent { get; set; }
    }

    public class ForumPollOption
    {
        public string Id { get; set; }
        public string Name { get; set; }

        [Required]
        public virtual List<ForumPollVote> Votes { get; set; }


        [Required]
        public virtual ForumPoll Poll { get; set; }
    }

    public class ForumPollVote
    {
        public string Id { get; set; }
        
        [Required]
        public ApplicationUser User { get; set; }

        [Required]
        public virtual ForumPollOption Option { get; set; }
    }

    //Unable to generate an explicit migration because the following explicit migrations are pending: [201703161804526_more-relationship-shit]. Apply the pending explicit migrations before attempting to generate a new explicit migration.

}