From c7f26fb636031185f3a62a9d9f4fd947f6ef7d9f Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Thu, 8 Jun 2017 22:45:34 +0200 Subject: [PATCH] restore l'edition du profile --- .../FormationSettingsController.cs | 3 +- .../Controllers/Generic/SettingsController.cs | 14 +++---- .../Haircut/BrusherProfileController.cs | 3 +- Yavsc/Services/BillingService.cs | 40 +++++++------------ 4 files changed, 24 insertions(+), 36 deletions(-) diff --git a/Yavsc/Controllers/FormationSettingsController.cs b/Yavsc/Controllers/FormationSettingsController.cs index 305d7469..7df2a455 100644 --- a/Yavsc/Controllers/FormationSettingsController.cs +++ b/Yavsc/Controllers/FormationSettingsController.cs @@ -1,14 +1,13 @@ using Yavsc.Controllers.Generic; using Yavsc.Models; using Yavsc.Models.Workflow.Profiles; -using Yavsc.Services; namespace Yavsc.Controllers { public class FormationSettingsController : SettingsController { - public FormationSettingsController(ApplicationDbContext context, IBillingService billing) : base(context, billing) + public FormationSettingsController(ApplicationDbContext context) : base(context) { } diff --git a/Yavsc/Controllers/Generic/SettingsController.cs b/Yavsc/Controllers/Generic/SettingsController.cs index 151eb121..5ac9b189 100644 --- a/Yavsc/Controllers/Generic/SettingsController.cs +++ b/Yavsc/Controllers/Generic/SettingsController.cs @@ -6,29 +6,29 @@ using Microsoft.Data.Entity; namespace Yavsc.Controllers.Generic { + using System.Linq; using Models; - using Yavsc.Services; [Authorize] public abstract class SettingsController : Controller where TSettings : class, ISpecializationSettings, new() { protected ApplicationDbContext _context; - IBillingService billing; DbSet dbSet=null; protected string activityCode=null; protected DbSet Settings { get { - if (dbSet == null) Task.Run( async () => { - dbSet = (DbSet) await billing.GetPerformersSettingsAsync(activityCode); - }); + if (dbSet == null) { + dbSet = (DbSet) Startup.UserSettings.Single(s=>s.Name == typeof(TSettings).Name).GetValue(_context); + } + + return dbSet; } } - public SettingsController(ApplicationDbContext context, IBillingService billing) + public SettingsController(ApplicationDbContext context) { _context = context; - this.billing = billing; } public async Task Index() diff --git a/Yavsc/Controllers/Haircut/BrusherProfileController.cs b/Yavsc/Controllers/Haircut/BrusherProfileController.cs index d92b549c..02280412 100644 --- a/Yavsc/Controllers/Haircut/BrusherProfileController.cs +++ b/Yavsc/Controllers/Haircut/BrusherProfileController.cs @@ -2,7 +2,6 @@ using Yavsc.Models; using Yavsc.Models.Haircut; using Microsoft.AspNet.Authorization; using Yavsc.Controllers.Generic; -using Yavsc.Services; namespace Yavsc.Controllers { @@ -10,7 +9,7 @@ namespace Yavsc.Controllers public class BrusherProfileController : SettingsController { - public BrusherProfileController(ApplicationDbContext context, IBillingService billing) : base(context, billing) + public BrusherProfileController(ApplicationDbContext context) : base(context) { } diff --git a/Yavsc/Services/BillingService.cs b/Yavsc/Services/BillingService.cs index ff3ed200..78d1b2d5 100644 --- a/Yavsc/Services/BillingService.cs +++ b/Yavsc/Services/BillingService.cs @@ -1,5 +1,3 @@ - -using System; using System.Linq; using System.Threading.Tasks; using Microsoft.Data.Entity; @@ -20,24 +18,6 @@ namespace Yavsc.Services logger = loggerFactory.CreateLogger(); DbContext = dbContext; } - public async Task> 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) dbSetPropInfo.GetValue(DbContext); - } public async Task GetBillAsync(string billingCode, long queryId) { @@ -48,14 +28,24 @@ namespace Yavsc.Services public async Task 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> GetPerformersSettingsAsync(string activityCode) + public async Task> 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) dbSetPropInfo.GetValue(DbContext); + } } } \ No newline at end of file