API
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

DataContext.cs 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.Banks;
  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. #endregion Timeshare
  53. #region ProcessFlow
  54. public DbSet<ProcessFlow> ProcessFlows { get; set; }
  55. public DbSet<BidItem> BidItems { get; set; }
  56. #endregion
  57. public override int SaveChanges()
  58. {
  59. foreach(var item in ChangeTracker
  60. .Entries()
  61. .Where(x => x.State == EntityState.Modified || x.State == EntityState.Added)
  62. .Select(x => x.Entity)
  63. .ToList())
  64. {
  65. if(item is BaseEntity)
  66. {
  67. (item as BaseEntity).UpdateModified(string.Empty);
  68. }
  69. }
  70. return base.SaveChanges();
  71. }
  72. protected override void OnModelCreating(ModelBuilder modelBuilder)
  73. {
  74. modelBuilder.Entity<SMTPHost>().ToTable("Hosts");
  75. modelBuilder.Entity<UnitConfiguration>()
  76. .HasIndex(u => u.Code)
  77. .IsUnique();
  78. }
  79. }
  80. }