restore l'edition du profile
This commit is contained in:
@ -1,14 +1,13 @@
|
|||||||
using Yavsc.Controllers.Generic;
|
using Yavsc.Controllers.Generic;
|
||||||
using Yavsc.Models;
|
using Yavsc.Models;
|
||||||
using Yavsc.Models.Workflow.Profiles;
|
using Yavsc.Models.Workflow.Profiles;
|
||||||
using Yavsc.Services;
|
|
||||||
|
|
||||||
namespace Yavsc.Controllers
|
namespace Yavsc.Controllers
|
||||||
{
|
{
|
||||||
public class FormationSettingsController : SettingsController<FormationSettings>
|
public class FormationSettingsController : SettingsController<FormationSettings>
|
||||||
{
|
{
|
||||||
|
|
||||||
public FormationSettingsController(ApplicationDbContext context, IBillingService billing) : base(context, billing)
|
public FormationSettingsController(ApplicationDbContext context) : base(context)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,29 +6,29 @@ using Microsoft.Data.Entity;
|
|||||||
|
|
||||||
namespace Yavsc.Controllers.Generic
|
namespace Yavsc.Controllers.Generic
|
||||||
{
|
{
|
||||||
|
using System.Linq;
|
||||||
using Models;
|
using Models;
|
||||||
using Yavsc.Services;
|
|
||||||
|
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public abstract class SettingsController<TSettings> : Controller where TSettings : class, ISpecializationSettings, new()
|
public abstract class SettingsController<TSettings> : Controller where TSettings : class, ISpecializationSettings, new()
|
||||||
{
|
{
|
||||||
protected ApplicationDbContext _context;
|
protected ApplicationDbContext _context;
|
||||||
IBillingService billing;
|
|
||||||
DbSet<TSettings> dbSet=null;
|
DbSet<TSettings> dbSet=null;
|
||||||
|
|
||||||
protected string activityCode=null;
|
protected string activityCode=null;
|
||||||
|
|
||||||
protected DbSet<TSettings> Settings { get {
|
protected DbSet<TSettings> Settings { get {
|
||||||
if (dbSet == null) Task.Run( async () => {
|
if (dbSet == null) {
|
||||||
dbSet = (DbSet<TSettings>) await billing.GetPerformersSettingsAsync(activityCode);
|
dbSet = (DbSet<TSettings>) Startup.UserSettings.Single(s=>s.Name == typeof(TSettings).Name).GetValue(_context);
|
||||||
});
|
}
|
||||||
|
|
||||||
|
|
||||||
return dbSet;
|
return dbSet;
|
||||||
} }
|
} }
|
||||||
|
|
||||||
public SettingsController(ApplicationDbContext context, IBillingService billing)
|
public SettingsController(ApplicationDbContext context)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
this.billing = billing;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> Index()
|
public async Task<IActionResult> Index()
|
||||||
|
@ -2,7 +2,6 @@ using Yavsc.Models;
|
|||||||
using Yavsc.Models.Haircut;
|
using Yavsc.Models.Haircut;
|
||||||
using Microsoft.AspNet.Authorization;
|
using Microsoft.AspNet.Authorization;
|
||||||
using Yavsc.Controllers.Generic;
|
using Yavsc.Controllers.Generic;
|
||||||
using Yavsc.Services;
|
|
||||||
|
|
||||||
namespace Yavsc.Controllers
|
namespace Yavsc.Controllers
|
||||||
{
|
{
|
||||||
@ -10,7 +9,7 @@ namespace Yavsc.Controllers
|
|||||||
public class BrusherProfileController : SettingsController<BrusherProfile>
|
public class BrusherProfileController : SettingsController<BrusherProfile>
|
||||||
{
|
{
|
||||||
|
|
||||||
public BrusherProfileController(ApplicationDbContext context, IBillingService billing) : base(context, billing)
|
public BrusherProfileController(ApplicationDbContext context) : base(context)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Data.Entity;
|
using Microsoft.Data.Entity;
|
||||||
@ -20,24 +18,6 @@ namespace Yavsc.Services
|
|||||||
logger = loggerFactory.CreateLogger<BillingService>();
|
logger = loggerFactory.CreateLogger<BillingService>();
|
||||||
DbContext = dbContext;
|
DbContext = dbContext;
|
||||||
}
|
}
|
||||||
public async Task<IQueryable<ISpecializationSettings>> GetPerformersSettings(string activityCode)
|
|
||||||
{
|
|
||||||
logger.LogDebug("searching for "+activityCode);
|
|
||||||
var activity = await DbContext.Activities.SingleAsync(a=>a.Code == activityCode);
|
|
||||||
logger.LogDebug(JsonConvert.SerializeObject(activity));
|
|
||||||
|
|
||||||
|
|
||||||
if (activity.SettingsClassName==null) return null;
|
|
||||||
var dbSetPropInfo = Startup.UserSettings.SingleOrDefault(s => s.PropertyType.GenericTypeArguments[0].FullName == activity.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<ISpecializationSettings>) dbSetPropInfo.GetValue(DbContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IBillable> GetBillAsync(string billingCode, long queryId)
|
public async Task<IBillable> GetBillAsync(string billingCode, long queryId)
|
||||||
{
|
{
|
||||||
@ -48,14 +28,24 @@ namespace Yavsc.Services
|
|||||||
|
|
||||||
public async Task<ISpecializationSettings> GetPerformerSettingsAsync(string activityCode, string userId)
|
public async Task<ISpecializationSettings> GetPerformerSettingsAsync(string activityCode, string userId)
|
||||||
{
|
{
|
||||||
return await (await GetPerformersSettings(activityCode)).SingleOrDefaultAsync(s=> s.UserId == userId);
|
return await (await GetPerformersSettingsAsync(activityCode)).SingleOrDefaultAsync(s=> s.UserId == userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<IQueryable<ISpecializationSettings>> GetPerformersSettingsAsync(string activityCode)
|
public async Task<IQueryable<ISpecializationSettings>> GetPerformersSettingsAsync(string activityCode)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
logger.LogDebug("searching for "+activityCode);
|
||||||
}
|
var activity = await DbContext.Activities.SingleAsync(a=>a.Code == activityCode);
|
||||||
|
logger.LogDebug(JsonConvert.SerializeObject(activity));
|
||||||
|
|
||||||
|
if (activity.SettingsClassName==null) return null;
|
||||||
|
var dbSetPropInfo = Startup.UserSettings.SingleOrDefault(s => s.PropertyType.GenericTypeArguments[0].FullName == activity.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<ISpecializationSettings>) dbSetPropInfo.GetValue(DbContext);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user