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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. public DbSet<VaultItem> VaultItems { get; set; }
  58. protected override void OnModelCreating(DbModelBuilder modelBuilder)
  59. {
  60. // User Settings Mappings
  61. modelBuilder.Entity<User>()
  62. .HasRequired(a => a.UserSettings)
  63. .WithRequiredPrincipal(a => a.User);
  64. modelBuilder.Entity<User>()
  65. .HasRequired(a => a.SecuritySettings)
  66. .WithRequiredPrincipal(a => a.User);
  67. modelBuilder.Entity<User>()
  68. .HasRequired(a => a.BlogSettings)
  69. .WithRequiredPrincipal(a => a.User);
  70. modelBuilder.Entity<User>()
  71. .HasRequired(a => a.UploadSettings)
  72. .WithRequiredPrincipal(a => a.User);
  73. modelBuilder.Entity<UserSettings>()
  74. .HasRequired(a => a.SecuritySettings)
  75. .WithRequiredPrincipal(a => a.UserSettings);
  76. modelBuilder.Entity<UserSettings>()
  77. .HasRequired(a => a.BlogSettings)
  78. .WithRequiredPrincipal(a => a.UserSettings);
  79. modelBuilder.Entity<UserSettings>()
  80. .HasRequired(a => a.UploadSettings)
  81. .WithRequiredPrincipal(a => a.UserSettings);
  82. modelBuilder.Entity<SecuritySettings>()
  83. .HasRequired(a => a.BlogSettings)
  84. .WithRequiredPrincipal(a => a.SecuritySettings);
  85. modelBuilder.Entity<SecuritySettings>()
  86. .HasRequired(a => a.UploadSettings)
  87. .WithRequiredPrincipal(a => a.SecuritySettings);
  88. modelBuilder.Entity<BlogSettings>()
  89. .HasRequired(a => a.UploadSettings)
  90. .WithRequiredPrincipal(a => a.BlogSettings);
  91. // User Mappings
  92. modelBuilder.Entity<User>()
  93. .HasMany<Upload>(u => u.Uploads)
  94. .WithOptional(u => u.User)
  95. .WillCascadeOnDelete(false);
  96. modelBuilder.Entity<User>()
  97. .HasMany<Paste>(u => u.Pastes)
  98. .WithOptional(u => u.User)
  99. .WillCascadeOnDelete(false);
  100. modelBuilder.Entity<User>()
  101. .HasMany<ShortenedUrl>(u => u.ShortenedUrls)
  102. .WithOptional(u => u.User)
  103. .WillCascadeOnDelete(false);
  104. modelBuilder.Entity<User>()
  105. .HasMany<Vault>(u => u.Vaults)
  106. .WithOptional(u => u.User)
  107. .WillCascadeOnDelete(false);
  108. // Upload Mappings
  109. modelBuilder.Entity<Upload>()
  110. .HasOptional(u => u.User);
  111. // Paste Mappings
  112. modelBuilder.Entity<Paste>()
  113. .HasOptional(u => u.User);
  114. // Shortened URL Mappings
  115. modelBuilder.Entity<ShortenedUrl>()
  116. .HasOptional(u => u.User);
  117. // Vault Mappings
  118. modelBuilder.Entity<Vault>()
  119. .HasOptional(u => u.User);
  120. // Users
  121. modelBuilder.Entity<User>().ToTable("Users");
  122. modelBuilder.Entity<Group>().ToTable("Groups");
  123. modelBuilder.Entity<Role>().ToTable("Roles");
  124. modelBuilder.Entity<TrustedDevice>().ToTable("TrustedDevices");
  125. modelBuilder.Entity<AuthToken>().ToTable("AuthTokens");
  126. modelBuilder.Entity<TransferType>().ToTable("TransferTypes");
  127. modelBuilder.Entity<RecoveryEmailVerification>().ToTable("RecoveryEmailVerifications");
  128. modelBuilder.Entity<ResetPasswordVerification>().ToTable("ResetPasswordVerifications");
  129. // User Settings
  130. modelBuilder.Entity<UserSettings>().ToTable("Users");
  131. modelBuilder.Entity<SecuritySettings>().ToTable("Users");
  132. modelBuilder.Entity<BlogSettings>().ToTable("Users");
  133. modelBuilder.Entity<UploadSettings>().ToTable("Users");
  134. // Blogs
  135. modelBuilder.Entity<Blog>().ToTable("Blogs");
  136. modelBuilder.Entity<BlogPost>().ToTable("BlogPosts");
  137. modelBuilder.Entity<PodcastComment>().ToTable("BlogComments");
  138. // Contact
  139. modelBuilder.Entity<Contact>().ToTable("Contact");
  140. // Uploads
  141. modelBuilder.Entity<Upload>().ToTable("Uploads");
  142. // Pastes
  143. modelBuilder.Entity<Paste>().ToTable("Pastes");
  144. // Shortened Urls
  145. modelBuilder.Entity<ShortenedUrl>().ToTable("ShortenedUrls");
  146. // Vaults
  147. modelBuilder.Entity<Vault>().ToTable("Vaults");
  148. modelBuilder.Entity<VaultItem>().ToTable("VaultItems");
  149. // Podcasts
  150. modelBuilder.Entity<Podcast>().ToTable("Podcasts");
  151. modelBuilder.Entity<PodcastFile>().ToTable("PodcastFiles");
  152. modelBuilder.Entity<PodcastComment>().ToTable("PodcastComments");
  153. // Transparency
  154. modelBuilder.Entity<Transaction>().ToTable("Transactions");
  155. modelBuilder.Entity<Takedown>().ToTable("Takedowns");
  156. // Custom Attributes
  157. modelBuilder.Conventions.Add(new AttributeToColumnAnnotationConvention<CaseSensitiveAttribute, bool>(
  158. "CaseSensitive",
  159. (property, attributes) => attributes.Single().IsEnabled));
  160. base.OnModelCreating(modelBuilder);
  161. }
  162. }
  163. }