2017-01-19 12:59:49 +01:00
|
|
|
|
|
2017-01-13 16:31:40 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Microsoft.AspNet.Identity.EntityFramework;
|
|
|
|
|
|
using Microsoft.Data.Entity;
|
2017-02-07 15:04:58 +01:00
|
|
|
|
using System.Threading;
|
2017-02-12 03:53:33 +01:00
|
|
|
|
using Yavsc.Models.Haircut;
|
2018-12-27 23:53:27 +00:00
|
|
|
|
using Yavsc.Models.IT.Evolution;
|
2017-10-02 04:43:20 +02:00
|
|
|
|
using Yavsc.Models.IT.Fixing;
|
2018-04-21 19:29:06 +02:00
|
|
|
|
using Yavsc.Server.Models.EMailing;
|
2018-06-08 09:57:53 +02:00
|
|
|
|
using Yavsc.Server.Models.IT.SourceCode;
|
2018-06-21 14:01:40 +02:00
|
|
|
|
using Yavsc.Server.Models.IT;
|
2019-01-03 14:42:35 +00:00
|
|
|
|
using Yavsc.Models.Streaming;
|
2017-01-13 16:31:40 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Yavsc.Models
|
|
|
|
|
|
{
|
2017-02-11 15:46:26 +01:00
|
|
|
|
using Relationship;
|
|
|
|
|
|
using Forms;
|
2017-05-27 16:22:58 +02:00
|
|
|
|
using Yavsc;
|
2017-01-13 16:31:40 +01:00
|
|
|
|
using Auth;
|
|
|
|
|
|
using Billing;
|
2017-02-12 22:20:57 +01:00
|
|
|
|
using Musical;
|
2017-01-13 16:31:40 +01:00
|
|
|
|
using Workflow;
|
|
|
|
|
|
using Identity;
|
|
|
|
|
|
using Market;
|
|
|
|
|
|
using Chat;
|
|
|
|
|
|
using Messaging;
|
|
|
|
|
|
using Access;
|
2017-02-12 22:20:57 +01:00
|
|
|
|
using Musical.Profiles;
|
2017-02-12 03:53:33 +01:00
|
|
|
|
using Workflow.Profiles;
|
|
|
|
|
|
using Drawing;
|
2017-05-07 22:12:04 +02:00
|
|
|
|
using Attributes;
|
|
|
|
|
|
using Bank;
|
|
|
|
|
|
using Payment;
|
2017-06-01 14:00:19 +02:00
|
|
|
|
using Yavsc.Models.Calendar;
|
2017-10-04 23:53:47 +02:00
|
|
|
|
using Blog;
|
2018-07-16 02:38:09 +02:00
|
|
|
|
using Yavsc.Abstract.Identity;
|
2018-12-12 14:32:03 +00:00
|
|
|
|
using Yavsc.Server.Models.Blog;
|
2017-02-25 17:48:11 +01:00
|
|
|
|
|
2017-01-13 16:31:40 +01:00
|
|
|
|
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
|
|
|
|
|
|
{
|
|
|
|
|
|
protected override void OnModelCreating(ModelBuilder builder)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnModelCreating(builder);
|
|
|
|
|
|
// Customize the ASP.NET Identity model and override the defaults if needed.
|
|
|
|
|
|
// For example, you can rename the ASP.NET Identity table names and more.
|
|
|
|
|
|
// Add your customizations after calling base.OnModelCreating(builder);
|
2019-05-07 14:01:23 +01:00
|
|
|
|
builder.Entity<Contact>().HasKey(x => new { x.OwnerId, x.UserId });
|
2018-06-25 22:15:33 +02:00
|
|
|
|
builder.Entity<GoogleCloudMobileDeclaration>().Property(x => x.DeclarationDate).HasDefaultValueSql("LOCALTIMESTAMP");
|
|
|
|
|
|
builder.Entity<BlogTag>().HasKey(x => new { x.PostId, x.TagId });
|
|
|
|
|
|
builder.Entity<ApplicationUser>().HasMany<ChatConnection>(c => c.Connections);
|
|
|
|
|
|
builder.Entity<ApplicationUser>().Property(u => u.Avatar).HasDefaultValue(Constants.DefaultAvatar);
|
|
|
|
|
|
builder.Entity<ApplicationUser>().Property(u => u.DiskQuota).HasDefaultValue(Constants.DefaultFSQ);
|
|
|
|
|
|
builder.Entity<UserActivity>().HasKey(u => new { u.DoesCode, u.UserId });
|
|
|
|
|
|
builder.Entity<Instrumentation>().HasKey(u => new { u.InstrumentId, u.UserId });
|
|
|
|
|
|
builder.Entity<CircleAuthorizationToBlogPost>().HasKey(a => new { a.CircleId, a.BlogPostId });
|
|
|
|
|
|
builder.Entity<CircleMember>().HasKey(c => new { MemberId = c.MemberId, CircleId = c.CircleId });
|
|
|
|
|
|
builder.Entity<DimissClicked>().HasKey(c => new { uid = c.UserId, notid = c.NotificationId });
|
|
|
|
|
|
builder.Entity<HairTaintInstance>().HasKey(ti => new { ti.TaintId, ti.PrestationId });
|
|
|
|
|
|
builder.Entity<HyperLink>().HasKey(l => new { l.HRef, l.Method });
|
|
|
|
|
|
builder.Entity<Period>().HasKey(l => new { l.Start, l.End });
|
|
|
|
|
|
builder.Entity<Models.Cratie.Option>().HasKey(o => new { o.Code, o.CodeScrutin });
|
|
|
|
|
|
builder.Entity<Notification>().Property(n => n.icon).HasDefaultValue("exclam");
|
|
|
|
|
|
builder.Entity<ChatRoomPresence>().HasKey(p => new { room = p.ChannelName, user = p.ChatUserConnectionId });
|
2018-12-27 22:23:02 +00:00
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
foreach (var et in builder.Model.GetEntityTypes())
|
|
|
|
|
|
{
|
|
|
|
|
|
if (et.ClrType.GetInterface("IBaseTrackedEntity") != null)
|
|
|
|
|
|
et.FindProperty("DateCreated").IsReadOnlyAfterSave = true;
|
2017-01-20 14:19:23 +01:00
|
|
|
|
}
|
2018-12-12 14:32:03 +00:00
|
|
|
|
builder.Entity<BlogTrad>().HasKey(tr => new { post = tr.PostId, lang = tr.Lang });
|
2017-01-13 16:31:40 +01:00
|
|
|
|
}
|
2018-06-25 17:54:39 +02:00
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
2018-06-25 22:15:33 +02:00
|
|
|
|
{
|
2018-06-29 10:30:04 +02:00
|
|
|
|
var appSetup = (string)AppDomain.CurrentDomain.GetData(Constants.YavscConnectionStringEnvName);
|
|
|
|
|
|
if (appSetup!=null) optionsBuilder.UseNpgsql(appSetup);
|
2019-01-03 14:42:35 +00:00
|
|
|
|
else {
|
|
|
|
|
|
var envSetup = Environment.GetEnvironmentVariable(Constants.YavscConnectionStringEnvName);
|
|
|
|
|
|
if (envSetup!=null) optionsBuilder.UseNpgsql(envSetup);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
}
|
2018-06-08 09:57:53 +02:00
|
|
|
|
|
2017-01-13 16:31:40 +01:00
|
|
|
|
public DbSet<Client> Applications { get; set; }
|
2017-04-01 02:14:10 +02:00
|
|
|
|
|
2017-01-13 16:31:40 +01:00
|
|
|
|
public DbSet<RefreshToken> RefreshTokens { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Activities referenced on this site
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public DbSet<Activity> Activities { get; set; }
|
|
|
|
|
|
public DbSet<UserActivity> UserActivities { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Users posts
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
2017-10-04 23:53:47 +02:00
|
|
|
|
public DbSet<Blog.BlogPost> Blogspot { get; set; }
|
2017-01-13 16:31:40 +01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Skills propulsed by this site
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public DbSet<Skill> SiteSkills { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Circle members
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public DbSet<CircleMember> CircleMembers { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Special commands, talking about
|
|
|
|
|
|
/// a given place and date.
|
|
|
|
|
|
/// </summary>
|
2017-02-27 19:28:32 +01:00
|
|
|
|
public DbSet<RdvQuery> RdvQueries { get; set; }
|
2017-06-08 00:26:29 +02:00
|
|
|
|
|
2017-02-27 19:28:32 +01:00
|
|
|
|
public DbSet<HairCutQuery> HairCutQueries { get; set; }
|
2017-04-01 02:14:10 +02:00
|
|
|
|
public DbSet<HairPrestation> HairPrestation { get; set; }
|
2017-06-08 00:26:29 +02:00
|
|
|
|
|
2017-02-27 19:28:32 +01:00
|
|
|
|
public DbSet<HairMultiCutQuery> HairMultiCutQueries { get; set; }
|
2017-01-13 16:31:40 +01:00
|
|
|
|
public DbSet<PerformerProfile> Performers { get; set; }
|
2017-06-08 00:26:29 +02:00
|
|
|
|
|
2017-01-13 16:31:40 +01:00
|
|
|
|
public DbSet<Estimate> Estimates { get; set; }
|
|
|
|
|
|
public DbSet<AccountBalance> BankStatus { get; set; }
|
|
|
|
|
|
public DbSet<BalanceImpact> BankBook { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Google Calendar offline
|
|
|
|
|
|
/// open auth tokens
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>tokens</returns>
|
|
|
|
|
|
public DbSet<OAuth2Tokens> Tokens { get; set; }
|
2017-04-01 02:14:10 +02:00
|
|
|
|
|
2017-01-13 16:31:40 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// References all declared external GCM devices
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<GoogleCloudMobileDeclaration> GCMDevices { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public DbSet<Service> Services { get; set; }
|
|
|
|
|
|
public DbSet<Product> Products { get; set; }
|
2017-01-13 16:31:40 +01:00
|
|
|
|
|
|
|
|
|
|
Client FindApplication(string clientId)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Applications.FirstOrDefault(
|
2018-06-25 22:15:33 +02:00
|
|
|
|
app => app.Id == clientId);
|
2017-01-13 16:31:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public DbSet<ExceptionSIREN> ExceptionsSIREN { get; set; }
|
|
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<Location> Locations { get; set; }
|
2017-01-13 16:31:40 +01:00
|
|
|
|
|
|
|
|
|
|
public DbSet<Tag> Tags { get; set; }
|
|
|
|
|
|
|
2017-09-20 13:07:13 +02:00
|
|
|
|
public DbSet<BlogTag> TagsDomain { get; set; }
|
2017-01-13 16:31:40 +01:00
|
|
|
|
|
|
|
|
|
|
public DbSet<EstimateTemplate> EstimateTemplates { get; set; }
|
|
|
|
|
|
|
2019-05-07 14:01:23 +01:00
|
|
|
|
public DbSet<Contact> Contacts { get; set; }
|
2017-01-13 16:31:40 +01:00
|
|
|
|
|
|
|
|
|
|
public DbSet<ClientProviderInfo> ClientProviderInfo { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public DbSet<BlackListed> BlackListed { get; set; }
|
|
|
|
|
|
|
2019-05-07 14:01:23 +01:00
|
|
|
|
public DbSet<MusicalPreference> MusicalPreference { get; set; }
|
2017-01-13 16:31:40 +01:00
|
|
|
|
|
|
|
|
|
|
public DbSet<MusicalTendency> MusicalTendency { get; set; }
|
|
|
|
|
|
|
2017-03-06 14:50:57 +01:00
|
|
|
|
public DbSet<Instrument> Instrument { get; set; }
|
|
|
|
|
|
|
2017-04-01 02:14:10 +02:00
|
|
|
|
[ActivitySettings]
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<DjSettings> DjSettings { get; set; }
|
2017-04-01 02:14:10 +02:00
|
|
|
|
|
2017-03-05 16:32:30 +01:00
|
|
|
|
[ActivitySettings]
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<Instrumentation> Instrumentation { get; set; }
|
2017-03-05 16:32:30 +01:00
|
|
|
|
|
|
|
|
|
|
[ActivitySettings]
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<FormationSettings> FormationSettings { get; set; }
|
2017-04-01 02:14:10 +02:00
|
|
|
|
|
2017-03-05 16:32:30 +01:00
|
|
|
|
[ActivitySettings]
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<GeneralSettings> GeneralSettings { get; set; }
|
2019-05-07 14:01:23 +01:00
|
|
|
|
public DbSet<CoWorking> CoWorking { get; set; }
|
2017-01-17 14:56:53 +01:00
|
|
|
|
|
2017-02-25 17:48:11 +01:00
|
|
|
|
private void AddTimestamps(string currentUsername)
|
2018-06-25 22:15:33 +02:00
|
|
|
|
{
|
|
|
|
|
|
var entities =
|
|
|
|
|
|
ChangeTracker.Entries()
|
|
|
|
|
|
.Where(x => x.Entity.GetType().GetInterface("IBaseTrackedEntity") != null
|
|
|
|
|
|
&& (x.State == EntityState.Added || x.State == EntityState.Modified));
|
2017-01-17 14:56:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
foreach (var entity in entities)
|
2017-01-17 14:56:53 +01:00
|
|
|
|
{
|
2018-06-25 22:15:33 +02:00
|
|
|
|
if (entity.State == EntityState.Added)
|
|
|
|
|
|
{
|
|
|
|
|
|
((IBaseTrackedEntity)entity.Entity).DateCreated = DateTime.Now;
|
|
|
|
|
|
((IBaseTrackedEntity)entity.Entity).UserCreated = currentUsername;
|
|
|
|
|
|
}
|
2017-01-17 14:56:53 +01:00
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
((IBaseTrackedEntity)entity.Entity).DateModified = DateTime.Now;
|
|
|
|
|
|
((IBaseTrackedEntity)entity.Entity).UserModified = currentUsername;
|
|
|
|
|
|
}
|
2017-01-17 14:56:53 +01:00
|
|
|
|
}
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public int SaveChanges(string userId)
|
|
|
|
|
|
{
|
2017-02-25 17:48:11 +01:00
|
|
|
|
AddTimestamps(userId);
|
2017-01-17 14:56:53 +01:00
|
|
|
|
return base.SaveChanges();
|
|
|
|
|
|
}
|
2017-02-25 17:48:11 +01:00
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public async Task<int> SaveChangesAsync(string userId, CancellationToken ctoken = default(CancellationToken))
|
|
|
|
|
|
{
|
2017-02-25 17:48:11 +01:00
|
|
|
|
AddTimestamps(userId);
|
2017-01-17 14:56:53 +01:00
|
|
|
|
return await base.SaveChangesAsync();
|
|
|
|
|
|
}
|
2017-04-01 02:14:10 +02:00
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<Circle> Circle { get; set; }
|
2017-01-20 14:19:23 +01:00
|
|
|
|
|
2019-05-07 14:01:23 +01:00
|
|
|
|
public DbSet<CircleAuthorizationToBlogPost> CircleAuthorizationToBlogPost { get; set; }
|
2017-01-20 14:19:23 +01:00
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<CommandForm> CommandForm { get; set; }
|
2017-01-23 09:52:13 +01:00
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<Form> Form { get; set; }
|
2017-01-24 10:43:42 +01:00
|
|
|
|
|
2019-05-07 14:01:23 +01:00
|
|
|
|
public DbSet<Ban> Ban { get; set; }
|
2017-02-12 03:53:33 +01:00
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<HairTaint> HairTaint { get; set; }
|
2017-02-12 03:53:33 +01:00
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<Color> Color { get; set; }
|
2017-02-20 15:53:25 +01:00
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<Notification> Notification { get; set; }
|
2017-02-20 15:53:25 +01:00
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<DimissClicked> DimissClicked { get; set; }
|
2017-02-27 19:28:32 +01:00
|
|
|
|
|
2017-02-28 14:01:24 +01:00
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
[ActivitySettings]
|
|
|
|
|
|
public DbSet<BrusherProfile> BrusherProfile { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public DbSet<BankIdentity> BankIdentity { get; set; }
|
2017-02-01 03:53:00 +01:00
|
|
|
|
|
2019-05-07 14:01:23 +01:00
|
|
|
|
public DbSet<PayPalPayment> PayPalPayment { get; set; }
|
2017-05-15 13:36:14 +02:00
|
|
|
|
|
2019-05-07 14:01:23 +01:00
|
|
|
|
public DbSet<HyperLink> HyperLink { get; set; }
|
2017-05-15 13:36:14 +02:00
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<Period> Period { get; set; }
|
2017-06-01 14:00:19 +02:00
|
|
|
|
|
2019-05-07 14:01:23 +01:00
|
|
|
|
public DbSet<BlogTag> BlogTag { get; set; }
|
2017-09-20 13:07:13 +02:00
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<ApplicationUser> ApplicationUser { get; set; }
|
2017-09-20 14:28:48 +02:00
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<Feature> Feature { get; set; }
|
2017-10-02 04:43:20 +02:00
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<Bug> Bug { get; set; }
|
2017-10-02 04:43:20 +02:00
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<Comment> Comment { get; set; }
|
2017-10-04 23:53:47 +02:00
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<Announce> Announce { get; set; }
|
2017-10-10 20:50:05 +02:00
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<ChatConnection> ChatConnection { get; set; }
|
2018-01-02 16:35:03 +01:00
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<ChatRoom> ChatRoom { get; set; }
|
2018-04-21 19:29:06 +02:00
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<MailingTemplate> MailingTemplate { get; set; }
|
2018-01-02 16:35:03 +01:00
|
|
|
|
|
2018-06-25 22:15:33 +02:00
|
|
|
|
public DbSet<GitRepositoryReference> GitRepositoryReference { get; set; }
|
2018-06-08 09:57:53 +02:00
|
|
|
|
|
2019-05-07 14:01:23 +01:00
|
|
|
|
public DbSet<Project> Project { get; set; }
|
2018-12-12 14:32:03 +00:00
|
|
|
|
|
|
|
|
|
|
public DbSet<BlogTrad> BlogTrad { get; set; }
|
2018-06-21 14:01:40 +02:00
|
|
|
|
|
2019-01-03 14:42:35 +00:00
|
|
|
|
public DbSet<LiveFlow> LiveFlow { get; set; }
|
|
|
|
|
|
|
2017-01-13 16:31:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|