The next generation of the Teknik Services. Written in ASP.NET. Fork for blog tags.
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.7KB

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