Artemis.ViewModels.Profiles.ProfileEditorViewModel.DuplicateProfile C# (CSharp) Method

DuplicateProfile() public method

public DuplicateProfile ( ) : void
return void
        public async void DuplicateProfile()
        {
            if (SelectedProfile == null)
                return;

            var newProfile = GeneralHelpers.Clone(SelectedProfile);
            newProfile.Name = await DialogService
                .ShowInputDialog("Duplicate profile", "Please enter a unique profile name");

            // Null when the user cancelled
            if (string.IsNullOrEmpty(newProfile.Name))
                return;

            // Verify the name
            while (ProfileProvider.GetAll().Contains(newProfile))
            {
                newProfile.Name =
                    await DialogService.ShowInputDialog("Name already in use", "Please enter a unique profile name");

                // Null when the user cancelled
                if (string.IsNullOrEmpty(newProfile.Name))
                    return;
            }

            newProfile.IsDefault = false;
            ProfileProvider.AddOrUpdate(newProfile);
            LoadProfiles();
            SelectedProfile = Profiles.FirstOrDefault(p => p.Name == newProfile.Name);
        }