User settings

This commit is contained in:
Paul Schneider
2025-02-24 23:29:48 +00:00
parent 7524e6323f
commit 76626f3ac4
16 changed files with 76 additions and 67 deletions

View File

@ -22,9 +22,9 @@ namespace Yavsc.ApiControllers
}
[HttpGet("profiles/{actCode}")]
IEnumerable<PerformerProfileViewModel> Profiles(string actCode)
async Task <IEnumerable<PerformerProfileViewModel>> Profiles(string actCode)
{
return dbContext.ListPerformers(billing, actCode);
return await dbContext.ListPerformersAsync(billing, actCode);
}
[HttpPost("query/reject")]
@ -39,7 +39,8 @@ namespace Yavsc.ApiControllers
dbContext.SaveChanges();
return Ok();
}
[HttpPost("query/reject")]
[HttpPost("query/reject")]
public IActionResult AcceptQuery(string billingCode, long queryId)
{
if (billingCode == null) return BadRequest("billingCode");

View File

@ -57,9 +57,9 @@ namespace Yavsc.Controllers
}
[HttpGet("doing/{id}"),AllowAnonymous]
public IActionResult ListPerformers(string id)
public async Task<IActionResult> ListPerformers(string id)
{
return Ok(dbContext.ListPerformers(billing, id));
return Ok(await dbContext.ListPerformersAsync(billing, id));
}
}
}

View File

@ -28,20 +28,13 @@ namespace Yavsc.Services
/// <returns>La facture</returns>
Task<IDecidableQuery> GetBillAsync(string billingCode, long queryId);
/// <summary>
/// All performer setting in this activity
/// </summary>
/// <param name="activityCode"></param>
/// <returns></returns>
Task<IEnumerable<ISpecializationSettings>> GetPerformersSettingsAsync(string activityCode);
/// <summary>
/// Perfomer settings for the specified performer in the activity
/// </summary>
/// <param name="activityCode">activityCode</param>
/// <param name="userId">performer uid</param>
/// <returns></returns>
Task<ISpecializationSettings> GetPerformerSettingsAsync(string activityCode, string userId);
Task<IUserSettings> GetPerformersSettingsAsync(string activityCode, string userId);
}
}

View File

