Serverseitig: 10 Benutzer Scoring Serverseiting reimplementiert
This commit is contained in:
@ -32,17 +32,17 @@
|
|||||||
@if (Status == true)
|
@if (Status == true)
|
||||||
{
|
{
|
||||||
<span class ="fontsizeInf">@Localizer["Zugesagt"]</span><br />
|
<span class ="fontsizeInf">@Localizer["Zugesagt"]</span><br />
|
||||||
<p><button class="btn btn-danger" @onclick="Absage">@Localizer["Absagen"]</button></p>
|
<p><button class="btn btn-danger" @onclick="Reject">@Localizer["Absagen"]</button></p>
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
<span class="fontsizeInf"> @Localizer["Abgesagt"]</span><br />
|
<span class="fontsizeInf"> @Localizer["Abgesagt"]</span><br />
|
||||||
<p><button class="btn btn-success" @onclick="Zusage">@Localizer["Zusagen"]</button></p>
|
<p><button class="btn btn-success" @onclick="Accept">@Localizer["Zusagen"]</button></p>
|
||||||
}
|
}
|
||||||
</p>
|
</p>
|
||||||
} else {
|
} else {
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<button class="btn btn-success" @onclick="Zusage">@Localizer["Zusagen"]</button>
|
<button class="btn btn-success" @onclick="Accept">@Localizer["Zusagen"]</button>
|
||||||
<button class="btn btn-danger" @onclick="Absage">@Localizer["Absagen"]</button>
|
<button class="btn btn-danger" @onclick="Reject">@Localizer["Absagen"]</button>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
@foreach (User u in _users)
|
@foreach (User u in _users)
|
||||||
@ -70,9 +70,6 @@
|
|||||||
new Resource { ResourceType = ResourceType.Stylesheet, Url = ModulePath() + "Module.css" }
|
new Resource { ResourceType = ResourceType.Stylesheet, Url = ModulePath() + "Module.css" }
|
||||||
};
|
};
|
||||||
|
|
||||||
// private ElementReference form;
|
|
||||||
// private bool validated = false;
|
|
||||||
|
|
||||||
private int _id;
|
private int _id;
|
||||||
private string _name;
|
private string _name;
|
||||||
private string _description;
|
private string _description;
|
||||||
@ -85,7 +82,7 @@
|
|||||||
private List<Profile> _profiles = new List<Profile>();
|
private List<Profile> _profiles = new List<Profile>();
|
||||||
private Dictionary<string, string> _settings;
|
private Dictionary<string, string> _settings;
|
||||||
|
|
||||||
private List<User> _users = new List<User>() {new User() {DisplayName = "Hello"}, new User() {DisplayName = "World"}};
|
private List<User> _users = new List<User>();
|
||||||
|
|
||||||
private async Task SendResponse(bool response)
|
private async Task SendResponse(bool response)
|
||||||
{
|
{
|
||||||
@ -114,12 +111,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void Zusage()
|
private async void Accept()
|
||||||
{
|
{
|
||||||
await SendResponse(true);
|
await SendResponse(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void Absage()
|
private async void Reject()
|
||||||
{
|
{
|
||||||
await SendResponse(false);
|
await SendResponse(false);
|
||||||
}
|
}
|
||||||
@ -128,6 +125,8 @@
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
_id = Int32.Parse(PageState.QueryString["id"]);
|
||||||
|
|
||||||
if(PageState.User != null) {
|
if(PageState.User != null) {
|
||||||
_profiles = await ProfileService.GetProfilesAsync(PageState.Site.SiteId);
|
_profiles = await ProfileService.GetProfilesAsync(PageState.Site.SiteId);
|
||||||
var user = await UserService.GetUserAsync(PageState.User.UserId, PageState.Site.SiteId);
|
var user = await UserService.GetUserAsync(PageState.User.UserId, PageState.Site.SiteId);
|
||||||
@ -135,10 +134,10 @@
|
|||||||
{
|
{
|
||||||
_settings = user.Settings;
|
_settings = user.Settings;
|
||||||
}
|
}
|
||||||
|
_users = await EventRegistrationService.GetRecommendedResponses(_id, ModuleState.ModuleId);
|
||||||
|
_users.ForEach(u => Console.WriteLine(u.UserId));
|
||||||
}
|
}
|
||||||
|
|
||||||
_id = Int32.Parse(PageState.QueryString["id"]);
|
|
||||||
|
|
||||||
Event currentEvent;
|
Event currentEvent;
|
||||||
Response rsvp;
|
Response rsvp;
|
||||||
(currentEvent, rsvp) = await EventRegistrationService.GetEventDetails(_id, ModuleState.ModuleId);
|
(currentEvent, rsvp) = await EventRegistrationService.GetEventDetails(_id, ModuleState.ModuleId);
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Numerics;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Oqtane.Enums;
|
using Oqtane.Enums;
|
||||||
@ -23,9 +25,10 @@ namespace SZUAbsolventenverein.Module.EventRegistration.Services
|
|||||||
private readonly IUserPermissions _userPermissions;
|
private readonly IUserPermissions _userPermissions;
|
||||||
private readonly ILogManager _logger;
|
private readonly ILogManager _logger;
|
||||||
private readonly IHttpContextAccessor _accessor;
|
private readonly IHttpContextAccessor _accessor;
|
||||||
|
private readonly ISettingRepository _settingRepository;
|
||||||
private readonly Alias _alias;
|
private readonly Alias _alias;
|
||||||
|
|
||||||
public ServerEventRegistrationService(IEventRepository EventRepository, IResponseRepository ResponseRepository, INotificationRepository NotificationRepository, IUserRepository UserRepository, IUserPermissions userPermissions, ITenantManager tenantManager, ILogManager logger, IHttpContextAccessor accessor)
|
public ServerEventRegistrationService(IEventRepository EventRepository, IResponseRepository ResponseRepository, INotificationRepository NotificationRepository, IUserRepository UserRepository, IUserPermissions userPermissions, ITenantManager tenantManager, ILogManager logger, IHttpContextAccessor accessor, ISettingRepository settingRepository)
|
||||||
{
|
{
|
||||||
_EventRepository = EventRepository;
|
_EventRepository = EventRepository;
|
||||||
_ResponseRepository = ResponseRepository;
|
_ResponseRepository = ResponseRepository;
|
||||||
@ -34,6 +37,7 @@ namespace SZUAbsolventenverein.Module.EventRegistration.Services
|
|||||||
_userPermissions = userPermissions;
|
_userPermissions = userPermissions;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_accessor = accessor;
|
_accessor = accessor;
|
||||||
|
_settingRepository = settingRepository;
|
||||||
_alias = tenantManager.GetAlias();
|
_alias = tenantManager.GetAlias();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +152,39 @@ namespace SZUAbsolventenverein.Module.EventRegistration.Services
|
|||||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Event Response Get Attempt {ModuleId}", ModuleId);
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Event Response Get Attempt {ModuleId}", ModuleId);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
throw new System.NotImplementedException();
|
}
|
||||||
|
|
||||||
|
public async Task<List<User>> GetRecommendedResponses(int EventId, int ModuleId)
|
||||||
|
{
|
||||||
|
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.View))
|
||||||
|
{
|
||||||
|
IEnumerable<Response> responses = _ResponseRepository.GetResponses(EventId, ModuleId).DistinctBy(r => r.OwnerId).Where(r => r.OwnerId != _accessor.HttpContext.User.UserId() && r.ResponseType);
|
||||||
|
IEnumerable<User> users = _UserRepository.GetUsers();
|
||||||
|
|
||||||
|
List<Setting> userSettings = _settingRepository.GetSettings("User").ToList();
|
||||||
|
|
||||||
|
List<Setting> requestorSettings = userSettings.FindAll(s => s.EntityId == _accessor.HttpContext.User.UserId());
|
||||||
|
string targetFachrichtung = requestorSettings.FirstOrDefault(s => s.SettingName == "Fachrichtung")?.SettingValue;
|
||||||
|
int targetStartjahr = int.Parse(requestorSettings.FirstOrDefault(s => s.SettingName == "Jahrgang")?.SettingValue ?? "0");
|
||||||
|
|
||||||
|
|
||||||
|
IEnumerable<GroupingUser> gu = responses.Join(users, r => r.OwnerId, u => u.UserId,
|
||||||
|
(response, user) => new GroupingUser(user, response)).GroupJoin(userSettings, gu => gu.User.UserId,
|
||||||
|
s => s.EntityId, (gu, s) =>
|
||||||
|
{
|
||||||
|
gu.Settings = s;
|
||||||
|
gu.TargetJahr = targetStartjahr;
|
||||||
|
gu.TargetFachrichtung = targetFachrichtung;
|
||||||
|
|
||||||
|
return gu;
|
||||||
|
}).OrderBy(gu => gu.Score());
|
||||||
|
return gu.Select(gu => gu.User).ToList();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Event Response Get Attempt {ModuleId}", ModuleId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<List<Event>> GetEventsAsync(int ModuleId)
|
public Task<List<Event>> GetEventsAsync(int ModuleId)
|
||||||
@ -179,55 +215,6 @@ namespace SZUAbsolventenverein.Module.EventRegistration.Services
|
|||||||
return Task.FromResult(NewEvent);
|
return Task.FromResult(NewEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement the methods for EventResponses
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
public Task<Models.Event> GetEventRegistrationAsync(int EventRegistrationId, int ModuleId)
|
|
||||||
{
|
|
||||||
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.View))
|
|
||||||
{
|
|
||||||
return Task.FromResult(_EventRegistrationRepository.GetEventRegistration(EventRegistrationId));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized EventRegistration Get Attempt {EventRegistrationId} {ModuleId}", EventRegistrationId, ModuleId);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<Models.Event> AddEventRegistrationAsync(Models.Event EventRegistration)
|
|
||||||
{
|
|
||||||
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, EventRegistration.ModuleId, PermissionNames.Edit))
|
|
||||||
{
|
|
||||||
EventRegistration = _EventRegistrationRepository.AddEventRegistration(EventRegistration);
|
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "EventRegistration Added {EventRegistration}", EventRegistration);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized EventRegistration Add Attempt {EventRegistration}", EventRegistration);
|
|
||||||
EventRegistration = null;
|
|
||||||
}
|
|
||||||
return Task.FromResult(EventRegistration);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<Models.Event> UpdateEventRegistrationAsync(Models.Event EventRegistration)
|
|
||||||
{
|
|
||||||
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, EventRegistration.ModuleId, PermissionNames.Edit))
|
|
||||||
{
|
|
||||||
EventRegistration = _EventRegistrationRepository.UpdateEventRegistration(EventRegistration);
|
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "EventRegistration Updated {EventRegistration}", EventRegistration);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized EventRegistration Update Attempt {EventRegistration}", EventRegistration);
|
|
||||||
EventRegistration = null;
|
|
||||||
}
|
|
||||||
return Task.FromResult(EventRegistration);
|
|
||||||
}
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
private void SendEventResponseNotification(string subject, string body)
|
private void SendEventResponseNotification(string subject, string body)
|
||||||
{
|
{
|
||||||
User user = _UserRepository.GetUser(_accessor.HttpContext.User.UserId());
|
User user = _UserRepository.GetUser(_accessor.HttpContext.User.UserId());
|
||||||
@ -235,4 +222,73 @@ namespace SZUAbsolventenverein.Module.EventRegistration.Services
|
|||||||
_NotificationRepository.AddNotification(notification);
|
_NotificationRepository.AddNotification(notification);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class GroupingUser
|
||||||
|
{
|
||||||
|
private User _user;
|
||||||
|
private Response _response;
|
||||||
|
|
||||||
|
private string _fachrichtung;
|
||||||
|
private int _startjahr;
|
||||||
|
|
||||||
|
private int _targetyear;
|
||||||
|
private string _targetfachrichtung;
|
||||||
|
public User User { get { return _user; } }
|
||||||
|
|
||||||
|
public IEnumerable<Setting> Settings
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
_fachrichtung = "-";
|
||||||
|
_startjahr = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_fachrichtung = value.FirstOrDefault(v => v.SettingName == "Fachrichtung", new Setting(){SettingValue = "-"}).SettingValue;
|
||||||
|
_startjahr = int.Parse(value.FirstOrDefault(v => v.SettingName == "Jahrgang", new Setting(){SettingValue = "0"}).SettingValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string TargetFachrichtung
|
||||||
|
{
|
||||||
|
set { _targetfachrichtung = value; }
|
||||||
|
}
|
||||||
|
public int TargetJahr
|
||||||
|
{
|
||||||
|
set { _targetyear = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public GroupingUser(User user, Response response)
|
||||||
|
{
|
||||||
|
_user = user;
|
||||||
|
_response = response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Score()
|
||||||
|
{
|
||||||
|
int total = 0;
|
||||||
|
total += ScoreYear() * 5;
|
||||||
|
total += ScoreFachrichtung() * 3;
|
||||||
|
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int ScoreYear()
|
||||||
|
{
|
||||||
|
return Math.Abs(_targetyear - _startjahr);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int ScoreFachrichtung()
|
||||||
|
{
|
||||||
|
if (_fachrichtung == _targetfachrichtung)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Oqtane.Models;
|
||||||
using SZUAbsolventenverein.Module.EventRegistration.Models;
|
using SZUAbsolventenverein.Module.EventRegistration.Models;
|
||||||
|
|
||||||
namespace SZUAbsolventenverein.Module.EventRegistration.Services
|
namespace SZUAbsolventenverein.Module.EventRegistration.Services
|
||||||
@ -26,5 +27,6 @@ namespace SZUAbsolventenverein.Module.EventRegistration.Services
|
|||||||
Task<(Event, Response)> GetEventDetails(int EventId, int ModuleId);
|
Task<(Event, Response)> GetEventDetails(int EventId, int ModuleId);
|
||||||
|
|
||||||
Task<List<Response>> GetEventResponses(int EventId, int ModuleId);
|
Task<List<Response>> GetEventResponses(int EventId, int ModuleId);
|
||||||
|
Task<List<User>> GetRecommendedResponses(int EventId, int ModuleId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user