restore l'edition du profile

This commit is contained in:
2017-06-08 22:45:34 +02:00
parent 15d050c8f9
commit c7f26fb636
4 changed files with 24 additions and 36 deletions

View File

@ -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<FormationSettings>
{
public FormationSettingsController(ApplicationDbContext context, IBillingService billing) : base(context, billing)
public FormationSettingsController(ApplicationDbContext context) : base(context)
{
}

View File

@ -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<TSettings> : Controller where TSettings : class, ISpecializationSettings, new()
{
protected ApplicationDbContext _context;
IBillingService billing;
DbSet<TSettings> dbSet=null;
protected string activityCode=null;
protected DbSet<TSettings> Settings { get {
if (dbSet == null) Task.Run( async () => {
dbSet = (DbSet<TSettings>) await billing.GetPerformersSettingsAsync(activityCode);
});
if (dbSet == null) {
dbSet = (DbSet<TSettings>) 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<IActionResult> Index()

View File

@ -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<BrusherProfile>
{
public BrusherProfileController(ApplicationDbContext context, IBillingService billing) : base(context, billing)
public BrusherProfileController(ApplicationDbContext context) : base(context)
{
}

View File

@ -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<BillingService>();
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)
{
@ -48,14 +28,24 @@ namespace Yavsc.Services
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);
}
}
}