@page "/pollcreate" @using Lieb.Data @using Lieb.Models @using Lieb.Models.Poll @using Lieb.Models.GuildWars2.Raid @using System.ComponentModel.DataAnnotations @using System.Security.Claims @using SharedClasses.SharedModels @inject RaidService RaidService @inject UserService UserService @inject PollService PollService @inject NavigationManager NavigationManager @inject AuthenticationStateProvider AuthenticationStateProvider @inject IJSRuntime JsRuntime

Create Poll

@if(_pollType == POLL_TYPE_RAID) {

} else if(_pollType == POLL_TYPE_GROUP) {

}

@foreach(PollOption option in _poll.Options) { }
Option

@code { public Poll _poll = new Poll(); private LiebUser _user; private string _errorMessage = string.Empty; private List _raids = new List(); private List _availabeGroups = new List(); private const string POLL_TYPE_RAID = "raid"; private const string POLL_TYPE_GROUP = "group"; private string _pollType = POLL_TYPE_RAID; private int _chosenRaid; private int _chosenRole; protected override async Task OnInitializedAsync() { var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); if (authState != null) { ulong discordId = ulong.Parse(authState.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value); _user = UserService.GetLiebUser(discordId); } if(_user == null) { NavigationManager.NavigateTo(""); } _raids = RaidService.GetRaids(); _chosenRaid = _raids.OrderByDescending(r => r.StartTimeUTC).First().RaidId; if(_user.RoleAssignments.Where(r => r.LiebRole.Level >= Constants.Roles.Admin.PowerLevel).Any()) { _availabeGroups = UserService.GetLiebRoles().Where(u => u.Type == RoleType.UserDefinedRole).ToList(); } else { _availabeGroups = UserService.GetUserRoles(_user.Id).Where(u => u.Type == RoleType.UserDefinedRole).ToList(); } _poll.AnswerType = AnswerType.Dropdown; if(_availabeGroups.Count > 0) { _chosenRole = _availabeGroups.First().LiebRoleId; } } async Task AddOptionClicked() { _poll.Options.Add(new PollOption()); } async Task DeleteOptionClicked(PollOption option) { _poll.Options.Remove(option); } private async Task HandleValidSubmit() { if(_poll.Options.Count < 2) { _errorMessage = "At least 2 options are needed for a Poll."; return; } foreach(PollOption option in _poll.Options) { if(string.IsNullOrWhiteSpace(option.Name)) { _errorMessage = "Options must not be empty."; return; } } if(_pollType == POLL_TYPE_RAID) { await PollService.CreatePoll(_poll, _chosenRaid); } else if(_pollType == POLL_TYPE_GROUP) { await PollService.CreatePoll(_poll, UserService.GetGroupMembers(_chosenRole).Select(u => u.Id).ToHashSet()); } NavigationManager.NavigateTo("polloverview"); } }