ValidateProfiles gemacht, Link zu Profiles wenn Jahrgang und fachrichtung fehlt und bei save wieder zurück zum Event gemacht
This commit is contained in:
@ -1,12 +1,18 @@
|
|||||||
@using Oqtane.Modules.Controls
|
@using Oqtane
|
||||||
|
@using Oqtane.Modules.Controls
|
||||||
@using SZUAbsolventenverein.Module.EventRegistration.Services
|
@using SZUAbsolventenverein.Module.EventRegistration.Services
|
||||||
@using SZUAbsolventenverein.Module.EventRegistration.Models
|
@using SZUAbsolventenverein.Module.EventRegistration.Models
|
||||||
|
@using System.Text.RegularExpressions
|
||||||
|
|
||||||
@namespace SZUAbsolventenverein.Module.EventRegistration
|
@namespace SZUAbsolventenverein.Module.EventRegistration
|
||||||
@inherits ModuleBase
|
@inherits ModuleBase
|
||||||
@inject IEventRegistrationService EventRegistrationService
|
@inject IEventRegistrationService EventRegistrationService
|
||||||
@inject NavigationManager NavigationManager
|
@inject NavigationManager NavigationManager
|
||||||
@inject IStringLocalizer<Edit> Localizer
|
@inject IStringLocalizer<Edit> Localizer
|
||||||
|
@inject IStringLocalizer<SharedResources> SharedLocalizer
|
||||||
|
@inject IUserService UserService
|
||||||
|
@inject IProfileService ProfileService
|
||||||
|
@inject ISettingService SettingService
|
||||||
|
|
||||||
<h3>Anmeldung zum Event</h3>
|
<h3>Anmeldung zum Event</h3>
|
||||||
|
|
||||||
@ -71,6 +77,9 @@
|
|||||||
private Response _response;
|
private Response _response;
|
||||||
private bool? Status;
|
private bool? Status;
|
||||||
|
|
||||||
|
private List<Profile> _profiles = new List<Profile>();
|
||||||
|
private Dictionary<string, string> _settings;
|
||||||
|
|
||||||
private async Task SendResponse(bool response)
|
private async Task SendResponse(bool response)
|
||||||
{
|
{
|
||||||
if(_response == null)
|
if(_response == null)
|
||||||
@ -90,19 +99,46 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async void Zusage()
|
private async void Zusage()
|
||||||
|
{
|
||||||
|
if(ValidateProfiles())
|
||||||
{
|
{
|
||||||
await SendResponse(true);
|
await SendResponse(true);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
var currentPathAndQuery = new Uri(NavigationManager.Uri).PathAndQuery;
|
||||||
|
var encodedReturnUrl = Uri.EscapeDataString(currentPathAndQuery);
|
||||||
|
var link = $"/profile?tab=Profile&returnurl={encodedReturnUrl}";
|
||||||
|
|
||||||
|
AddModuleMessage(string.Format(SharedLocalizer["ProfileRequired"], $"Vervollständige hier dein Profil mit deinem Jahrgang und deiner Fachrichtung: <a href=\"{link}\">Link zum Profil</a>"), MessageType.Warning);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void Absage()
|
private async void Absage()
|
||||||
|
{
|
||||||
|
if(ValidateProfiles())
|
||||||
{
|
{
|
||||||
await SendResponse(false);
|
await SendResponse(false);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
var currentPathAndQuery = new Uri(NavigationManager.Uri).PathAndQuery;
|
||||||
|
var encodedReturnUrl = Uri.EscapeDataString(currentPathAndQuery);
|
||||||
|
var link = $"/profile?tab=profile&returnurl={encodedReturnUrl}";
|
||||||
|
|
||||||
|
AddModuleMessage(string.Format(SharedLocalizer["ProfileRequired"], $"Vervollständige hier dein Profil mit deinem Jahrgang und deiner Fachrichtung: {link}"), MessageType.Warning);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
_profiles = await ProfileService.GetProfilesAsync(PageState.Site.SiteId);
|
||||||
|
var user = await UserService.GetUserAsync(PageState.User.UserId, PageState.Site.SiteId);
|
||||||
|
if (user != null)
|
||||||
|
{
|
||||||
|
_settings = user.Settings;
|
||||||
|
}
|
||||||
|
|
||||||
_id = Int32.Parse(PageState.QueryString["id"]);
|
_id = Int32.Parse(PageState.QueryString["id"]);
|
||||||
|
|
||||||
Event currentEvent;
|
Event currentEvent;
|
||||||
@ -128,4 +164,46 @@
|
|||||||
AddModuleMessage(Localizer["Message.LoadError"], MessageType.Error);
|
AddModuleMessage(Localizer["Message.LoadError"], MessageType.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private bool ValidateProfiles()
|
||||||
|
{
|
||||||
|
foreach (Profile profile in _profiles)
|
||||||
|
{
|
||||||
|
var value = GetProfileValue(profile.Name, string.Empty);
|
||||||
|
if (string.IsNullOrEmpty(value) && !string.IsNullOrEmpty(profile.DefaultValue))
|
||||||
|
{
|
||||||
|
_settings = SettingService.SetSetting(_settings, profile.Name, profile.DefaultValue);
|
||||||
|
}
|
||||||
|
if (!profile.IsPrivate || UserSecurity.IsAuthorized(PageState.User, RoleNames.Admin))
|
||||||
|
{
|
||||||
|
if (profile.IsRequired && string.IsNullOrEmpty(value))
|
||||||
|
{
|
||||||
|
AddModuleMessage(string.Format(SharedLocalizer["ProfileRequired"], profile.Title), MessageType.Warning);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(profile.Validation))
|
||||||
|
{
|
||||||
|
Regex regex = new Regex(profile.Validation);
|
||||||
|
bool valid = regex.Match(value).Success;
|
||||||
|
if (!valid)
|
||||||
|
{
|
||||||
|
AddModuleMessage(string.Format(SharedLocalizer["ProfileInvalid"], profile.Title), MessageType.Warning);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetProfileValue(string SettingName, string DefaultValue)
|
||||||
|
{
|
||||||
|
string value = SettingService.GetSetting(_settings, SettingName, DefaultValue);
|
||||||
|
if (value.Contains("]"))
|
||||||
|
{
|
||||||
|
value = value.Substring(value.IndexOf("]") + 1);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user