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