API
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

DataContext.cs 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.Bank;
  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. #endregion User
  23. #region Communication
  24. public virtual DbSet<Email> Emails { get; set; }
  25. public virtual DbSet<SMTPAccount> Accounts { get; set; }
  26. public virtual DbSet<SMTPHost> Hosts { get; set; }
  27. #endregion Communication
  28. #region Property
  29. public DbSet<Property> Properties { get; set; }
  30. public DbSet<PropertyImage> PropertyImages { get; set; }
  31. public DbSet<PropertyType> PropertyTypes { get; set; }
  32. public DbSet<PropertyUserField> PropertyUserFields { get; set; }
  33. public DbSet<UserDefinedField> UserDefinedFields { get; set; }
  34. public DbSet<UserDefinedGroup> UserDefinedGroups { get; set; }
  35. #endregion
  36. #region Region
  37. public DbSet<Province> Provinces { get; set; }
  38. public DbSet<City> Cities { get; set; }
  39. public DbSet<Suburb> Suburbs { get; set; }
  40. #endregion
  41. #region Timeshare
  42. public DbSet<TimeshareWeek> Weeks { get; set; }
  43. public DbSet<Status> Status { get; set; }
  44. public DbSet<UnitConfiguration> UnitConfigurations { get; set; }
  45. public DbSet<UnitConfigurationType> UnitConfigurationTypes { get; set; }
  46. public DbSet<Season> Seasons { get; set; }
  47. public DbSet<Bank> Banks { get; set; }
  48. public DbSet<BankAccount> BankAccounts { get; set; }
  49. #endregion Timeshare
  50. public override int SaveChanges()
  51. {
  52. foreach(var item in ChangeTracker
  53. .Entries()
  54. .Where(x => x.State == EntityState.Modified || x.State == EntityState.Added)
  55. .Select(x => x.Entity)
  56. .ToList())
  57. {
  58. if(item is BaseEntity)
  59. {
  60. (item as BaseEntity).UpdateModified(string.Empty);
  61. }
  62. }
  63. return base.SaveChanges();
  64. }
  65. protected override void OnModelCreating(ModelBuilder modelBuilder)
  66. {
  67. modelBuilder.Entity<SMTPHost>().ToTable("Hosts");
  68. modelBuilder.Entity<UnitConfiguration>()
  69. .HasIndex(u => u.Code)
  70. .IsUnique();
  71. }
  72. }
  73. }