12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using Microsoft.EntityFrameworkCore;
- using UnivateProperties_API.Model.Communication;
- using UnivateProperties_API.Model.Users;
- using UnivateProperties_API.Model.Property;
- using UnivateProperties_API.Model.Region;
- using UnivateProperties_API.Model.Timeshare;
- using System.Linq;
- using UnivateProperties_API.Model;
-
- namespace UnivateProperties_API.Context
- {
- public class DataContext : DbContext
- {
- public DataContext(DbContextOptions<DataContext> options) : base(options)
- {
-
- }
-
- #region User
- public virtual DbSet<Agency> Agencies { get; set; }
- public virtual DbSet<Agent> Agents { get; set; }
- public virtual DbSet<User> Users { get; set; }
- public virtual DbSet<Individual> Individuals { get; set; }
- #endregion User
-
- #region Communication
- public virtual DbSet<Email> Emails { get; set; }
- public virtual DbSet<SMTPAccount> Accounts { get; set; }
- public virtual DbSet<SMTPHost> Hosts { get; set; }
- #endregion Communication
-
- #region Property
- public DbSet<Property> Properties { get; set; }
- public DbSet<PropertyImage> PropertyImages { get; set; }
- public DbSet<PropertyType> PropertyTypes { get; set; }
- public DbSet<PropertyUserField> PropertyUserFields { get; set; }
- public DbSet<UserDefinedField> UserDefinedFields { get; set; }
- public DbSet<UserDefinedGroup> UserDefinedGroups { get; set; }
- #endregion
-
- #region Region
- public DbSet<Province> Provinces { get; set; }
- public DbSet<City> Cities { get; set; }
- public DbSet<Suburb> Suburbs { get; set; }
- #endregion
-
- #region Timeshare
- public DbSet<TimeshareWeek> Weeks { get; set; }
- public DbSet<Status> Status { get; set; }
- public DbSet<UnitConfiguration> UnitConfigurations { get; set; }
- public DbSet<UnitConfigurationType> UnitConfigurationTypes { get; set; }
- public DbSet<Season> Seasons { get; set; }
- #endregion Timeshare
-
- public override int SaveChanges()
- {
- foreach(var item in ChangeTracker
- .Entries()
- .Where(x => x.State == EntityState.Modified || x.State == EntityState.Added)
- .Select(x => x.Entity)
- .ToList())
- {
- if(item is BaseEntity)
- {
- (item as BaseEntity).UpdateModified(string.Empty);
- }
- }
- return base.SaveChanges();
- }
-
- protected override void OnModelCreating(ModelBuilder modelBuilder)
- {
- modelBuilder.Entity<SMTPHost>().ToTable("Hosts");
- modelBuilder.Entity<UnitConfiguration>()
- .HasIndex(u => u.Code)
- .IsUnique();
- }
- }
- }
|