radzenhq / radzen-blazor-studio

Sample applications created with Radzen Blazor Studio
https://www.radzen.com/blazor-studio
16 stars 2 forks source link

unable to select role in add application user dialog #117

Closed daskabe closed 10 months ago

daskabe commented 10 months ago

Hello, created new security using ASP.NET Core identity.

I created roles image

then tried to create user - on the dilaog the role dropdown does not allow selection chrome_4DG34QZlJF

image

This generated code is suspect

 public partial class ApplicationRole : IdentityRole
    {
        [JsonIgnore]
        public ICollection<ApplicationUser> Users { get; set; }
    }

Shouldn't it be

 public partial class ApplicationRole : IdentityRole
    {
        [JsonIgnore]
        public ICollection<ApplicationRole> Roles{ get; set; }
    }

This is where its getting called image

akorchev commented 10 months ago

I can't reproduce such a problem with a default application.

image

Also the generated code is correct (this is how Entity Framework maps related entities). If you have a Radzen Blazor Studio subscription you can send us your app to info@radzen.com so we can troubleshoot.

daskabe commented 9 months ago

I dont have subscription - yet :).

Can you confirm my back code for AddApplicationUser.razor.cs has everything?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.JSInterop;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Radzen;
using Radzen.Blazor;

namespace TestApp.Pages
{
    public partial class AddApplicationUser
    {
        [Inject]
        protected IJSRuntime JSRuntime { get; set; }

        [Inject]
        protected NavigationManager NavigationManager { get; set; }

        [Inject]
        protected DialogService DialogService { get; set; }

        [Inject]
        protected TooltipService TooltipService { get; set; }

        [Inject]
        protected ContextMenuService ContextMenuService { get; set; }

        [Inject]
        protected NotificationService NotificationService { get; set; }

        protected IEnumerable<TestApp.Models.ApplicationRole> roles;
        protected TestApp.Models.ApplicationUser user;
        protected IEnumerable<string> userRoles = Enumerable.Empty<string>();
        protected string error;
        protected bool errorVisible;

        [Inject]
        protected SecurityService Security { get; set; }

        protected override async Task OnInitializedAsync()
        {
            user = new TestApp.Models.ApplicationUser();

            roles = await Security.GetRoles();
        }

        protected async Task FormSubmit(TestApp.Models.ApplicationUser user)
        {
            try
            {
                user.Roles = roles.Where(role => userRoles.Contains(role.Id)).ToList();
                await Security.CreateUser(user);
                DialogService.Close(null);
            }
            catch (Exception ex)
            {
                errorVisible = true;
                error = ex.Message;
            }
        }

        protected async Task CancelClick()
        {
            DialogService.Close(null);
        }

    }
}