API
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

DataContext.cs 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using Microsoft.EntityFrameworkCore;
  2. using UnivateProperties_API.Model.Communication;
  3. using UnivateProperties_API.Model.Users;
  4. using UnivateProperties_API.Model.Properties;
  5. using UnivateProperties_API.Model.Region;
  6. using UnivateProperties_API.Model.Timeshare;
  7. using System.Linq;
  8. using UnivateProperties_API.Model;
  9. using UnivateProperties_API.Model.Bank;
  10. using UnivateProperties_API.Model.Misc;
  11. namespace UnivateProperties_API.Context
  12. {
  13. public class DataContext : DbContext
  14. {
  15. public DataContext(DbContextOptions<DataContext> options) : base(options)
  16. {
  17. }
  18. #region User
  19. public virtual DbSet<Agency> Agencies { get; set; }
  20. public virtual DbSet<Agent> Agents { get; set; }
  21. public virtual DbSet<User> Users { get; set; }
  22. public virtual DbSet<Individual> Individuals { get; set; }
  23. public virtual DbSet<Address> Addresses { get; set; }
  24. #endregion User
  25. #region Communication
  26. public virtual DbSet<Email> Emails { get; set; }
  27. public virtual DbSet<SMTPAccount> Accounts { get; set; }
  28. public virtual DbSet<SMTPHost> Hosts { get; set; }
  29. #endregion Communication
  30. #region Property
  31. public DbSet<Property> Properties { get; set; }
  32. public DbSet<PropertyImage> PropertyImages { get; set; }
  33. public DbSet<PropertyType> PropertyTypes { get; set; }
  34. public DbSet<PropertyUserField> PropertyUserFields { get; set; }
  35. public DbSet<UserDefinedField> UserDefinedFields { get; set; }
  36. public DbSet<UserDefinedGroup> UserDefinedGroups { get; set; }
  37. #endregion
  38. #region Region
  39. public DbSet<Province> Provinces { get; set; }
  40. public DbSet<City> Cities { get; set; }
  41. public DbSet<Suburb> Suburbs { get; set; }
  42. #endregion
  43. #region Timeshare
  44. public DbSet<TimeshareWeek> Weeks { get; set; }
  45. public DbSet<Status> Status { get; set; }
  46. public DbSet<UnitConfiguration> UnitConfigurations { get; set; }
  47. public DbSet<UnitConfigurationType> UnitConfigurationTypes { get; set; }
  48. public DbSet<Season> Seasons { get; set; }
  49. public DbSet<Bank> Banks { get; set; }
  50. public DbSet<BankAccount> BankAccounts { get; set; }
  51. #endregion Timeshare
  52. public override int SaveChanges()
  53. {
  54. foreach(var item in ChangeTracker
  55. .Entries()
  56. .Where(x => x.State == EntityState.Modified || x.State == EntityState.Added)
  57. .Select(x => x.Entity)
  58. .ToList())
  59. {
  60. if(item is BaseEntity)
  61. {
  62. (item as BaseEntity).UpdateModified(string.Empty);
  63. }
  64. }
  65. return base.SaveChanges();
  66. }
  67. protected override void OnModelCreating(ModelBuilder modelBuilder)
  68. {
  69. modelBuilder.Entity<SMTPHost>().ToTable("Hosts");
  70. modelBuilder.Entity<UnitConfiguration>()
  71. .HasIndex(u => u.Code)
  72. .IsUnique();
  73. }
  74. }
  75. }