The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TeknikEntities.cs 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using Microsoft.AspNet.Identity.EntityFramework;
  2. using System.Data.Entity;
  3. using System.Data.Entity.Infrastructure;
  4. using Teknik.Areas.Blog.Models;
  5. using Teknik.Areas.Users.Models;
  6. using Teknik.Areas.Contact.Models;
  7. using Teknik.Migrations;
  8. using Teknik.Areas.Upload.Models;
  9. using Teknik.Areas.Paste.Models;
  10. using Teknik.Areas.Podcast.Models;
  11. using Teknik.Areas.Transparency.Models;
  12. using Teknik.Areas.Shortener.Models;
  13. using Teknik.Attributes;
  14. using System.Data.Entity.ModelConfiguration.Conventions;
  15. using System.Linq;
  16. using Teknik.Areas.Vault.Models;
  17. namespace Teknik.Models
  18. {
  19. public class TeknikEntities : DbContext
  20. {
  21. // Users
  22. public DbSet<User> Users { get; set; }
  23. public DbSet<Group> Groups { get; set; }
  24. public DbSet<Role> Roles { get; set; }
  25. public DbSet<TrustedDevice> TrustedDevices { get; set; }
  26. public DbSet<AuthToken> AuthTokens { get; set; }
  27. public DbSet<TransferType> TransferTypes { get; set; }
  28. // User Settings
  29. public DbSet<UserSettings> UserSettings { get; set; }
  30. public DbSet<SecuritySettings> SecuritySettings { get; set; }
  31. public DbSet<BlogSettings> BlogSettings { get; set; }
  32. public DbSet<UploadSettings> UploadSettings { get; set; }
  33. // Authentication and Sessions
  34. public DbSet<RecoveryEmailVerification> RecoveryEmailVerifications { get; set; }
  35. public DbSet<ResetPasswordVerification> ResetPasswordVerifications { get; set; }
  36. // Blogs
  37. public DbSet<Blog> Blogs { get; set; }
  38. public DbSet<BlogPost> BlogPosts { get; set; }
  39. public DbSet<BlogPostComment> BlogComments { get; set; }
  40. // Contact
  41. public DbSet<Contact> Contact { get; set; }
  42. // Uploads
  43. public DbSet<Upload> Uploads { get; set; }
  44. // Pastes
  45. public DbSet<Paste> Pastes { get; set; }
  46. // Podcasts
  47. public DbSet<Podcast> Podcasts { get; set; }
  48. public DbSet<PodcastFile> PodcastFiles { get; set; }
  49. public DbSet<PodcastComment> PodcastComments { get; set; }
  50. // Transparency
  51. public DbSet<Transaction> Transactions { get; set; }
  52. public DbSet<Takedown> Takedowns { get; set; }
  53. // Url Shortener
  54. public DbSet<ShortenedUrl> ShortenedUrls { get; set; }
  55. // Vaults
  56. public DbSet<Vault> Vaults { get; set; }
  57. protected override void OnModelCreating(DbModelBuilder modelBuilder)
  58. {
  59. // User Settings Mappings
  60. modelBuilder.Entity<User>()
  61. .HasRequired(a => a.UserSettings)
  62. .WithRequiredPrincipal(a => a.User);
  63. modelBuilder.Entity<User>()
  64. .HasRequired(a => a.SecuritySettings)
  65. .WithRequiredPrincipal(a => a.User);
  66. modelBuilder.Entity<User>()
  67. .HasRequired(a => a.BlogSettings)
  68. .WithRequiredPrincipal(a => a.User);
  69. modelBuilder.Entity<User>()
  70. .HasRequired(a => a.UploadSettings)
  71. .WithRequiredPrincipal(a => a.User);
  72. modelBuilder.Entity<UserSettings>()
  73. .HasRequired(a => a.SecuritySettings)
  74. .WithRequiredPrincipal(a => a.UserSettings);
  75. modelBuilder.Entity<UserSettings>()
  76. .HasRequired(a => a.BlogSettings)
  77. .WithRequiredPrincipal(a => a.UserSettings);
  78. modelBuilder.Entity<UserSettings>()
  79. .HasRequired(a => a.UploadSettings)
  80. .WithRequiredPrincipal(a => a.UserSettings);
  81. modelBuilder.Entity<SecuritySettings>()
  82. .HasRequired(a => a.BlogSettings)
  83. .WithRequiredPrincipal(a => a.SecuritySettings);
  84. modelBuilder.Entity<SecuritySettings>()
  85. .HasRequired(a => a.UploadSettings)
  86. .WithRequiredPrincipal(a => a.SecuritySettings);
  87. modelBuilder.Entity<BlogSettings>()
  88. .HasRequired(a => a.UploadSettings)
  89. .WithRequiredPrincipal(a => a.BlogSettings);
  90. // User Mappings
  91. modelBuilder.Entity<User>()
  92. .HasMany<Upload>(u => u.Uploads)
  93. .WithOptional(u => u.User)
  94. .WillCascadeOnDelete(false);
  95. modelBuilder.Entity<User>()
  96. .HasMany<Paste>(u => u.Pastes)
  97. .WithOptional(u => u.User)
  98. .WillCascadeOnDelete(false);
  99. modelBuilder.Entity<User>()
  100. .HasMany<ShortenedUrl>(u => u.ShortenedUrls)
  101. .WithOptional(u => u.User)
  102. .WillCascadeOnDelete(false);
  103. modelBuilder.Entity<User>()
  104. .HasMany<Vault>(u => u.Vaults)
  105. .WithOptional(u => u.User)
  106. .WillCascadeOnDelete(false);
  107. // Upload Mappings
  108. modelBuilder.Entity<Upload>()
  109. .HasOptional(u => u.User);
  110. // Paste Mappings
  111. modelBuilder.Entity<Paste>()
  112. .HasOptional(u => u.User);
  113. // Shortened URL Mappings
  114. modelBuilder.Entity<ShortenedUrl>()
  115. .HasOptional(u => u.User);
  116. // Vault Mappings
  117. modelBuilder.Entity<Vault>()
  118. .HasOptional(u => u.User);
  119. // Users
  120. modelBuilder.Entity<User>().ToTable("Users");
  121. modelBuilder.Entity<Group>().ToTable("Groups");
  122. modelBuilder.Entity<Role>().ToTable("Roles");
  123. modelBuilder.Entity<TrustedDevice>().ToTable("TrustedDevices");
  124. modelBuilder.Entity<AuthToken>().ToTable("AuthTokens");
  125. modelBuilder.Entity<TransferType>().ToTable("TransferTypes");
  126. modelBuilder.Entity<RecoveryEmailVerification>().ToTable("RecoveryEmailVerifications");
  127. modelBuilder.Entity<ResetPasswordVerification>().ToTable("ResetPasswordVerifications");
  128. // User Settings
  129. modelBuilder.Entity<UserSettings>().ToTable("Users");
  130. modelBuilder.Entity<SecuritySettings>().ToTable("Users");
  131. modelBuilder.Entity<BlogSettings>().ToTable("Users");
  132. modelBuilder.Entity<UploadSettings>().ToTable("Users");
  133. // Blogs
  134. modelBuilder.Entity<Blog>().ToTable("Blogs");
  135. modelBuilder.Entity<BlogPost>().ToTable("BlogPosts");
  136. modelBuilder.Entity<PodcastComment>().ToTable("BlogComments");
  137. // Contact
  138. modelBuilder.Entity<Contact>().ToTable("Contact");
  139. // Uploads
  140. modelBuilder.Entity<Upload>().ToTable("Uploads");
  141. // Pastes
  142. modelBuilder.Entity<Paste>().ToTable("Pastes");
  143. // Shortened Urls
  144. modelBuilder.Entity<ShortenedUrl>().ToTable("ShortenedUrls");
  145. // Vaults
  146. modelBuilder.Entity<Vault>().ToTable("Vaults");
  147. // Podcasts
  148. modelBuilder.Entity<Podcast>().ToTable("Podcasts");
  149. modelBuilder.Entity<PodcastFile>().ToTable("PodcastFiles");
  150. modelBuilder.Entity<PodcastComment>().ToTable("PodcastComments");
  151. // Transparency
  152. modelBuilder.Entity<Transaction>().ToTable("Transactions");
  153. modelBuilder.Entity<Takedown>().ToTable("Takedowns");
  154. // Custom Attributes
  155. modelBuilder.Conventions.Add(new AttributeToColumnAnnotationConvention<CaseSensitiveAttribute, bool>(
  156. "CaseSensitive",
  157. (property, attributes) => attributes.Single().IsEnabled));
  158. base.OnModelCreating(modelBuilder);
  159. }
  160. }
  161. }