diff --git a/Yavsc/Models/ApplicationDbContext.cs b/Yavsc/Models/ApplicationDbContext.cs index dbaa6dfd..ff53e8a3 100644 --- a/Yavsc/Models/ApplicationDbContext.cs +++ b/Yavsc/Models/ApplicationDbContext.cs @@ -27,6 +27,7 @@ namespace Yavsc.Models using Workflow.Profiles; using Drawing; using Yavsc.Attributes; + using System.Collections.Generic; public class ApplicationDbContext : IdentityDbContext { @@ -54,11 +55,19 @@ namespace Yavsc.Models } } - + public ISet GetDbSet() where TSettings : class, ISpecializationSettings + + { + return (ISet) GetDbSet(typeof(TSettings).FullName); + } public IQueryable GetDbSet(string settingsClassName) { - var dbSetPropInfo = Startup.UserSettings.SingleOrDefault(s => s.PropertyType.GenericTypeArguments[0].FullName == settingsClassName ) ; + var dbSetPropInfo = Startup.GetUserSettingPropertyInfo(settingsClassName); if (dbSetPropInfo == null) return null; + // var settingType = dbSetPropInfo.PropertyType; + // var dbSetType = typeof(DbSet<>).MakeGenericType(new Type[] { settingType } ); + // avec une info method Remove et Update, ça le ferait ... + return (IQueryable) dbSetPropInfo.GetValue(this); } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) @@ -242,9 +251,11 @@ namespace Yavsc.Models private void AddTimestamps(string currentUsername) { - var entities = ChangeTracker.Entries().Where(x => x.Entity.GetType().GetInterface("IBaseTrackedEntity")!=null && (x.State == EntityState.Added || x.State == EntityState.Modified)); + var entities = + ChangeTracker.Entries() + .Where(x => x.Entity.GetType().GetInterface("IBaseTrackedEntity")!=null + && (x.State == EntityState.Added || x.State == EntityState.Modified)); - // Microsoft.AspNet.Identity; foreach (var entity in entities) { diff --git a/Yavsc/Startup/Startup.Workflow.cs b/Yavsc/Startup/Startup.Workflow.cs index f1193cf4..77a332d6 100644 --- a/Yavsc/Startup/Startup.Workflow.cs +++ b/Yavsc/Startup/Startup.Workflow.cs @@ -25,6 +25,11 @@ namespace Yavsc /// public static readonly string [] Forms = new string [] { "Profiles" , "HairCut" }; + public static PropertyInfo GetUserSettingPropertyInfo(string settingsClassName) + { + return UserSettings.SingleOrDefault(s => s.PropertyType.GenericTypeArguments[0].FullName == settingsClassName ) ; + } + private void ConfigureWorkflow(IApplicationBuilder app, SiteSettings settings, ILogger logger) { System.AppDomain.CurrentDomain.ResourceResolve += OnYavscResourceResolve;