Skip to content

Commit

Permalink
Adding MG role functions and characters asigned to users
Browse files Browse the repository at this point in the history
  • Loading branch information
KrystianKempski committed Mar 12, 2024
1 parent 2a4f905 commit 23a959a
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 41 deletions.
6 changes: 6 additions & 0 deletions DA_Business/Repository/CharacterReps/CharacterRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ public async Task<CharacterDTO> GetById(int id)
}
return new CharacterDTO();
}
public async Task<IEnumerable<CharacterDTO>> GetAllForUser(string userName)
{
if (userName == null || userName.Length<3)
return null;
return _mapper.Map<IEnumerable<Character>, IEnumerable<CharacterDTO>>(_db.Characters.Where(u => u.UserName == userName));
}

public async Task<CharacterDTO> Update(CharacterDTO objDTO)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public interface ICharacterRepository

public Task<CharacterDTO> GetById(int id);
public Task<IEnumerable<CharacterDTO>> GetAll(int? id=null);
public Task<IEnumerable<CharacterDTO>> GetAllForUser(string userName);
}
}
31 changes: 1 addition & 30 deletions DagoniteEmpire/Areas/Identity/Pages/Account/Register.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -45,36 +45,7 @@
<button id="registerSubmit" type="submit" class="w-100 btn btn-lg btn-primary">Register</button>
</form>
</div>
@* <div class="col-md-6 col-md-offset-2">
<section>
<h3>Use another service to register.</h3>
<hr />
@{
if ((Model.ExternalLogins?.Count ?? 0) == 0)
{
<div>
<p>
There are no external authentication services configured. See this <a href="https://go.microsoft.com/fwlink/?LinkID=532715">article
about setting up this ASP.NET application to support logging in via external services</a>.
</p>
</div>
}
else
{
<form id="external-account" asp-page="./ExternalLogin" asp-route-returnUrl="@Model.ReturnUrl" method="post" class="form-horizontal">
<div>
<p>
@foreach (var provider in Model.ExternalLogins!)
{
<button type="submit" class="btn btn-primary" name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account">@provider.DisplayName</button>
}
</p>
</div>
</form>
}
}
</section>
</div> *@

</div>

