Store Multiple Selection drop down values back to a table as individual records

I know this has been discussed many times on this forum, but for the life of me I cannot Understand/figure out how to store my dropdown multiple selections as records.

I have successfully adopted the methodology for allowing multiple selection utilizing an IEnumerable as a value, but converting the selection value to individual records is stumping me.

I am implementing an employee registry (not application users) and need to assign multiple job roles to some employees. I can successfully select multiple roles and store them in my temporary variable of 'selectedRoles', but then when the employee data is saved, I need each selected role to be added as an individual record in my EmployeeRoles table that consists of a JobRoleId and EmployeeId which can be called up again when I edit that employee. Id like to have previously saved job roles already selected when the drop down is opened and be able to make changes and reproduce this behavior.

Any help is appreciated.

As a note, I am using Radzen desktop application. My C# coding skills are intermediate, my blazor skills are mature.

@Andrew_Paull The way I save them is to invoke a custom method on save and loop through your 'selectedRoles' list saving them. Here's a custom method example -

        private AmpirDataService AmpirDataService { get; set; }
        //Adds items to junction table
        public async Task<bool> saveHCDFundingSourcesJunction(int propertyFK, IEnumerable<string> HCDFundingSourcesJunctionsList)
        {
            try
            {
                foreach (var item in HCDFundingSourcesJunctionsList)
                {
                    Ampir.Models.AmpirData.HcdFundingSourcesJunction i = new Ampir.Models.AmpirData.HcdFundingSourcesJunction
                    {
                        PropertyFK = propertyFK,
                        HCDFundingSource = item
                    };
                    await AmpirData.CreateHcdFundingSourcesJunction(i);
                }
                await InvokeAsync(() => { StateHasChanged(); });

            }
            catch (System.Exception saveHCDFundingSourcesJunction)
            {
                NotificationService.Notify(new NotificationMessage() { Severity = NotificationSeverity.Error, Summary = $"Error", Detail = $"Unable to add HCD Funding Source" });

                return false;
            }
            return true;
        }

@SloSuenos Excellent. I had considered and assumed a loop was necessary, but wasn't sure where to store such a method to call on in Radzen. How does radzen IDE handle this? Also, once the junction table is updated, how do I call upon the stored values again and set them as the value of the drop down when I edit the employee? Thanks!

I have adapted the code to my model:

private BiaBuilderDbService BiaBuilderDbDataService { get; set; }
        //Adds Employee roles to junction table
        public async Task<bool> saveEmployeeJobRoles(int propertyFK, IEnumerable<string> selectedRoles)
        {
            try
            {
                foreach (var item in selectedRoles)
                {
                    BiaBuilder.Models.BiaBuilderDb.EmployeeJobRole i = new BiaBuilder.Models.BiaBuilderDb.EmployeeJobRole
                    {
                        PropertyFK = propertyFK,
                        JobRole = item
                    };
                    await BiaBuilderDb.createdBiaBuilder.Models.BiaBuilderDb.EmployeeJobRole(i);
                }
                await InvokeAsync(() => { StateHasChanged(); });

            }
            catch (System.Exception saveEmployeeJobRoles)
            {
                NotificationService.Notify(new NotificationMessage() { Severity = NotificationSeverity.Error, Summary = $"Error", Detail = $"Unable to add Employee Job Role" });

                return false;
            }
            return true;
        }

Now I just need to figure out where it goes so Radzen can see it

Save -

There's other posts here that show how to load the dropdown. Also read the documentation about invoking custom methods.

This is very helpful! Where can i store this method in my model so that Radzen IDE can see it and I can call it as a method? I'm using Visual Studio.

I am assuming to the page component? Can i save it somewhere that it can be called from all pages if necessary?

I have made all the necessary changes to the example code to reflect what i am trying to do in this method, but intellisense doesnt like my Async and Notification calls. Ive tried adding the correct references, but none are working. I added this method to a custom service

Do you know any specific posts that may provide more details? I feel that this has been a bit of a wild goose chase trying to find one with my specific situation. I have been trying to resolve this for many hours and I cant get past the intellisense errors im getting. Ive completed the code structure and added to the correct page.cs so that radzen can find it..

I have refactored the code to incorporate the correct void and context. hopefully there will be no run errors!

@SloSuenos, This Worked!

Now I just need to retrieve the data on load of the edit page to appropriately select the correct boxes in the list. What is your input?