protected override object CreateInstance(Type itemType)
 {
     if (itemType.UnderlyingSystemType == typeof(WindowsModelRoleMember))
     {
         return(WindowsModelRoleMember.CreateUnassigned());
     }
     else
     {
         return(ExternalModelRoleMember.CreateUnassigned());
     }
 }
        public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request)
        {
            var    azureToken       = request.DataStore.GetJson("AzureToken");
            string serverUrl        = request.DataStore.GetValue("ASServerUrl");
            string asDatabase       = request.DataStore.GetValue("ASDatabase");
            string user             = request.DataStore.GetValue("UserToAdd");
            string connectionString = ValidateConnectionToAS.GetASConnectionString(request, azureToken, serverUrl);

            Server server = null;

            try
            {
                server = new Server();
                server.Connect(connectionString);

                Database db = server.Databases.FindByName(asDatabase);
                if (db == null)
                {
                    return(new ActionResponse(ActionStatus.Failure, string.Empty, null, null, "Unable to find model"));
                }

                var role = new ModelRole()
                {
                    Name = "ProcessOnlyRole"
                };

                role.ModelPermission = ModelPermission.Administrator;
                ExternalModelRoleMember member = new ExternalModelRoleMember();
                member.IdentityProvider = "AzureAD";
                member.MemberName       = user;
                //AzureAD
                role.Members.Add(member);

                db.Model.Roles.Add(role);
                db.Model.SaveChanges();
                server.Disconnect(true);

                return(new ActionResponse(ActionStatus.Success));
            }
            catch (Exception e)
            {
                return(new ActionResponse(ActionStatus.Failure, string.Empty, e, null, "Unable to assign permissions"));
            }
            finally
            {
                server?.Dispose();
            }
        }