fullstackhero / blazor-wasm-boilerplate

Clean Architecture Boilerplate Template for .NET 6.0 Blazor WebAssembly built for FSH WebAPI with the goodness of MudBlazor Components.

Home Page:https://fullstackhero.net/blazor-webassembly-boilerplate/general/getting-started/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error while update Role

anasseb opened this issue · comments

Hello,
I think there is a regression in the front while updating role, before there was no bug, this month I tried to update a role and I have the error bellow
Unhandled exception rendering component: The given key 'PermissionViewModel { Description = View Dashboard, Action = View, Resource = Dashboard, IsBasic = False, IsRoot = False, Name = Permissions.Dashboard.View, Enabled = True }' was not present in the dictionary.

I download the last version in this repo and the error existe too.

To reproduce, juste go to Basic role and check or uncheck any field then save.

The actual role seems to be saved successfully though...

Not sure what's going on. I have a suspicion it has something to do with the fact that PermissionViewModel is a record in stead of a regular class...

Indeed like I thought... Adding an Equals method to PermissionViewModel that delegates to the base (FSHPermission) seems to get rid of the exception (otherwise it also takes the Enabled property into account when comparing):

public sealed record PermissionViewModel : FSHPermission
{
    public bool Enabled { get; set; }

    public PermissionViewModel(string Description, string Action, string Resource, bool IsBasic = false, bool IsRoot = false)
        : base(Description, Action, Resource, IsBasic, IsRoot)
    {
    }

    public bool Equals(PermissionViewModel? other) => base.Equals(other);
    public override int GetHashCode() => base.GetHashCode();
}

I'll test that and give you a feedback

Worked fine after adding the Equals method.
Thanks

This shouldn't be closed as long as it isn't fixed in the actual repo... You're welcome to create a PR ;-)