Lesson 21 library management system using radzen blazor studio

In this lesson, I customize the add library employee page so that when a new library employee is created, a new application user is created also.

This customization was achieved by using Visual Studio 2022.

1 Like

So amazing! I was just working on this very thing. As usual I was over thinking it and your solution to adding Employees and creating users at the same time is just genius in my book. I was trying so hard to do it the other way around.


Good to know that my approach helped you in such way!

Thank you for all your tutorials! Such a great help! I do have one question. After following your example for an employee table to update both employees and aspnetusers, I extended the aspnetuser table and then tried to update the extended columns (basically an account number (bigint) and a store number (int). The code does not generate any errors, but also does not update the aspnetuser table. I am not familiar enough with security services and was wondering if I need to add those fields somewhere else to be affected properly (not sure on whether its json or security services)...any insight would be greatly appreciated!

In Radzen Studio it was quite easy to update, but I cannot see how to do it in radzen blazor studio...

Just to follow up on my last comment! There seems to be an issue with RBS when you use EF Migrations to add columns to the AspNetUser table. They add fine and are displayed fine, but when you modify the Add Application User page to include the additional columns from the the AspNetUsers table, it will not add the additional data, nor will it allow you to update it using Edit Application User. I looked everywhere to see where the code did not get updated, but no luck.

Luckily, I used the code you provided here and I modified it! After CreateUser is executed and before closing the dialog, I created an additional method that located the just created record outside of ApplicationUser, and then added the additional column data directly to the AspNetUser and then updated it.

It worked like a charm. So again I thank you for this example as it really made my day!!!

Below is my modifications, in case anybody else would like to handle it this way!

    protected async Task FormSubmit()
            // check if email has been used
            IEnumerable<Models.ApplicationUser> users = await Security.GetUsers();
                Models.ApplicationUser existingUser = users.FirstOrDefault(p => p.Email == employee.EmailAddress);
                if(existingUser!= null)
                    // email has been used
                    NotificationService.Notify(new NotificationMessage() { Severity = NotificationSeverity.Error, Summary = $"Duplicate Email Error", Detail = $"Email has been used previously" });
                    // get application roles
                    var roles=await Security.GetRoles();
                    if (roles.Any())
                        var employeeStaffRole = "Staff";
                        var employeeRole=roles.FirstOrDefault(r=> r.Name==employeeStaffRole);
                        if (employeeRole!=null)
                            var newUser=new Models.ApplicationUser();
                            newUser.Email = employee.EmailAddress;
                            newUser.Name = newUser.Email;
                            newUser.Password = employee.Password;
                            newUser.ConfirmPassword = employee.ConfirmPassword;
                            newUser.Roles=new List<Models.ApplicationRole>();
                            // we do not want to store passwords in unsecure location
                            employee.Password = "Not Displayed";
                            employee.ConfirmPassword = "Not Displayed";
                            await AccelerateDataService.CreateEmployee(employee);
                            await Security.CreateUser(newUser);
                            IEnumerable<Models.AccelerateData.AspNetUser> updateUser = await AccelerateDataService.GetAspNetUsers();
                            if (updateUser.Any())
                                Models.AccelerateData.AspNetUser updateExistingUser = updateUser.FirstOrDefault(p => p.Email == employee.EmailAddress);
                                    Id = updateExistingUser.Id;
                                    updateExistingUser.AccountID = employee.AccountID;
                                    updateExistingUser.StoreID= employee.StoreID;
                                    updateExistingUser.UserActive = employee.EmployeeActive;
                                    updateExistingUser.MultiStore = employee.MultiStore;
                                await AccelerateDataService.UpdateAspNetUser(Id,updateExistingUser);
        catch (Exception ex)
            errorVisible = true;

Obviously with my columns, but you'll get the jist....again THANK YOU!!!