API
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

DataContext.cs 2.9KB

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