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 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. namespace Teknik.Models
  17. {
  18. public class TeknikEntities : DbContext
  19. {
  20. // Users
  21. public DbSet<User> Users { get; set; }
  22. public DbSet<Group> Groups { get; set; }
  23. public DbSet<Role> Roles { get; set; }
  24. public DbSet<TrustedDevice> TrustedDevices { get; set; }
  25. public DbSet<TransferType> TransferTypes { get; set; }
  26. // User Settings
  27. public DbSet<UserSettings> UserSettings { get; set; }
  28. public DbSet<SecuritySettings> SecuritySettings { get; set; }
  29. public DbSet<BlogSettings> BlogSettings { get; set; }
  30. public DbSet<UploadSettings> UploadSettings { get; set; }
  31. // Authentication and Sessions
  32. public DbSet<RecoveryEmailVerification> RecoveryEmailVerifications { get; set; }
  33. public DbSet<ResetPasswordVerification> ResetPasswordVerifications { get; set; }
  34. // Blogs
  35. public DbSet<Blog> Blogs { get; set; }
  36. public DbSet<BlogPost> BlogPosts { get; set; }
  37. public DbSet<BlogPostComment> BlogComments { get; set; }
  38. // Contact
  39. public DbSet<Contact> Contact { get; set; }
  40. // Uploads
  41. public DbSet<Upload> Uploads { get; set; }
  42. // Pastes
  43. public DbSet<Paste> Pastes { get; set; }
  44. // Podcasts
  45. public DbSet<Podcast> Podcasts { get; set; }
  46. public DbSet<PodcastFile> PodcastFiles { get; set; }
  47. public DbSet<PodcastComment> PodcastComments { get; set; }
  48. // Transparency
  49. public DbSet<Transaction> Transactions { get; set; }
  50. public DbSet<Takedown> Takedowns { get; set; }
  51. // Url Shortener
  52. public DbSet<ShortenedUrl> ShortenedUrls { get; set; }
  53. protected override void OnModelCreating(DbModelBuilder modelBuilder)
  54. {
  55. // User Settings Mappings
  56. modelBuilder.Entity<User>()
  57. .HasRequired(a => a.UserSettings)
  58. .WithRequiredPrincipal(a => a.User);
  59. modelBuilder.Entity<User>()
  60. .HasRequired(a => a.SecuritySettings)
  61. .WithRequiredPrincipal(a => a.User);
  62. modelBuilder.Entity<User>()
  63. .HasRequired(a => a.BlogSettings)
  64. .WithRequiredPrincipal(a => a.User);
  65. modelBuilder.Entity<User>()
  66. .HasRequired(a => a.UploadSettings)
  67. .WithRequiredPrincipal(a => a.User);
  68. modelBuilder.Entity<UserSettings>()
  69. .HasRequired(a => a.SecuritySettings)
  70. .WithRequiredPrincipal(a => a.UserSettings);
  71. modelBuilder.Entity<UserSettings>()
  72. .HasRequired(a => a.BlogSettings)
  73. .WithRequiredPrincipal(a => a.UserSettings);
  74. modelBuilder.Entity<UserSettings>()
  75. .HasRequired(a => a.UploadSettings)
  76. .WithRequiredPrincipal(a => a.UserSettings);
  77. modelBuilder.Entity<SecuritySettings>()
  78. .HasRequired(a => a.BlogSettings)
  79. .WithRequiredPrincipal(a => a.SecuritySettings);
  80. modelBuilder.Entity<SecuritySettings>()
  81. .HasRequired(a => a.UploadSettings)
  82. .WithRequiredPrincipal(a => a.SecuritySettings);
  83. modelBuilder.Entity<BlogSettings>()
  84. .HasRequired(a => a.UploadSettings)
  85. .WithRequiredPrincipal(a => a.BlogSettings);
  86. // User Mappings
  87. modelBuilder.Entity<User>()
  88. .HasMany<Upload>(u => u.Uploads)
  89. .WithOptional(u => u.User)
  90. .WillCascadeOnDelete(false);
  91. modelBuilder.Entity<User>()
  92. .HasMany<Paste>(u => u.Pastes)
  93. .WithOptional(u => u.User)
  94. .WillCascadeOnDelete(false);
  95. // Upload Mappings
  96. modelBuilder.Entity<Upload>()
  97. .HasOptional(u => u.User);
  98. // Paste Mappings
  99. modelBuilder.Entity<Paste>()
  100. .HasOptional(u => u.User);
  101. // Users
  102. modelBuilder.Entity<User>().ToTable("Users");
  103. modelBuilder.Entity<Group>().ToTable("Groups");
  104. modelBuilder.Entity<Role>().ToTable("Roles");
  105. modelBuilder.Entity<TrustedDevice>().ToTable("TrustedDevices");
  106. modelBuilder.Entity<TransferType>().ToTable("TransferTypes");
  107. modelBuilder.Entity<RecoveryEmailVerification>().ToTable("RecoveryEmailVerifications");
  108. modelBuilder.Entity<ResetPasswordVerification>().ToTable("ResetPasswordVerifications");
  109. // User Settings
  110. modelBuilder.Entity<UserSettings>().ToTable("Users");
  111. modelBuilder.Entity<SecuritySettings>().ToTable("Users");
  112. modelBuilder.Entity<BlogSettings>().ToTable("Users");
  113. modelBuilder.Entity<UploadSettings>().ToTable("Users");
  114. // Blogs
  115. modelBuilder.Entity<Blog>().ToTable("Blogs");
  116. modelBuilder.Entity<BlogPost>().ToTable("BlogPosts");
  117. modelBuilder.Entity<PodcastComment>().ToTable("BlogComments");
  118. // Contact
  119. modelBuilder.Entity<Contact>().ToTable("Contact");
  120. // Uploads
  121. modelBuilder.Entity<Upload>().ToTable("Uploads");
  122. // Pastes
  123. modelBuilder.Entity<Paste>().ToTable("Pastes");
  124. // Podcasts
  125. modelBuilder.Entity<Podcast>().ToTable("Podcasts");
  126. modelBuilder.Entity<PodcastFile>().ToTable("PodcastFiles");
  127. modelBuilder.Entity<PodcastComment>().ToTable("PodcastComments");
  128. // Transparency
  129. modelBuilder.Entity<Transaction>().ToTable("Transactions");
  130. modelBuilder.Entity<Takedown>().ToTable("Takedowns");
  131. // Shortened Urls
  132. modelBuilder.Entity<ShortenedUrl>().ToTable("ShortenedUrls");
  133. // Custom Attributes
  134. modelBuilder.Conventions.Add(new AttributeToColumnAnnotationConvention<CaseSensitiveAttribute, bool>(
  135. "CaseSensitive",
  136. (property, attributes) => attributes.Single().IsEnabled));
  137. base.OnModelCreating(modelBuilder);
  138. }
  139. }
  140. }