@ -1,6 +1,6 @@
namespace Yavsc
{
public interface ISpecializationSettings
public interface IUserSettings
{
string UserId { get ; set ; }
}

View File

@ -11,22 +11,23 @@ namespace Yavsc.Helpers
public static class WorkflowHelpers
{
public static List<PerformerProfileViewModel> ListPerformers(this ApplicationDbContext context,
public static async Task<List<PerformerProfileViewModel>> ListPerformersAsync(this ApplicationDbContext context,
IBillingService billing,
string actCode)
{
var settings = billing.GetPerformersSettingsAsync(actCode).Result?.ToArray();
var actors = context.Performers
.Include(p=>p.Activity)
.Include(p=>p.Performer)
.Include(p=>p.Performer.Posts)
.Include(p=>p.Performer.DeviceDeclaration)
.Where(p => p.Active && p.Activity.Any(u=>u.DoesCode==actCode)).OrderBy( x => x.Rate )
.ToArray();
List<PerformerProfileViewModel> result = new List<PerformerProfileViewModel> ();
result.AddRange(
actors.Select(a=> new PerformerProfileViewModel(a, actCode, settings?.FirstOrDefault(s => s.UserId == a.PerformerId))));
List<PerformerProfileViewModel> result = new ();
foreach (var a in actors)
{
var settings = await billing.GetPerformersSettingsAsync(actCode, a.PerformerId);
result.Add(new PerformerProfileViewModel(a, actCode,settings));
}
return result;
}

View File

@ -31,7 +31,7 @@ namespace Yavsc.Models.Haircut
using Relationship;
using Calendar;
public class BrusherProfile : ISpecializationSettings
public class BrusherProfile : IUserSettings
{
public BrusherProfile()
{

View File

@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations;
namespace Yavsc.Models.Musical.Profiles
{
public class DjSettings : ISpecializationSettings
public class DjSettings : IUserSettings
{
public string SoundCloudId { get; set; }

View File

@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations;
namespace Yavsc.Models.Musical.Profiles
{
public class GeneralSettings : ISpecializationSettings
public class GeneralSettings : IUserSettings
{
public virtual List<MusicalPreference> SoundColor { get; set; }
[Key]

View File

@ -3,7 +3,7 @@ using Yavsc.Models.Workflow;
namespace Yavsc.Models.Musical.Profiles
{
public class Instrumentation : ISpecializationSettings
public class Instrumentation : IUserSettings
{
public string UserId
{

View File

@ -6,7 +6,7 @@ namespace Yavsc.Models.Workflow.Profiles
{
using Models.Workflow;
using Yavsc;
public class FormationSettings : ISpecializationSettings
public class FormationSettings : IUserSettings
{
public virtual List<CoWorking> CoWorking { get; set; }

View File

@ -8,15 +8,16 @@ namespace Yavsc.Services
public class BillingService : IBillingService
{
public ApplicationDbContext DbContext { get; private set; }
public static Dictionary<string,Func<ApplicationDbContext,long,IDecidableQuery>> Billing =
new Dictionary<string,Func<ApplicationDbContext,long,IDecidableQuery>> ();
public static Dictionary<string, Func<ApplicationDbContext, long, IDecidableQuery>> Billing =
new Dictionary<string, Func<ApplicationDbContext, long, IDecidableQuery>>();
public static List<PropertyInfo> UserSettings = new List<PropertyInfo>();
public static Dictionary<string,string> GlobalBillingMap =
new Dictionary<string,string>();
public Dictionary<string,string> BillingMap {
get { return GlobalBillingMap; }
public static Dictionary<string, string> GlobalBillingMap =
new Dictionary<string, string>();
public Dictionary<string, string> BillingMap
{
get { return GlobalBillingMap; }
}
public BillingService(ApplicationDbContext dbContext)
@ -26,23 +27,30 @@ namespace Yavsc.Services
public Task<IDecidableQuery> GetBillAsync(string billingCode, long queryId)
{
return Task.FromResult(GetBillable(DbContext,billingCode,queryId));
return Task.FromResult(GetBillable(DbContext, billingCode, queryId));
}
public static IDecidableQuery GetBillable(ApplicationDbContext context, string billingCode, long queryId ) => Billing[billingCode](context, queryId);
public async Task<ISpecializationSettings> GetPerformerSettingsAsync(string activityCode, string userId)
public static IDecidableQuery GetBillable(ApplicationDbContext context, string billingCode, long queryId) => Billing[billingCode](context, queryId);
public async Task<IUserSettings> GetPerformersSettingsAsync(string activityCode, string userId)
{
return (await GetPerformersSettingsAsync(activityCode)).SingleOrDefault(s=> s.UserId == userId);
var activity = await DbContext.Activities.SingleAsync(a => a.Code == activityCode);
if (activity.SettingsClassName == null) return null;
var dbSetGetter =
UserSettings.SingleOrDefault(s => s.Name == activity.SettingsClassName);
if (dbSetGetter==null) return null;
var dbSet = dbSetGetter.GetValue(DbContext);
if (dbSet == null) return null;
if (dbSet is DbSet<IUserSettings> userSettings)
{
return userSettings.FirstOrDefault(s => s.UserId == userId);
}
return null;
}
public async Task<IEnumerable<ISpecializationSettings>> GetPerformersSettingsAsync(string activityCode)
{
var activity = await DbContext.Activities.SingleAsync(a=>a.Code == activityCode);
if (activity.SettingsClassName==null) return null;
return UserSettings.Where(s => s.PropertyType.GenericTypeArguments[0].FullName == activity.SettingsClassName)
.Cast<ISpecializationSettings>();
}
}
}

View File

@ -6,6 +6,6 @@ namespace Yavsc.ViewModels.Workflow
{
public UserActivity Declaration { get; set; }
public bool NeedsSettings { get; set; }
public ISpecializationSettings Settings { get; set; }
public IUserSettings Settings { get; set; }
}
}
}

View File

@ -59,7 +59,7 @@ namespace Yavsc.Controllers
return NotFound();
}
bool hasConfigurableSettings = (userActivity.Does.SettingsClassName != null);
var settings = await billing.GetPerformerSettingsAsync(activityCode,id);
var settings = await billing.GetPerformersSettingsAsync(activityCode, id);
ViewBag.ProfileType = Config.ProfileTypes.Single(t=>t.FullName==userActivity.Does.SettingsClassName);
var gift = new UserActivityViewModel {

View File

@ -9,6 +9,7 @@ namespace Yavsc.Controllers
public FormationSettingsController(ApplicationDbContext context) : base(context)
{
}
}

View File

@ -53,26 +53,26 @@ namespace Yavsc.Controllers
}
[AllowAnonymous]
public ActionResult Profiles(string id)
public async Task<ActionResult> Profiles(string id)
{
if (id == null)
{
throw new NotImplementedException("No Activity code");
}
ViewBag.Activity = _context.Activities.FirstOrDefault(a => a.Code == id);
var result = _context.ListPerformers(_billing, id);
ViewBag.Activity = await _context.Activities.FirstOrDefaultAsync(a => a.Code == id);
var result = await _context.ListPerformersAsync(_billing, id);
return View(result);
}
[AllowAnonymous]
public ActionResult HairCut(string id)
public async Task <ActionResult> HairCut(string id)
{
if (id == null)
{
throw new NotImplementedException("No Activity code");
}
ViewBag.Activity = _context.Activities.FirstOrDefault(a => a.Code == id);
var result = _context.ListPerformers(_billing, id);
ViewBag.Activity = await _context.Activities.FirstOrDefaultAsync(a => a.Code == id);
var result = await _context.ListPerformersAsync(_billing, id);
return View(result);
}

View File

@ -10,7 +10,7 @@ namespace Yavsc.Controllers.Generic
using Yavsc.Services;
[Authorize]
public abstract class SettingsController<TSettings> : Controller where TSettings : class, ISpecializationSettings, new()
public abstract class SettingsController<TSettings> : Controller where TSettings : class, IUserSettings, new()
{
protected ApplicationDbContext _context;
DbSet<TSettings> dbSet=null;
@ -21,11 +21,17 @@ namespace Yavsc.Controllers.Generic
if (dbSet == null) {
dbSet = (DbSet<TSettings>) BillingService.UserSettings.Single(s=>s.Name == typeof(TSettings).Name).GetValue(_context);
}
return dbSet;
} }
virtual protected async Task<TSettings> GetSettingsAsync(
string userId
)
{
return await Settings.SingleOrDefaultAsync(p=>p.UserId == userId);
}
public SettingsController(ApplicationDbContext context)
{
_context = context;
@ -33,8 +39,7 @@ namespace Yavsc.Controllers.Generic
public async Task<IActionResult> Index()
{
var existing = await this.Settings.SingleOrDefaultAsync(p=>p.UserId == User.GetUserId());
return View(existing);
return View(await GetSettingsAsync(User.GetUserId()));
}
// GET: BrusherProfile/Details/5
public async Task<IActionResult> Details(string id)
@ -44,7 +49,7 @@ namespace Yavsc.Controllers.Generic
id = User.GetUserId();
}
var profile = await Settings.SingleAsync(m => m.UserId == id);
var profile = await GetSettingsAsync(id);
if (profile == null)
{
return NotFound();
@ -68,7 +73,7 @@ namespace Yavsc.Controllers.Generic
id = User.GetUserId();
}
TSettings setting = await Settings.SingleOrDefaultAsync(m => m.UserId == id);
TSettings setting = await GetSettingsAsync(id);
if (setting == null)
{
setting = new TSettings { };
@ -87,13 +92,13 @@ namespace Yavsc.Controllers.Generic
return NotFound();
}
var brusherProfile = await Settings.SingleAsync(m => m.UserId == id);
if (brusherProfile == null)
var profile = await GetSettingsAsync(id);
if (profile == null)
{
return NotFound();
}
return View(brusherProfile);
return View(profile);
}
// POST: FormationSettings/Create
@ -135,8 +140,8 @@ namespace Yavsc.Controllers.Generic
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(string id)
{
TSettings formationSettings = await Settings.SingleAsync(m => m.UserId == id);
Settings.Remove(formationSettings);
TSettings userSettings = await GetSettingsAsync(id);
Settings.Remove(userSettings);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}