public AccessProfileDialog(AccessProfileViewModel accessProfile)
 {
     InitializeComponent();
     accessProfile.WindowCloseRequest += () => this.Close();
     this.Closing += (sender, args) => accessProfile.OnClosing(args);
     this.DataContext = accessProfile;
 }
        public void LoadData(List<string> selectedItems = null)
        {
            var bw = new BackgroundWorker();
            var returnList = new List<AccessProfileViewModel>();

            bw.DoWork += delegate
            {
                foreach (var accessProfile in _accessProfileServicee.AccessProfiles)
                {
                    var viewModel = new AccessProfileViewModel(accessProfile);

                    if (selectedItems != null && selectedItems.Count > 0 && selectedItems.Contains(accessProfile.Id))
                        viewModel.IsSelected = true;

                    returnList.Add(viewModel);
                }

            };
            bw.RunWorkerCompleted += delegate
            {
                _accessProfiles = new ObservableCollection<AccessProfileViewModel>();

                foreach (var accessProfileViewModel in returnList)
                {
                    _accessProfiles.Add(accessProfileViewModel);
                }

                this.RaisePropertyChanged("AccessProfiles");
            };

            bw.RunWorkerAsync();
        }
        private void InitializeAccessProfiles()
        {
            ShowBusyHandler();

            var bw = new BackgroundWorker();
            var returnList = new List<AccessProfileViewModel>();
            string selectedAccessProfileId = String.Empty;

            bw.DoWork += delegate
            {
                returnList.AddRange(_accessProfileServicee.AccessProfiles.Select(accessProfile => new AccessProfileViewModel(accessProfile)));
                if (this.SelectedAccessProfile != null)
                    selectedAccessProfileId = this.SelectedAccessProfile.Model.Id;
            };
            bw.RunWorkerCompleted += delegate
            {
                _accessProfiles = new ObservableCollection<AccessProfileViewModel>();

                foreach (var accessProfileViewModel in returnList)
                {
                    _accessProfiles.Add(accessProfileViewModel);

                    if (!String.IsNullOrEmpty(selectedAccessProfileId) && selectedAccessProfileId == accessProfileViewModel.Model.Id)
                        this.SelectedAccessProfile = accessProfileViewModel;
                }

                this.RaisePropertyChanged("AccessProfiles");
                this.RaisePropertyChanged("SelectedAccessProfile");

                HideBusyHandler();
            };

            bw.RunWorkerAsync();
        }
        public void ShowEditAccessProfileDialog(AccessProfileViewModel accessProfileViewModel)
        {
            Window window = FindFromCollection(accessProfileViewModel.Model.Id);

            if (window == null)
            {
                window = new AccessProfileDialog(new AccessProfileViewModel(_accessProfileService.CreateCopy(accessProfileViewModel.Model)));
                AddToCollection(accessProfileViewModel.Model.Id, window);
            }
            window.Closed += (sender, args) => DialogCollection.Remove(((AccessProfileViewModel)((MetroWindow)sender).DataContext).Model.Id);
            ActivateWindow(window);
        }