/// <summary>
 /// Executes the manage command.
 /// </summary>
 /// <param name="vm">The vm.</param>
 private void ExecuteManageCommand(WebsiteViewModel vm)
 {
     if (vm == null)
     {
         return;
     }
     using (var cursor = ApplicationCursor.SetCursor(Cursors.Wait))
     {
         var q = new UriQuery {
             { "WebsiteId", vm.Website.Id.ToString() }
         };
         RegionManager.RequestNavigate(RegionNames.MainContent, new Uri(ViewNames.WebsiteManageView + q, UriKind.Relative));
     }
 }
        /// <summary>
        /// Executes the delete command.
        /// </summary>
        /// <param name="vm">The vm.</param>
        private void ExecuteDeleteCommand(WebsiteViewModel vm)
        {
            if (MessageBox.Show(
                    string.Format("Are you sure you want to delete this website: {0}", vm.Website.Name),
                    "Delete Website?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
            {
                return;
            }

            if (!WebsiteDataService.DeleteWebsite(vm.Website))
            {
                // publish so the WebsiteCollectionView will refresh without this web
                Events.GetEvent <WebsiteDeletedEvent>().Publish(vm);
            }
        }
        //void OnWebsiteUpdated(WebsiteViewModel vm)
        //{
        //    // TODO: re-apply the sortby function now in case the current sort-property was changed on the website.

        //    var msg = String.Format("Website {0} has been updated", vm.Website.Name);
        //    EventAggregator.GetEvent<GenericNotificationEvent>().Publish(msg);

        //    WebsitesCVS.View.Refresh();
        //    SelectedWebsite = vm;
        //}

        void OnWebsiteDeleted(WebsiteViewModel vm)
        {
            var name = vm.Website.Name;

            WebsiteViewModels.Remove(vm);

            var msg = String.Format("Website {0} has been deleted", name);

            Events.GetEvent <GenericNotificationEvent>().Publish(msg);

            WebsitesCVS.View.Refresh();

            // Select the 1st one in the list or null.
            // TODO: better to select 1 below the one just deleted.
            SelectedWebsite = WebsiteViewModels.Any() ? WebsiteViewModels[0] : null;
        }
        private void ExecuteExportCommand(WebsiteViewModel vm)
        {
            try
            {
                if (vm == null)
                {
                    return;
                }
                //if (WebsiteDataService == null)
                //Events.GetEvent<ErrorNotificationEvent>().Publish();

                base.Logger.Information($"Exporting configuration for website \"{vm.DisplayName}\"");
                Website websiteToExport = null;
                using (ApplicationCursor.SetCursor(Cursors.Wait))
                {
                    WebsiteDataService.GetEntityById <Website>(vm.Website.Id, (website, exception) =>
                    {
                        if (exception == null)
                        {
                            websiteToExport = website;
                        }
                        else
                        {
                            Events.GetEvent <ErrorNotificationEvent>().Publish(exception);
                        }
                    });

                    if (websiteToExport == null)
                    {
                        return;
                    }

                    WebsiteExporter.Export(websiteToExport);
                }
            }
            catch (Exception exc)
            {
                Events.GetEvent <ErrorNotificationEvent>().Publish(exc);
            }
        }
 void OnWebsiteSelected(WebsiteViewModel vm)
 {
     SelectedWebsite = vm;
 }
        ///// <summary>
        ///// Called when [update website tab context].
        ///// </summary>
        ///// <param name="obj">The object.</param>
        ///// <param name="website"></param>
        ///// <exception cref="System.NotImplementedException"></exception>
        //void OnUpdateWebsiteTabContext(WebsiteViewModel website)
        //{
        //    if (website != null)
        //    {
        //        Website = website.Website;
        //    }
        //}

        private bool CanExecute(WebsiteViewModel vm)
        {
            return(true);
        }