refactoring
This commit is contained in:
parent
013e36c558
commit
f60584b0e4
2 changed files with 20 additions and 4 deletions
|
|
@ -27,6 +27,7 @@ namespace Yavsc.Models
|
||||||
using Workflow.Profiles;
|
using Workflow.Profiles;
|
||||||
using Drawing;
|
using Drawing;
|
||||||
using Yavsc.Attributes;
|
using Yavsc.Attributes;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
|
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
|
||||||
{
|
{
|
||||||
|
|
@ -54,11 +55,19 @@ namespace Yavsc.Models
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public ISet<TSettings> GetDbSet<TSettings>() where TSettings : class, ISpecializationSettings
|
||||||
|
|
||||||
|
{
|
||||||
|
return (ISet<TSettings>) GetDbSet(typeof(TSettings).FullName);
|
||||||
|
}
|
||||||
public IQueryable<ISpecializationSettings> GetDbSet(string settingsClassName)
|
public IQueryable<ISpecializationSettings> 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;
|
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<ISpecializationSettings>) dbSetPropInfo.GetValue(this);
|
return (IQueryable<ISpecializationSettings>) dbSetPropInfo.GetValue(this);
|
||||||
}
|
}
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
|
@ -242,9 +251,11 @@ namespace Yavsc.Models
|
||||||
|
|
||||||
private void AddTimestamps(string currentUsername)
|
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)
|
foreach (var entity in entities)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,11 @@ namespace Yavsc
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly string [] Forms = new string [] { "Profiles" , "HairCut" };
|
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)
|
private void ConfigureWorkflow(IApplicationBuilder app, SiteSettings settings, ILogger logger)
|
||||||
{
|
{
|
||||||
System.AppDomain.CurrentDomain.ResourceResolve += OnYavscResourceResolve;
|
System.AppDomain.CurrentDomain.ResourceResolve += OnYavscResourceResolve;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue