mib
This commit is contained in:
@ -2,7 +2,7 @@ using System;
|
|||||||
|
|
||||||
namespace Yavsc.Attributes
|
namespace Yavsc.Attributes
|
||||||
{
|
{
|
||||||
public class ActivitySettingAttribute : Attribute
|
public class ActivitySettingsAttribute : Attribute
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
@ -10,6 +10,7 @@ namespace Yavsc.Controllers
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Models;
|
using Models;
|
||||||
using Models.Workflow;
|
using Models.Workflow;
|
||||||
|
using Yavsc.Exceptions;
|
||||||
using Yavsc.ViewModels.Workflow;
|
using Yavsc.ViewModels.Workflow;
|
||||||
|
|
||||||
[Authorize]
|
[Authorize]
|
||||||
@ -40,6 +41,7 @@ namespace Yavsc.Controllers
|
|||||||
// GET: Do/Details/5
|
// GET: Do/Details/5
|
||||||
public IActionResult Details(string id, string activityCode)
|
public IActionResult Details(string id, string activityCode)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (id == null || activityCode == null)
|
if (id == null || activityCode == null)
|
||||||
{
|
{
|
||||||
return HttpNotFound();
|
return HttpNotFound();
|
||||||
@ -51,16 +53,25 @@ namespace Yavsc.Controllers
|
|||||||
{
|
{
|
||||||
return HttpNotFound();
|
return HttpNotFound();
|
||||||
}
|
}
|
||||||
ViewBag.HasConfigurableSettings = (userActivity.Does.SettingsClassName != null);
|
|
||||||
if (ViewBag.HasConfigurableSettings)
|
bool hasConfigurableSettings = (userActivity.Does.SettingsClassName != null);
|
||||||
ViewBag.SettingsControllerName = Startup.ProfileTypes.Single(t=>t.FullName==userActivity.Does.SettingsClassName).Name;
|
if (hasConfigurableSettings) {
|
||||||
_logger.LogWarning(userActivity.Does.SettingsClassName);
|
|
||||||
var dbset = _context.GetDbSet(userActivity.Does.SettingsClassName);
|
ViewBag.ProfileType = Startup.ProfileTypes.Single(t=>t.FullName==userActivity.Does.SettingsClassName);
|
||||||
_logger.LogWarning(dbset.Any(i=>i.UserId == id).ToString());
|
|
||||||
return View(new UserActivityViewModel {
|
|
||||||
|
var dbset = _context.GetDbSet(userActivity.Does.SettingsClassName);
|
||||||
|
if (dbset == null) throw new InvalidWorkflowModelException($"pas de db set pour {userActivity.Does.SettingsClassName}, vous avez peut-être besoin de décorer votre propriété avec l'attribut [ActivitySettings]");
|
||||||
|
return View(new UserActivityViewModel {
|
||||||
Declaration = userActivity,
|
Declaration = userActivity,
|
||||||
HasSettings = dbset?.Any(ua=>ua.UserId==id) ?? false,
|
HasSettings = dbset?.Any(ua=>ua.UserId==id) ?? false,
|
||||||
NeedsSettings = userActivity.Does.SettingsClassName != null
|
NeedsSettings = hasConfigurableSettings
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
return View(new UserActivityViewModel {
|
||||||
|
Declaration = userActivity,
|
||||||
|
HasSettings = false,
|
||||||
|
NeedsSettings = hasConfigurableSettings
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
Yavsc/Exceptions/InvalidActivityModelException.cs
Normal file
15
Yavsc/Exceptions/InvalidActivityModelException.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
namespace Yavsc.Exceptions
|
||||||
|
{
|
||||||
|
public class InvalidWorkflowModelException : Exception
|
||||||
|
{
|
||||||
|
public InvalidWorkflowModelException(string descr) : base(descr)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public InvalidWorkflowModelException(string descr, Exception inner) : base(descr,inner)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -229,8 +229,14 @@ namespace Yavsc.Models
|
|||||||
|
|
||||||
public DbSet<Instrument> Instrument { get; set; }
|
public DbSet<Instrument> Instrument { get; set; }
|
||||||
public DbSet<DjSettings> DjSettings { get; set; }
|
public DbSet<DjSettings> DjSettings { get; set; }
|
||||||
|
|
||||||
|
[ActivitySettings]
|
||||||
public DbSet<Instrumentation> Instrumentation { get; set; }
|
public DbSet<Instrumentation> Instrumentation { get; set; }
|
||||||
|
|
||||||
|
[ActivitySettings]
|
||||||
public DbSet<FormationSettings> FormationSettings { get; set; }
|
public DbSet<FormationSettings> FormationSettings { get; set; }
|
||||||
|
|
||||||
|
[ActivitySettings]
|
||||||
public DbSet<GeneralSettings> GeneralSettings { get; set; }
|
public DbSet<GeneralSettings> GeneralSettings { get; set; }
|
||||||
public DbSet<CoWorking> WorkflowProviders { get; set; }
|
public DbSet<CoWorking> WorkflowProviders { get; set; }
|
||||||
|
|
||||||
@ -282,7 +288,7 @@ namespace Yavsc.Models
|
|||||||
|
|
||||||
public DbSet<HairPrestation> HairPrestation { get; set; }
|
public DbSet<HairPrestation> HairPrestation { get; set; }
|
||||||
|
|
||||||
[ActivitySetting]
|
[ActivitySettings]
|
||||||
public DbSet<BrusherProfile> BrusherProfile { get; set; }
|
public DbSet<BrusherProfile> BrusherProfile { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
@ -398,7 +398,7 @@
|
|||||||
{0} devrait être disponible pour ce rendez-vous</value></data>
|
{0} devrait être disponible pour ce rendez-vous</value></data>
|
||||||
<data name="Yavsc.Models.Musical.Profiles.Instrumentation"><value>Paramètres musicien (l'instrument)</value></data>
|
<data name="Yavsc.Models.Musical.Profiles.Instrumentation"><value>Paramètres musicien (l'instrument)</value></data>
|
||||||
<data name="Yavsc.Models.Musical.Profiles.DjSettings"><value>Paramètres Dj (le compte SoundCloud.com)</value></data>
|
<data name="Yavsc.Models.Musical.Profiles.DjSettings"><value>Paramètres Dj (le compte SoundCloud.com)</value></data>
|
||||||
<data name="Yavsc.Models.Musical.Profiles.FormationSettings"><value>Paramètres formation (les partenaires)</value></data>
|
<data name="Yavsc.Models.Workflow.Profiles.FormationSettings"><value>Paramètres formation (les partenaires)</value></data>
|
||||||
<data name="Yavsc.Models.Musical.Profiles.GeneralSettings"><value>Paramètres généraux (visibilité et présentation)</value></data>
|
<data name="Yavsc.Models.Musical.Profiles.GeneralSettings"><value>Paramètres généraux (visibilité et présentation)</value></data>
|
||||||
<data name="Yavsc.Models.Haircut.BrusherProfile"><value>Paramètres coiffeur: tarifs, disponibilité</value></data>
|
<data name="Yavsc.Models.Haircut.BrusherProfile"><value>Paramètres coiffeur: tarifs, disponibilité</value></data>
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.AspNet.Builder;
|
using Microsoft.AspNet.Builder;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Yavsc.Exceptions;
|
||||||
using Yavsc.Models;
|
using Yavsc.Models;
|
||||||
using YavscLib;
|
using YavscLib;
|
||||||
|
|
||||||
@ -38,22 +39,23 @@ namespace Yavsc
|
|||||||
}
|
}
|
||||||
foreach (var propinfo in typeof(ApplicationDbContext).GetProperties()) {
|
foreach (var propinfo in typeof(ApplicationDbContext).GetProperties()) {
|
||||||
foreach (var attr in propinfo.CustomAttributes) {
|
foreach (var attr in propinfo.CustomAttributes) {
|
||||||
if (attr.AttributeType.FullName == "Yavsc.Attributes.ActivitySettingAttribute") {
|
if (attr.AttributeType == typeof(Yavsc.Attributes.ActivitySettingsAttribute)) {
|
||||||
// bingo
|
// bingo
|
||||||
if (typeof(IQueryable<ISpecializationSettings>).IsAssignableFrom(propinfo.PropertyType))
|
if (typeof(IQueryable<ISpecializationSettings>).IsAssignableFrom(propinfo.PropertyType))
|
||||||
{
|
{
|
||||||
logger.LogInformation($"Paramêtres utilisateur déclaré: {propinfo.Name}");
|
logger.LogInformation($"Paramêtres utilisateur déclaré: {propinfo.Name}");
|
||||||
UserSettings.Add(propinfo);
|
UserSettings.Add(propinfo);
|
||||||
|
|
||||||
} else
|
} else
|
||||||
// Design time error
|
// Design time error
|
||||||
{
|
{
|
||||||
logger.LogCritical(
|
var msg =
|
||||||
$@"la propriété {propinfo.Name} du contexte de la
|
$@"La propriété {propinfo.Name} du contexte de la
|
||||||
base de donnée déclare être un refuge de paramêtre utilisateur
|
base de donnée porte l'attribut [ActivitySetting],
|
||||||
du workflow, mais l'implemente pas l'interface IQueryable<ISpecializationSettings>,
|
mais n'implemente pas l'interface IQueryable<ISpecializationSettings>
|
||||||
Elle est du type {propinfo.MemberType.GetType()}");
|
({propinfo.MemberType.GetType()})";
|
||||||
throw new NotSupportedException("invalid ActivitySettingAttribute on property from dbcontext");
|
logger.LogCritical(msg);
|
||||||
|
|
||||||
|
throw new InvalidWorkflowModelException(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,13 +11,13 @@
|
|||||||
<hr />
|
<hr />
|
||||||
<dl class="dl-horizontal">
|
<dl class="dl-horizontal">
|
||||||
<dt>@SR["Activity"]</dt>
|
<dt>@SR["Activity"]</dt>
|
||||||
<dd> @Html.DisplayFor(m=>m.Declaration.Does)
|
<dd>@Html.DisplayFor(m=>m.Declaration.Does)
|
||||||
@if (ViewBag.HasConfigurableSettings) {
|
@if (Model.NeedsSettings) {
|
||||||
<a asp-controller="@ViewBag.SettingsControllerName" asp-action="Index" class="btn btn-default">
|
<a asp-controller="@ViewBag.ProfileType.Name" asp-action="Index" class="btn btn-default">
|
||||||
@SR[Model.Declaration.Does.SettingsClassName]
|
@SR[Model.Declaration.Does.SettingsClassName]
|
||||||
|
@if (!Model.HasSettings) {
|
||||||
NeedsSettings: @Model.NeedsSettings
|
<span class="badge">Non renseigné: Cliquez vite<br/> ici pour positionner les<br/> paramêtres de cette activité</span>
|
||||||
HasSettings: @Model.HasSettings
|
}
|
||||||
|
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user