API
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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