/// <summary>
        /// Closes the specified view.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <param name="viewId">The view identifier.</param>
        public virtual void Close(dynamic viewModel, string viewId)
        {
            var region = RegionManager.Regions[Regions.MainRegion];

            for (var i = 0; i < region.Views.Count(); i++)
            {
                var v = (UserControl)region.Views.ElementAt(i);
                var d = v?.DataContext;
                if (d == null)
                {
                    continue;
                }
                if (d.GetType() != viewModel.GetType())
                {
                    continue;
                }
                if (((NavigationBaseViewModel)d).ViewId != viewId)
                {
                    continue;
                }
                try
                {
                    var fe = (FrameworkElement)v;
                    region.Remove(fe);
                }
                catch (Exception ex)
                {
                    ErrorTracker.LogError(new ErrorModel(ex, Environment.UserName, "NavigationBaseViewModel.Close"));
                    Logger.Log(LogLevel.Error, ex.Message.Trim(), ex.Data);
                }
            }
        }
        /// <summary>
        /// Navigates to the specified view with parameters and closes the current view.
        /// </summary>
        /// <param name="navModel">The nav model.</param>
        public virtual void NavigateWithClose(INavModel navModel)
        {
            var message = $"Navigating to {navModel.ViewName} with the following parameters:\n";

            message = navModel.NavigationParameters.Aggregate(message, (current, o) => current + $"{o.Key} - {o.Value}\n");
            Logger.Log(LogLevel.Info, message);
            try
            {
                RegionManager.RequestNavigate(Regions.MainRegion, navModel.ViewName, NavigationCallback,
                                              navModel.NavigationParameters);
                var vm = navModel.ViewModel as NavigationBaseViewModel;
                if (vm == null)
                {
                    Debug.WriteLine("VM NULL!!");
                    return;
                }
                navModel.ViewId = vm.ViewId;
                Close(navModel);
            }
            catch (Exception ex)
            {
                ErrorTracker.LogError(new ErrorModel(ex, Environment.UserName,
                                                     "NavigationBaseViewModel.NavigateWithClose"));
                Logger.Log(LogLevel.Error, "Failed to navigate to view. Location: NavigationBaseViewModel.NavigateWithClose");
                Logger.Log(LogLevel.Error, ex, ex.Message.Trim(), ex.StackTrace);
            }
        }
 /// <summary>
 /// Navigates the specified view.
 /// </summary>
 /// <param name="navModel">The nav model.</param>
 public virtual void Navigate(INavModel navModel)
 {
     Logger.Log(LogLevel.Info, $"Navigating to {navModel.ViewName}.");
     try
     {
         RegionManager.RequestNavigate(Regions.MainRegion, navModel.ViewName, NavigationCallback);
     }
     catch (Exception ex)
     {
         ErrorTracker.LogError(new ErrorModel(ex, Environment.UserName, "NavigationBaseViewModel.Navigate"));
         Logger.Log(LogLevel.Error, "Failed to navigate to view. Location: NavigationBaseViewModel.Navigate");
         Logger.Log(LogLevel.Error, ex, ex.Message.Trim(), ex.StackTrace);
     }
 }