@section Scripts {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public async Task<IActionResult> OnPostAsync(string returnUrl = null)
{
var user = CreateUser();

await _userStore.SetUserNameAsync(user, Input.Email, CancellationToken.None);
await _userStore.SetUserNameAsync(user, Input.UserName, CancellationToken.None);
await _emailStore.SetEmailAsync(user, Input.Email, CancellationToken.None);
var result = await _userManager.CreateAsync(user, Input.Password);

Expand Down
1 change: 1 addition & 0 deletions DagoniteEmpire/DagoniteEmpire.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.11" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
<PackageReference Include="SendGrid" Version="9.29.2" />
<PackageReference Include="Syncfusion.Blazor.Grid" Version="24.2.3" />
<PackageReference Include="Syncfusion.Blazor.RichTextEditor" Version="24.2.3" />
<PackageReference Include="Syncfusion.Blazor.Themes" Version="24.2.3" />
Expand Down
31 changes: 26 additions & 5 deletions DagoniteEmpire/Pages/CharacterPages/CharacterList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
@using Syncfusion.Blazor.Navigations;
@inject ICharacterRepository _characterRepository
@inject ISpecialSkillRepository _specialSkillRepository
@inject AuthenticationStateProvider GetAuthenticationStateAsync
@inject NavigationManager _navigationManager
@inject IJSRuntime _jsRuntime
@attribute [Authorize(Roles = SD.Role_Admin + "," + SD.Role_HeroPlayer + "," + SD.Role_DukePlayer + "," + SD.Role_GameMaster)]
<_DeleteConfirmation IsParentComponentProcessing=IsLoading DeleteConfirmation="ConfirmDelete_Click" DeletingComponentName="this character"></_DeleteConfirmation>

<div class="row mt-4">
<div class="col-12">
<h4 class="card-title">User Characters List </h4>
<h4 class="card-title">@Title</h4>
</div>
</div>
<div class="row mt-4">
Expand All @@ -19,10 +20,13 @@
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="@EditMode.Dialog"></GridEditSettings>
<GridEvents OnActionBegin="ActionHandler" TValue="CharacterDTO"></GridEvents>
<GridColumns>
@if (IsAdminOrMG){
<GridColumn Field=@nameof(CharacterDTO.UserName) HeaderText="User name" TextAlign="TextAlign.Left" Width="300"></GridColumn>
}
<GridColumn Field=@nameof(CharacterDTO.NPCName) HeaderText="Name" TextAlign="TextAlign.Left" Width="300"></GridColumn>
<GridColumn Field=@nameof(CharacterDTO.Race) HeaderText="Race" TextAlign="TextAlign.Left" Width="150"></GridColumn>
<GridColumn Field=@nameof(CharacterDTO.Class) HeaderText="Class" TextAlign="TextAlign.Left" Width="300"></GridColumn>
<GridColumn Field=@nameof(CharacterDTO.Age) HeaderText="Age" Format="d" TextAlign="TextAlign.Right" Width="50"></GridColumn>
<GridColumn Field=@nameof(CharacterDTO.Race) HeaderText="Race" TextAlign="TextAlign.Left" Width="200"></GridColumn>
<GridColumn Field=@nameof(CharacterDTO.Class) HeaderText="Class" TextAlign="TextAlign.Left" Width="200"></GridColumn>
<GridColumn Field=@nameof(CharacterDTO.Age) HeaderText="Age" Format="d" TextAlign="TextAlign.Left" Width="50"></GridColumn>
</GridColumns>
</SfGrid>
@if (Characters.Any())
Expand All @@ -48,7 +52,9 @@
@code {
private IEnumerable<CharacterDTO> Characters { get; set; } = new List<CharacterDTO>();
public bool IsLoading { get; set; }
public bool IsAdminOrMG { get; set; } = true;
private int DeleteCharacterId { get; set; } = 0;
private string Title { get; set; } = "Your characters";

// [CascadingParameter]
// public Task<AuthenticationState> AuthenticationState { get; set; }
Expand Down Expand Up @@ -80,7 +86,22 @@
{
IsLoading = true;
StateHasChanged();
Characters = await _characterRepository.GetAll();
var authstate = await GetAuthenticationStateAsync.GetAuthenticationStateAsync();
var user = authstate.User;
Title = "Characters of " + user.Identity.Name;
if (user == null)
return; // failed to load
IsAdminOrMG = user.IsInRole(SD.Role_Admin) || user.IsInRole(SD.Role_GameMaster);

if (IsAdminOrMG)
{
Characters = await _characterRepository.GetAll();
}
else
{
Characters = await _characterRepository.GetAllForUser(user.Identity.Name);
}
IsLoading = false;
StateHasChanged();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@

.card-title{
color: black;
padding-left:8px;
}
2 changes: 1 addition & 1 deletion DagoniteEmpire/Pages/CharacterPages/CharacterUpsert.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@using DA_Models
@using DagoniteEmpire.Service.IService
@using DagoniteEmpire.Pages.Components
@attribute [Authorize(Roles = SD.Role_Admin + "," + SD.Role_HeroPlayer + "," + SD.Role_DukePlayer)]
@attribute [Authorize(Roles = SD.Role_Admin + "," + SD.Role_HeroPlayer + "," + SD.Role_DukePlayer + "," + SD.Role_GameMaster)]

@inject NavigationManager _navigationManager
<_LeavePage IsParentComponentProcessing=IsLoading LeaveConfirmation="ConfirmLeave_Click" ></_LeavePage>
Expand Down
4 changes: 2 additions & 2 deletions DagoniteEmpire/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PageTitle>Dagonite Empire</PageTitle>

<header class="hero-img" id="home">
<div class="hero-text text-center p-2">
<h1>Welcome to <span class="blue-text">Dagonite Empire!</span></h1>
<div class="hero-text text-center">
<h1 class="text" >Welcome to <span class="text blue-text">Dagonite Empire!</span></h1>
</div>
<div class="hero-shadow"></div>

Expand Down
8 changes: 6 additions & 2 deletions DagoniteEmpire/Pages/Index.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

h1 {
font-family: 'Eagle Lake', serif;
text-shadow: 8px 8px 6px black;
}

.hero-img {
position: relative;
height: 100vh;
height: calc(100vh - 62px);
background-image: url('../images/EastMarchy_header.webp');
background-size: cover;
background-position: center;
Expand All @@ -27,10 +28,13 @@ h1 {
}

.blue-text {
color: darkgoldenrod;
color: darkgoldenrod;/*
text-shadow: 5px 5px 20px rgb(0, 0, 0);*/
}

.text{

}

.hero-shadow {
position: absolute;
Expand Down

0 comments on commit 23a959a

Please sign in to comment.