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

DataContext.cs 3.2KB

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