示例#1
0
        private void EmployeeSelected(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return;
            }

            Employee selectedEmployee = _dataService.GetEmployees().FirstOrDefault(item => item.Id == id);

            IRegion mainRegion = _regionManager.Regions[RegionNames.MainRegion];

            if (mainRegion == null)
            {
                return;
            }

            EmployeeSummaryView view = mainRegion.GetView(nameof(EmployeeSummaryView)) as EmployeeSummaryView;

            if (view == null)
            {
                view = _container.Resolve <EmployeeSummaryView>();
                mainRegion.Add(view, nameof(EmployeeSummaryView));
            }
            else
            {
                mainRegion.Activate(view);
            }

            if (view.DataContext is EmployeeSummaryViewModel viewModel)
            {
                viewModel.CurrentEmployee = selectedEmployee;
            }
        }
示例#2
0
        /// <summary>
        /// Called when a new employee is selected. This method uses
        /// view injection to programmatically
        /// </summary>
        private void EmployeeSelected(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return;
            }

            // Get the employee entity with the selected ID.
            Employee selectedEmployee = this.dataService.GetEmployees().FirstOrDefault(item => item.Id == id);

            // TODO: 05 - The MainRegionController displays the EmployeeSummaryView in the Main region when an employee is first selected.

            // Get a reference to the main region.
            IRegion mainRegion = this.regionManager.Regions[RegionNames.MainRegion];

            if (mainRegion == null)
            {
                return;
            }

            // Check to see if we need to create an instance of the view.
            EmployeeSummaryView view = mainRegion.GetView("EmployeeSummaryView") as EmployeeSummaryView;

            if (view == null)
            {
                // Create a new instance of the EmployeeDetailsView using the Unity container.
                view = this.container.Resolve <EmployeeSummaryView>();

                // Add the view to the main region. This automatically activates the view too.
                mainRegion.Add(view, "EmployeeSummaryView");
            }
            else
            {
                // The view has already been added to the region so just activate it.
                mainRegion.Activate(view);
            }

            // Set the current employee property on the view model.
            EmployeeSummaryViewModel viewModel = view.DataContext as EmployeeSummaryViewModel;

            if (viewModel != null)
            {
                viewModel.CurrentEmployee = selectedEmployee;
            }
        }