Example #1
0
        private async Task AddValidRolesAsync(Delta <CustomerDto> customerDelta, Customer currentCustomer)
        {
            var allCustomerRoles = await CustomerService.GetAllCustomerRolesAsync(true);

            foreach (var customerRole in allCustomerRoles)
            {
                if (customerDelta.Dto.RoleIds.Contains(customerRole.Id))
                {
                    //new role
                    if (!await CustomerService.IsInCustomerRoleAsync(currentCustomer, customerRole.Name))
                    {
                        await CustomerService.AddCustomerRoleMappingAsync(new CustomerCustomerRoleMapping
                        {
                            CustomerId     = currentCustomer.Id,
                            CustomerRoleId = customerRole.Id
                        });
                    }
                }
                else
                {
                    if (await CustomerService.IsInCustomerRoleAsync(currentCustomer, customerRole.Name))
                    {
                        await CustomerService.RemoveCustomerRoleMappingAsync(currentCustomer, customerRole);
                    }
                }
            }
        }