User settings
This commit is contained in:
@ -22,9 +22,9 @@ namespace Yavsc.ApiControllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("profiles/{actCode}")]
|
[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")]
|
[HttpPost("query/reject")]
|
||||||
@ -39,7 +39,8 @@ namespace Yavsc.ApiControllers
|
|||||||
dbContext.SaveChanges();
|
dbContext.SaveChanges();
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
[HttpPost("query/reject")]
|
|
||||||
|
[HttpPost("query/reject")]
|
||||||
public IActionResult AcceptQuery(string billingCode, long queryId)
|
public IActionResult AcceptQuery(string billingCode, long queryId)
|
||||||
{
|
{
|
||||||
if (billingCode == null) return BadRequest("billingCode");
|
if (billingCode == null) return BadRequest("billingCode");
|
||||||
|
@ -57,9 +57,9 @@ namespace Yavsc.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("doing/{id}"),AllowAnonymous]
|
[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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,20 +28,13 @@ namespace Yavsc.Services
|
|||||||
/// <returns>La facture</returns>
|
/// <returns>La facture</returns>
|
||||||
Task<IDecidableQuery> GetBillAsync(string billingCode, long queryId);
|
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>
|
/// <summary>
|
||||||
/// Perfomer settings for the specified performer in the activity
|
/// Perfomer settings for the specified performer in the activity
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="activityCode">activityCode</param>
|
/// <param name="activityCode">activityCode</param>
|
||||||
/// <param name="userId">performer uid</param>
|
/// <param name="userId">performer uid</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<ISpecializationSettings> GetPerformerSettingsAsync(string activityCode, string userId);
|
Task<IUserSettings> GetPerformersSettingsAsync(string activityCode, string userId);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
namespace Yavsc
|
namespace Yavsc
|
||||||
{
|
{
|
||||||
public interface ISpecializationSettings
|
public interface IUserSettings
|
||||||
{
|
{
|
||||||
string UserId { get ; set ; }
|
string UserId { get ; set ; }
|
||||||
}
|
}
|
||||||
|
@ -11,22 +11,23 @@ namespace Yavsc.Helpers
|
|||||||
|
|
||||||
public static class WorkflowHelpers
|
public static class WorkflowHelpers
|
||||||
{
|
{
|
||||||
public static List<PerformerProfileViewModel> ListPerformers(this ApplicationDbContext context,
|
public static async Task<List<PerformerProfileViewModel>> ListPerformersAsync(this ApplicationDbContext context,
|
||||||
IBillingService billing,
|
IBillingService billing,
|
||||||
string actCode)
|
string actCode)
|
||||||
{
|
{
|
||||||
var settings = billing.GetPerformersSettingsAsync(actCode).Result?.ToArray();
|
|
||||||
|
|
||||||
var actors = context.Performers
|
var actors = context.Performers
|
||||||
.Include(p=>p.Activity)
|
.Include(p=>p.Activity)
|
||||||
.Include(p=>p.Performer)
|
.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 )
|
.Where(p => p.Active && p.Activity.Any(u=>u.DoesCode==actCode)).OrderBy( x => x.Rate )
|
||||||
.ToArray();
|
.ToArray();
|
||||||
List<PerformerProfileViewModel> result = new List<PerformerProfileViewModel> ();
|
|
||||||
result.AddRange(
|
List<PerformerProfileViewModel> result = new ();
|
||||||
actors.Select(a=> new PerformerProfileViewModel(a, actCode, settings?.FirstOrDefault(s => s.UserId == a.PerformerId))));
|
foreach (var a in actors)
|
||||||
|
{
|
||||||
|
var settings = await billing.GetPerformersSettingsAsync(actCode, a.PerformerId);
|
||||||
|
result.Add(new PerformerProfileViewModel(a, actCode,settings));
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ namespace Yavsc.Models.Haircut
|
|||||||
using Relationship;
|
using Relationship;
|
||||||
using Calendar;
|
using Calendar;
|
||||||
|
|
||||||
public class BrusherProfile : ISpecializationSettings
|
public class BrusherProfile : IUserSettings
|
||||||
{
|
{
|
||||||
public BrusherProfile()
|
public BrusherProfile()
|
||||||
{
|
{
|
||||||
|
@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations;
|
|||||||
|
|
||||||
namespace Yavsc.Models.Musical.Profiles
|
namespace Yavsc.Models.Musical.Profiles
|
||||||
{
|
{
|
||||||
public class DjSettings : ISpecializationSettings
|
public class DjSettings : IUserSettings
|
||||||
{
|
{
|
||||||
|
|
||||||
public string SoundCloudId { get; set; }
|
public string SoundCloudId { get; set; }
|
||||||
|
@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations;
|
|||||||
|
|
||||||
namespace Yavsc.Models.Musical.Profiles
|
namespace Yavsc.Models.Musical.Profiles
|
||||||
{
|
{
|
||||||
public class GeneralSettings : ISpecializationSettings
|
public class GeneralSettings : IUserSettings
|
||||||
{
|
{
|
||||||
public virtual List<MusicalPreference> SoundColor { get; set; }
|
public virtual List<MusicalPreference> SoundColor { get; set; }
|
||||||
[Key]
|
[Key]
|
||||||
|
@ -3,7 +3,7 @@ using Yavsc.Models.Workflow;
|
|||||||
|
|
||||||
namespace Yavsc.Models.Musical.Profiles
|
namespace Yavsc.Models.Musical.Profiles
|
||||||
{
|
{
|
||||||
public class Instrumentation : ISpecializationSettings
|
public class Instrumentation : IUserSettings
|
||||||
{
|
{
|
||||||
public string UserId
|
public string UserId
|
||||||
{
|
{
|
||||||
|
@ -6,7 +6,7 @@ namespace Yavsc.Models.Workflow.Profiles
|
|||||||
{
|
{
|
||||||
using Models.Workflow;
|
using Models.Workflow;
|
||||||
using Yavsc;
|
using Yavsc;
|
||||||
public class FormationSettings : ISpecializationSettings
|
public class FormationSettings : IUserSettings
|
||||||
{
|
{
|
||||||
public virtual List<CoWorking> CoWorking { get; set; }
|
public virtual List<CoWorking> CoWorking { get; set; }
|
||||||
|
|
||||||
|
@ -8,15 +8,16 @@ namespace Yavsc.Services
|
|||||||
public class BillingService : IBillingService
|
public class BillingService : IBillingService
|
||||||
{
|
{
|
||||||
public ApplicationDbContext DbContext { get; private set; }
|
public ApplicationDbContext DbContext { get; private set; }
|
||||||
public static Dictionary<string,Func<ApplicationDbContext,long,IDecidableQuery>> Billing =
|
public static Dictionary<string, Func<ApplicationDbContext, long, IDecidableQuery>> Billing =
|
||||||
new Dictionary<string,Func<ApplicationDbContext,long,IDecidableQuery>> ();
|
new Dictionary<string, Func<ApplicationDbContext, long, IDecidableQuery>>();
|
||||||
public static List<PropertyInfo> UserSettings = new List<PropertyInfo>();
|
public static List<PropertyInfo> UserSettings = new List<PropertyInfo>();
|
||||||
|
|
||||||
public static Dictionary<string,string> GlobalBillingMap =
|
public static Dictionary<string, string> GlobalBillingMap =
|
||||||
new Dictionary<string,string>();
|
new Dictionary<string, string>();
|
||||||
|
|
||||||
public Dictionary<string,string> BillingMap {
|
public Dictionary<string, string> BillingMap
|
||||||
get { return GlobalBillingMap; }
|
{
|
||||||
|
get { return GlobalBillingMap; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public BillingService(ApplicationDbContext dbContext)
|
public BillingService(ApplicationDbContext dbContext)
|
||||||
@ -26,23 +27,30 @@ namespace Yavsc.Services
|
|||||||
|
|
||||||
public Task<IDecidableQuery> GetBillAsync(string billingCode, long queryId)
|
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 static IDecidableQuery GetBillable(ApplicationDbContext context, string billingCode, long queryId) => Billing[billingCode](context, queryId);
|
||||||
public async Task<ISpecializationSettings> GetPerformerSettingsAsync(string activityCode, string userId)
|
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>();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,6 @@ namespace Yavsc.ViewModels.Workflow
|
|||||||
{
|
{
|
||||||
public UserActivity Declaration { get; set; }
|
public UserActivity Declaration { get; set; }
|
||||||
public bool NeedsSettings { get; set; }
|
public bool NeedsSettings { get; set; }
|
||||||
public ISpecializationSettings Settings { get; set; }
|
public IUserSettings Settings { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -59,7 +59,7 @@ namespace Yavsc.Controllers
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
bool hasConfigurableSettings = (userActivity.Does.SettingsClassName != null);
|
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);
|
ViewBag.ProfileType = Config.ProfileTypes.Single(t=>t.FullName==userActivity.Does.SettingsClassName);
|
||||||
|
|
||||||
var gift = new UserActivityViewModel {
|
var gift = new UserActivityViewModel {
|
||||||
|
@ -9,6 +9,7 @@ namespace Yavsc.Controllers
|
|||||||
|
|
||||||
public FormationSettingsController(ApplicationDbContext context) : base(context)
|
public FormationSettingsController(ApplicationDbContext context) : base(context)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -53,26 +53,26 @@ namespace Yavsc.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public ActionResult Profiles(string id)
|
public async Task<ActionResult> Profiles(string id)
|
||||||
{
|
{
|
||||||
if (id == null)
|
if (id == null)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException("No Activity code");
|
throw new NotImplementedException("No Activity code");
|
||||||
}
|
}
|
||||||
ViewBag.Activity = _context.Activities.FirstOrDefault(a => a.Code == id);
|
ViewBag.Activity = await _context.Activities.FirstOrDefaultAsync(a => a.Code == id);
|
||||||
var result = _context.ListPerformers(_billing, id);
|
var result = await _context.ListPerformersAsync(_billing, id);
|
||||||
return View(result);
|
return View(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public ActionResult HairCut(string id)
|
public async Task <ActionResult> HairCut(string id)
|
||||||
{
|
{
|
||||||
if (id == null)
|
if (id == null)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException("No Activity code");
|
throw new NotImplementedException("No Activity code");
|
||||||
}
|
}
|
||||||
ViewBag.Activity = _context.Activities.FirstOrDefault(a => a.Code == id);
|
ViewBag.Activity = await _context.Activities.FirstOrDefaultAsync(a => a.Code == id);
|
||||||
var result = _context.ListPerformers(_billing, id);
|
var result = await _context.ListPerformersAsync(_billing, id);
|
||||||
return View(result);
|
return View(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ namespace Yavsc.Controllers.Generic
|
|||||||
using Yavsc.Services;
|
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, IUserSettings, new()
|
||||||
{
|
{
|
||||||
protected ApplicationDbContext _context;
|
protected ApplicationDbContext _context;
|
||||||
DbSet<TSettings> dbSet=null;
|
DbSet<TSettings> dbSet=null;
|
||||||
@ -21,11 +21,17 @@ namespace Yavsc.Controllers.Generic
|
|||||||
if (dbSet == null) {
|
if (dbSet == null) {
|
||||||
dbSet = (DbSet<TSettings>) BillingService.UserSettings.Single(s=>s.Name == typeof(TSettings).Name).GetValue(_context);
|
dbSet = (DbSet<TSettings>) BillingService.UserSettings.Single(s=>s.Name == typeof(TSettings).Name).GetValue(_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return dbSet;
|
return dbSet;
|
||||||
} }
|
} }
|
||||||
|
|
||||||
|
virtual protected async Task<TSettings> GetSettingsAsync(
|
||||||
|
string userId
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return await Settings.SingleOrDefaultAsync(p=>p.UserId == userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public SettingsController(ApplicationDbContext context)
|
public SettingsController(ApplicationDbContext context)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
@ -33,8 +39,7 @@ namespace Yavsc.Controllers.Generic
|
|||||||
|
|
||||||
public async Task<IActionResult> Index()
|
public async Task<IActionResult> Index()
|
||||||
{
|
{
|
||||||
var existing = await this.Settings.SingleOrDefaultAsync(p=>p.UserId == User.GetUserId());
|
return View(await GetSettingsAsync(User.GetUserId()));
|
||||||
return View(existing);
|
|
||||||
}
|
}
|
||||||
// GET: BrusherProfile/Details/5
|
// GET: BrusherProfile/Details/5
|
||||||
public async Task<IActionResult> Details(string id)
|
public async Task<IActionResult> Details(string id)
|
||||||
@ -44,7 +49,7 @@ namespace Yavsc.Controllers.Generic
|
|||||||
id = User.GetUserId();
|
id = User.GetUserId();
|
||||||
}
|
}
|
||||||
|
|
||||||
var profile = await Settings.SingleAsync(m => m.UserId == id);
|
var profile = await GetSettingsAsync(id);
|
||||||
if (profile == null)
|
if (profile == null)
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound();
|
||||||
@ -68,7 +73,7 @@ namespace Yavsc.Controllers.Generic
|
|||||||
id = User.GetUserId();
|
id = User.GetUserId();
|
||||||
}
|
}
|
||||||
|
|
||||||
TSettings setting = await Settings.SingleOrDefaultAsync(m => m.UserId == id);
|
TSettings setting = await GetSettingsAsync(id);
|
||||||
if (setting == null)
|
if (setting == null)
|
||||||
{
|
{
|
||||||
setting = new TSettings { };
|
setting = new TSettings { };
|
||||||
@ -87,13 +92,13 @@ namespace Yavsc.Controllers.Generic
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
var brusherProfile = await Settings.SingleAsync(m => m.UserId == id);
|
var profile = await GetSettingsAsync(id);
|
||||||
if (brusherProfile == null)
|
if (profile == null)
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
return View(brusherProfile);
|
return View(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST: FormationSettings/Create
|
// POST: FormationSettings/Create
|
||||||
@ -135,8 +140,8 @@ namespace Yavsc.Controllers.Generic
|
|||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
public async Task<IActionResult> DeleteConfirmed(string id)
|
public async Task<IActionResult> DeleteConfirmed(string id)
|
||||||
{
|
{
|
||||||
TSettings formationSettings = await Settings.SingleAsync(m => m.UserId == id);
|
TSettings userSettings = await GetSettingsAsync(id);
|
||||||
Settings.Remove(formationSettings);
|
Settings.Remove(userSettings);
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user