/// <summary>
        /// The set selected new item.
        /// </summary>
        /// <param name="itemNew">
        /// The item new.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        private async Task SetSelectedNewItem(EquipCategory itemNew)
        {
            this._selectedCategoryItem = await AssetClassesCategoryFunctions.GetDataDetailItemSelected(itemNew.EquipCatId);

            var itemExist = this.ListDataGridItem.FirstOrDefault(x => x.EquipCategoryId == itemNew.EquipCatId);

            if (itemExist != null)
            {
                this.ListDataGridItem.Remove(itemExist);
                this.ListDataGridItem.Add(this._selectedCategoryItem);
            }
            else
            {
                this.ListDataGridItem.Add(this._selectedCategoryItem);
            }

            this.ListDataGridItem = this.ListDataGridItem.OrderBy(x => x.Category).ToList();
        }
        /// <summary>
        /// The set selected category item.
        /// </summary>
        /// <param name="value">
        /// The value.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        private async Task SetSelectedCategoryItem(AssetClassesCategoryRowItem value)
        {
            this.SetField(ref this._selectedCategoryItem, value, () => this.SelectedCategoryItem);
            if (value != null)
            {
                if (this.IsCheckedOut)
                {
                    this.SetBusyAction(LoadingText);
                    this.IsCheckedOut = false;
                    this.InModeAdd = false;
                    this.InError = false;
                    this.ValidateNotError();
                    this.CategoryDetailViewModel.ClearNotifyErrors();
                    this.SetBackgroundToNotEdit();
                    this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesCategory, Asset.EnumSteps.Cancel);
                    this.CurrentState = Asset.EnumSteps.SelectedAssetClassesCategoryItem;
                    await this.UnLockAssetClassesCategoryAsync();
                    this.SetActionCommandsAsync();
                }

                // Load data for detail screen
                await this.GetDataSourceForDetailScreen();
                await this.GetDataSourceForFeaturesScreen();
                await this.GetDataSourceForAssetTypesScreen();
                this.ResetBusyAction();
            }

            this.IsChanged = false;
        }
 /// <summary>
 /// The main grid selected item changed.
 /// </summary>
 /// <param name="value">
 /// The value.
 /// </param>
 private async void MainGridSelectedItemChanged(object value)
 {
     if (!this.DynamicMainGridViewModel.IsEnableHoverRow)
     {
         if (!this.InModeBulkUpdate)
         {
             if (value != null)
             {
                 this._selectedCategoryItem = value as AssetClassesCategoryRowItem;
                 await this.OnStepAsync("SelectedAssetClassesCategoryItem");
             }
         }
     }
 }
        /// <summary>
        /// The parse category item detail to save.
        /// </summary>
        /// <returns>
        /// The <see cref="AssetClassesCategoryRowItem"/>.
        /// </returns>
        internal AssetClassesCategoryRowItem ParseCategoryItemDetailToSave()
        {
            var result = new AssetClassesCategoryRowItem
                             {
                                 Category = this.CategoryName,
                                 Enabled = this.IsCategoryEnable
                             };

            if (this.UpdateDepreciationViewModel != null)
            {
                foreach (var item in this.UpdateDepreciationViewModel)
                {
                    if (item.Header.Equals("Book"))
                    {
                        result.BookDepnMethodId = item.ItemChildViewMdoel.SelectedItemCombobox.ItemId;
                        if (item.ItemChildViewMdoel.SalvagePercent != null)
                        {
                            result.SalvagePercent = item.ItemChildViewMdoel.SalvagePercent.Value;
                        }

                        result.BookDepnLife = item.ItemChildViewMdoel.EffectiveMonth;
                        result.BookDepnLifeYear = item.ItemChildViewMdoel.EffectiveYear;
                        result.BookDepnPercent = item.ItemChildViewMdoel.DepnRatePercent;

                        if (item.ItemChildViewMdoel.IsConTractTermActive)
                        {
                            result.BookDepnEffectiveLifeOption = 753;
                        }
                        else if (item.ItemChildViewMdoel.IsDenpRateActive)
                        {
                            result.BookDepnEffectiveLifeOption = 754;
                        }
                        else if (item.ItemChildViewMdoel.IsEffectiveLifeActive)
                        {
                            result.BookDepnEffectiveLifeOption = 755;
                        }
                    }

                    if (item.Header.Equals("Tax"))
                    {
                        result.TaxDepnMethodId = item.ItemChildViewMdoel.SelectedItemCombobox.ItemId;
                        result.TaxDepnLife = item.ItemChildViewMdoel.EffectiveMonth;
                        result.TaxDepnLifeYear = item.ItemChildViewMdoel.EffectiveYear;
                        result.TaxDepnPercent = item.ItemChildViewMdoel.DepnRatePercent;

                        if (item.ItemChildViewMdoel.IsConTractTermActive)
                        {
                            result.TaxDepnEffectiveLifeOption = 753;
                        }
                        else if (item.ItemChildViewMdoel.IsDenpRateActive)
                        {
                            result.TaxDepnEffectiveLifeOption = 754;
                        }
                        else if (item.ItemChildViewMdoel.IsEffectiveLifeActive)
                        {
                            result.TaxDepnEffectiveLifeOption = 755;
                        }
                    }
                }
            }

            return result;
        }
        /// <summary>
        /// The get update depreciation data source.
        /// </summary>
        /// <param name="categoryName">
        /// The category name.
        /// </param>
        /// <param name="itemSelected">
        /// The item selected.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task GetUpdateDepreciationDataSource(string categoryName, AssetClassesCategoryRowItem itemSelected)
        {
            if (itemSelected != null)
            {
                this.CategoryName = categoryName;
                this.IsCategoryEnable = itemSelected.Enabled;

                List<AssetClassesCategoryItemDetail> listBookItemComboBox;
                listBookItemComboBox = await AssetClassesCategoryFunctions.GetListBookDepnMethod();
                listBookItemComboBox.Insert(
                    0,
                    new AssetClassesCategoryItemDetail
                        {
                            Text = "<None>",
                            ItemId = -1,
                        }); 

                this.ItemBookViewModel = new ItemChildViewModel
                {
                    Header = "Book",
                    IsCheckBoxAllShowUp = true,
                    HasSalvage = true,
                    IsConTractTermActive = true,
                    ListItemDepnMethod = listBookItemComboBox,
                    SelectedItemCombobox = listBookItemComboBox.FirstOrDefault(x => x.ItemId == itemSelected.BookDepnMethodId) == null ? listBookItemComboBox.FirstOrDefault() : listBookItemComboBox.FirstOrDefault(x => x.ItemId == itemSelected.BookDepnMethodId),
                    SalvagePercent = itemSelected.SalvagePercent,
                    EffectiveMonth = itemSelected.BookDepnLife,
                    EffectiveYear = itemSelected.BookDepnLifeYear,
                    DepnRatePercent = itemSelected.BookDepnPercent,
                    IsAllDepnMethodChecked = false,
                    IsAllEffectiveLifeChecked = false,
                    IsAllSalvageChecked = false,
                };

                List<AssetClassesCategoryItemDetail> listTaxItemComboBox;
                listTaxItemComboBox = await AssetClassesCategoryFunctions.GetListTaxDepnMethod();
                listTaxItemComboBox.Insert(
                    0,
                    new AssetClassesCategoryItemDetail
                        {
                            Text = "<None>",
                            ItemId = -1,
                        });

                this.ItemTaxViewModel = new ItemChildViewModel
                {
                    Header = "Tax",
                    IsCheckBoxAllShowUp = true,
                    HasSalvage = false,
                    IsConTractTermActive = true,
                    ListItemDepnMethod = listTaxItemComboBox,
                    SelectedItemCombobox = listTaxItemComboBox.FirstOrDefault(),
                    SalvagePercent = itemSelected.SalvagePercent,
                    EffectiveMonth = itemSelected.TaxDepnLife,
                    EffectiveYear = itemSelected.TaxDepnLifeYear,
                    DepnRatePercent = itemSelected.TaxDepnPercent,
                    IsAllDepnMethodChecked = false,
                    IsAllEffectiveLifeChecked = false,
                    IsAllSalvageChecked = false,
                };

                if (this.UpdateDepreciationViewModel != null)
                {
                    var itemBookDepreciationDetailViewModel = this.UpdateDepreciationViewModel.FirstOrDefault(x => x.Header.Equals("Book"));
                    if (itemBookDepreciationDetailViewModel != null)
                    {
                        itemBookDepreciationDetailViewModel.ItemChildViewMdoel = this.ItemBookViewModel;
                    }

                    var itemTaxDepreciationDetailViewModel = this.UpdateDepreciationViewModel.FirstOrDefault(x => x.Header.Equals("Tax"));
                    if (itemTaxDepreciationDetailViewModel != null)
                    {
                        itemTaxDepreciationDetailViewModel.ItemChildViewMdoel = this.ItemTaxViewModel;
                    }
                }
            }

            this.PropertyChanged += this.AssetCategoryUpdateDepreciationViewModel_PropertyChanged;
        }
        /// <summary>
        /// update right hand grid when add or edit a record.
        /// </summary>
        /// <param name="currentStep">
        /// The current Step.
        /// </param>
        /// <param name="item">
        /// The item.
        /// </param>
        private void ContentViewModel_OnPropertyChanged(EnumSteps currentStep, object item)
        {
            switch (Screen)
            {
                #region User
                case EnumScreen.Users:
                    var mainWindowDetailsTabControlViewModelUsers =
                        this.ScreenDetailViewModel as MainWindowDetailsTabControlViewModel;
                    if (mainWindowDetailsTabControlViewModelUsers != null)
                    {
                        var usersViewModel =
                            mainWindowDetailsTabControlViewModelUsers.UsersMainWindowDetailsVm.ScreenDetailViewModel as
                            UsersViewModel;

                        if (usersViewModel != null && usersViewModel.AllUsers != null)
                        {
                            UserMapping userMapping = new UserMapping();

                            var user = usersViewModel.AllUsers.FirstOrDefault(x => x == item as UserDetails);
                                
                            if (user != null)
                            {
                                userMapping.UserEntityId = user.UserEntityId;
                                userMapping.LoginName = user.UserCredentials.LoginName;
                                userMapping.IsEnabled = user.UserCredentials.IsEnabled;
                                DataRow editItem = null;
                                foreach (var row in ToggleViewModel.GridDynamicViewModel.MembersTable.Rows)
                                {
                                    var userDetails = item as UserDetails;
                                    if (userDetails != null && row["UserEntityId"].ToString() == userDetails.UserEntityId.ToString(CultureInfo.InvariantCulture))
                                    {
                                        editItem = row;
                                        break;
                                    }
                                }

                                if (editItem != null)
                                {
                                    ToggleViewModel.GridDynamicViewModel.IsSetSelectedItem = true;
                                    int index = ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.IndexOf(editItem);
                                    ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.RemoveAt(index);
                                    ToggleViewModel.GridDynamicViewModel.InsertRow(index, userMapping);
                                }
                                else
                                {
                                    ToggleViewModel.GridDynamicViewModel.AddRow(userMapping);
                                }
                                ToggleViewModel.SetSelectedItem(user);
                            }
                        }
                    }
                    break;
                #endregion

                #region Group
                case EnumScreen.Groups:
                    var mainWindowDetailsTabControlViewModelGroups =
                        this.ScreenDetailViewModel as MainWindowDetailsTabControlViewModel;
                    if (mainWindowDetailsTabControlViewModelGroups != null)
                    {
                        var groupsViewModel =
                            mainWindowDetailsTabControlViewModelGroups.GroupsMainWindowDetailsVm.ScreenDetailViewModel
                            as GroupsViewModel;

                        if (groupsViewModel != null && groupsViewModel.Groups != null)
                        {
                            GroupMapping groupMapping = new GroupMapping();

                            var group = groupsViewModel.Groups.FirstOrDefault(x => x == item as GroupDetails);
                            if (group != null)
                            {
                                groupMapping.UserEntityId = group.UserEntityId;
                                groupMapping.GroupName = group.LXMGroup.GroupName;
                                DataRow editItem = null;
                                foreach (var row in ToggleViewModel.GridDynamicViewModel.MembersTable.Rows)
                                {
                                    var groupDetails = item as GroupDetails;
                                    if (groupDetails != null && row["UserEntityId"].ToString() == groupDetails.UserEntityId.ToString(CultureInfo.InvariantCulture))
                                    {
                                        editItem = row;
                                        break;
                                    }
                                }

                                if (editItem != null)
                                {
                                    ToggleViewModel.GridDynamicViewModel.IsSetSelectedItem = true;
                                    int index = ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.IndexOf(editItem);
                                    ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.RemoveAt(index);
                                    ToggleViewModel.GridDynamicViewModel.InsertRow(index, groupMapping);
                                }
                                else
                                {
                                    ToggleViewModel.GridDynamicViewModel.AddRow(groupMapping);
                                }
                                ToggleViewModel.SetSelectedItem(group);
                            }
                        }
                    }
                    break;
                #endregion

                #region ColletionQueues
                case EnumScreen.ColletionQueues:
                    var collectionQueueViewModel = this.ScreenDetailViewModel as MainWindowDetailsTabControlCollectionQueueViewModel;
                    QueueDetailsModel queueSource = item as QueueDetailsModel;
                    if (collectionQueueViewModel != null)
                    {
                        var collectionManagementViewModel =
                            collectionQueueViewModel.ListMainWindowDetailsVm.ScreenDetailViewModel as
                            CollectionsManagementViewModel;

                        if (collectionManagementViewModel != null
                            && collectionManagementViewModel.AllQueueManagementDetails != null)
                        {
                            CollectionsManagementMapping collectionsManagementMapping =
                                new CollectionsManagementMapping();
                            
                            var queue =
                                collectionManagementViewModel.AllQueueManagementDetails.FirstOrDefault(d => queueSource != null && d.QueueDetailId == queueSource.QueueDetailId);
                            if (queue != null)
                            {
                                collectionsManagementMapping.Enabled = queue.CollectionQueue.Enabled;
                                collectionsManagementMapping.ID = queue.CollectionQueue.ID;
                                collectionsManagementMapping.QueueName = queue.CollectionQueue.QueueName;
                                collectionsManagementMapping.AssignmentOrder = queue.CollectionQueue.AssignmentOrder;
                                DataRow editItem = null;
                                foreach (var row in ToggleViewModel.GridDynamicViewModel.MembersTable.Rows)
                                {
                                    var queueDetailsModel = item as QueueDetailsModel;
                                    if (queueDetailsModel != null && row["ID"].ToString() == queueDetailsModel.QueueDetailId.ToString(CultureInfo.InvariantCulture))
                                    {
                                        editItem = row;
                                        break;
                                    }
                                }

                                if (editItem != null)
                                {
                                    ToggleViewModel.GridDynamicViewModel.IsSetSelectedItem = true;
                                    int index = ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.IndexOf(editItem);
                                    ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.RemoveAt(index);
                                    ToggleViewModel.GridDynamicViewModel.InsertRow(index, collectionsManagementMapping);
                                }
                                else
                                {
                                    ToggleViewModel.GridDynamicViewModel.AddRow(collectionsManagementMapping);
                                }
                                ToggleViewModel.SetSelectedItem(queue);
                            }
                        }
                    }
                    break;
                #endregion

                #region CollectionAssignment
                case EnumScreen.CollectionAssignment:
                    var collectionAssignmentViewModel =
                        this.ScreenDetailViewModel as MainWindowDetailsViewModel;
                    if (collectionAssignmentViewModel != null)
                    {
                        var viewModel = collectionAssignmentViewModel.ScreenDetailViewModel as CollectionsAssignmentViewModel;
                        CollectionAssignmentModel itemSource = item as CollectionAssignmentModel;
                        if (viewModel != null && itemSource != null)
                        {
                            CollectionAssignmentMapping collectionAssignmentMapping =
                                new CollectionAssignmentMapping();
                            
                            var collectionAssignment =
                                viewModel.FilteredItems.FirstOrDefault(d => d.QueueID == itemSource.QueueID && d.ContractId == itemSource.ContractId);

                            if (collectionAssignment != null)
                            {
                                collectionAssignmentMapping.QueueID = collectionAssignment.QueueID;
                                collectionAssignmentMapping.FollowUpDate = collectionAssignment.FollowUpDate;
                                collectionAssignmentMapping.ContractId = collectionAssignment.ContractId;
                                DataRow editItem = null;
                                foreach (var row in this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows)
                                {
                                    var collectionAssignmentModel = item as CollectionAssignmentModel;
                                    if (row["QueueID"].ToString() == collectionAssignmentModel.QueueID.ToString(CultureInfo.InvariantCulture) && row["ContractId"].ToString() == collectionAssignmentModel.ContractId.ToString(CultureInfo.InvariantCulture))
                                    {
                                        editItem = row;
                                        break;
                                    }
                                }

                                if (editItem != null)
                                {
                                    this.ToggleViewModel.GridDynamicViewModel.IsSetSelectedItem = true;
                                    int index = this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.IndexOf(editItem);
                                    this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.RemoveAt(index);
                                    this.ToggleViewModel.GridDynamicViewModel.InsertRow(index, collectionAssignmentMapping);
                                }
                                else
                                {
                                    this.ToggleViewModel.GridDynamicViewModel.AddRow(collectionAssignmentMapping);
                                }
                                this.ToggleViewModel.SetSelectedItem(collectionAssignment);
                            }
                            
                        }
                    }
                    break;
                #endregion

                #region FundingSummary
                case EnumScreen.FundingSummary:
                    var fundingViewModel =
                        this.ScreenDetailViewModel as MainWindowDetailsViewModel;
                    if (fundingViewModel != null)
                    {
                        var fundingSummaryViewModel =
                            fundingViewModel.ScreenDetailViewModel as
                            FundingSummaryViewModel;
                        
                        FundingSummaryMaping fundingSummaryMapping =
                                new FundingSummaryMaping();
                        if (fundingSummaryViewModel != null)
                        {
                            var fundingSummary =
                                fundingSummaryViewModel.TrancheSummary.FirstOrDefault(x => x.TrancheId == (int)item);
                            
                            if (fundingSummary != null)
                            {
                                fundingSummaryMapping.TrancheId = fundingSummary.TrancheId;
                                fundingSummaryMapping.FunderName = fundingSummary.FunderName;
                                DataRow editItem = null;
                                foreach (var row in this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows)
                                {
                                    if (row["TrancheId"].ToString() == item.ToString())
                                    {
                                        editItem = row;
                                        break;
                                    }
                                }

                                if (editItem != null)
                                {
                                    this.ToggleViewModel.GridDynamicViewModel.IsSetSelectedItem = true;
                                    int index = this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.IndexOf(editItem);
                                    this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.RemoveAt(index);                                    
                                    this.ToggleViewModel.GridDynamicViewModel.InsertRow(
                                            index,
                                            fundingSummaryMapping);
                                }
                                else
                                {
                                    this.ToggleViewModel.GridDynamicViewModel.AddRow(fundingSummaryMapping);
                                }
                                this.ToggleViewModel.SetSelectedItem(fundingSummary);
                            }
                            else
                            {
                                if (currentStep == EnumSteps.Delete)
                                {
                                    DataRow editItem = null;
                                    foreach (var row in this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows)
                                    {
                                        if (row["TrancheId"].ToString() == item.ToString())
                                        {
                                            editItem = row;
                                            break;
                                        }
                                    }
                                    if (editItem != null)
                                    {
                                        this.ToggleViewModel.GridDynamicViewModel.IsSetSelectedItem = false;
                                        int index = this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.IndexOf(editItem);
                                        this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.RemoveAt(index);
                                    }
                                    this.ToggleViewModel.SetSelectedItem(null);
                                }
                            }
                        }
                    }
                    break;
                #endregion

                #region Asset Class Category
                case EnumScreen.AssetClassesCategory:
                    var mainWindowDetailsTabControlViewModelCategory =
                        this.ScreenDetailViewModel as MainAssetClassesViewModel;
                    if (mainWindowDetailsTabControlViewModelCategory != null)
                    {
                        var categoryViewModel =
                            mainWindowDetailsTabControlViewModelCategory.AssetCategoryViewModel.ScreenDetailViewModel as
                            AssetClassesCategoryViewModel;

                        if (categoryViewModel != null && categoryViewModel.ListDataGridItem != null)
                        {
                            AssetClassesCategoryRowItem categoryMapping = new AssetClassesCategoryRowItem();

                            var category = categoryViewModel.ListDataGridItem.FirstOrDefault(x => x.EquipCategoryId == (item as EquipCategory).EquipCatId);

                            if (category != null)
                            {
                                categoryMapping.EquipCategoryId = (item as EquipCategory).EquipCatId;
                                categoryMapping.Category = (item as EquipCategory).Description;
                                categoryMapping.Enabled = (item as EquipCategory).Enabled;
                                DataRow editItem = null;
                                foreach (var row in ToggleViewModel.GridDynamicViewModel.MembersTable.Rows)
                                {
                                    if (row["EquipCategoryId"].ToString() == (item as EquipCategory).EquipCatId.ToString())
                                    {
                                        editItem = row;
                                        break;
                                    }
                                }

                                if (editItem != null)
                                {
                                    ToggleViewModel.GridDynamicViewModel.IsSetSelectedItem = true;
                                    int index = ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.IndexOf(editItem);
                                    ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.RemoveAt(index);
                                    ToggleViewModel.GridDynamicViewModel.InsertRow(index, categoryMapping);
                                }
                                else
                                {
                                    ToggleViewModel.GridDynamicViewModel.AddRow(categoryMapping);
                                }
                                ToggleViewModel.SetSelectedItem(item);
                            }
                        }
                    }
                    break;
                #endregion

                #region Asset Class Type
                case EnumScreen.AssetClassesType:
                    var mainWindowDetailsTabControlViewModelType =
                        this.ScreenDetailViewModel as MainAssetClassesViewModel;
                    if (mainWindowDetailsTabControlViewModelType != null)
                    {
                        var typeViewModel =
                            mainWindowDetailsTabControlViewModelType.AssetClassesTypeViewModel.ScreenDetailViewModel as AssetClassesTypeViewModel;

                        if (typeViewModel != null && typeViewModel.ListDataGridItem != null)
                        {
                            AssetClassesTypeRowItem typeMapping = new AssetClassesTypeRowItem();

                            var type = typeViewModel.ListDataGridItem.FirstOrDefault(x => x.EquipTypeId == (item as EquipType).EquipTypeId);

                            if (type != null)
                            {
                                typeMapping.EquipTypeId = (item as EquipType).EquipTypeId;
                                typeMapping.TypeDescription = (item as EquipType).Description;
                                typeMapping.Enabled = (item as EquipType).Enabled;
                                DataRow editItem = null;
                                foreach (var row in ToggleViewModel.GridDynamicViewModel.MembersTable.Rows)
                                {
                                    if (row["EquipTypeId"].ToString() == (item as EquipType).EquipTypeId.ToString())
                                    {
                                        editItem = row;
                                        break;
                                    }
                                }

                                if (editItem != null)
                                {
                                    ToggleViewModel.GridDynamicViewModel.IsSetSelectedItem = true;
                                    int index = ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.IndexOf(editItem);
                                    ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.RemoveAt(index);
                                    ToggleViewModel.GridDynamicViewModel.InsertRow(index, typeMapping);
                                }
                                else
                                {
                                    ToggleViewModel.GridDynamicViewModel.AddRow(typeMapping);
                                }
                                ToggleViewModel.SetSelectedItem(item);
                            }
                        }
                    }
                    break;
                #endregion

                #region AssetClassesModel
                case EnumScreen.AssetClassesModel:
                    var modelViewModel = this.ScreenDetailViewModel as MainAssetClassesViewModel;
                    if (modelViewModel != null)
                    {
                        var modelDetailViewModel = modelViewModel.AssetClassesModelViewModel.ScreenDetailViewModel
                            as AssetClassesModelViewModel;
                        AssetClassesModelRowItem assetModelMapping=new AssetClassesModelRowItem();
                        if (modelDetailViewModel != null)
                        {
                            var assetDetail =
                                modelDetailViewModel.AllAssetModel.FirstOrDefault(x=> x.EquipModelId == ((EquipModel)item).EquipModelId);

                            if (assetDetail != null)
                            {
                                assetModelMapping.EquipModelId = assetDetail.EquipModelId;
                                assetModelMapping.Description = assetDetail.Description;
                                assetModelMapping.Enabled = assetDetail.Enabled;
                                DataRow editItem = null;
                                foreach (var row in this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows)
                                {
                                    if (row["EquipModelId"].ToString() == ((EquipModel)item).EquipModelId.ToString())
                                    {
                                        editItem = row;
                                        break;
                                    }
                                }

                                if (editItem != null)
                                {
                                    this.ToggleViewModel.GridDynamicViewModel.IsSetSelectedItem = true;
                                    int index = this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.IndexOf(editItem);
                                    this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.RemoveAt(index);
                                    this.ToggleViewModel.GridDynamicViewModel.InsertRow(
                                            index,
                                            assetModelMapping);
                                }
                                else
                                {
                                    this.ToggleViewModel.GridDynamicViewModel.AddRow(assetModelMapping);
                                }
                                this.ToggleViewModel.SetSelectedItem(item);
                            }
                        }
                    }
                    break;
                #endregion

                #region AssetFeatures
                case EnumScreen.AssetFeatures:
                    var featureViewModel =
                        this.ScreenDetailViewModel as MainWindowDetailsViewModel;
                    if (featureViewModel != null)
                    {
                        var assetFeatureViewModel =
                            featureViewModel.ScreenDetailViewModel as
                            AssetFeaturesViewModel;

                        AssetFeatureTypeRowItem featureTypeMapping =
                                new AssetFeatureTypeRowItem();
                        if (assetFeatureViewModel != null)
                        {
                            var feature =
                                assetFeatureViewModel.AllFeatureTypes.FirstOrDefault(x => x.FeatureTypeId == (int)item);

                            if (feature != null)
                            {
                                featureTypeMapping.FeatureTypeId = feature.FeatureTypeId;
                                featureTypeMapping.FeatureName = feature.FeatureName;
                                featureTypeMapping.Enabled = feature.Enabled;
                                featureTypeMapping.RequiredLength = feature.RequiredLength == -1 ? "N/A" : feature.RequiredLength.ToString();
                                DataRow editItem = null;
                                foreach (var row in this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows)
                                {
                                    if (row["FeatureTypeId"].ToString() == item.ToString())
                                    {
                                        editItem = row;
                                        break;
                                    }
                                }

                                if (editItem != null)
                                {
                                    this.ToggleViewModel.GridDynamicViewModel.IsSetSelectedItem = true;
                                    int index = this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.IndexOf(editItem);
                                    this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.RemoveAt(index);
                                    this.ToggleViewModel.GridDynamicViewModel.InsertRow(
                                            index,
                                            featureTypeMapping);
                                }
                                else
                                {
                                    this.ToggleViewModel.GridDynamicViewModel.AddRow(featureTypeMapping);
                                }
                                this.ToggleViewModel.SetSelectedItem(feature);
                            }
                            else
                            {
                                if (currentStep == EnumSteps.Delete)
                                {
                                    DataRow editItem = null;
                                    foreach (var row in this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows)
                                    {
                                        if (row["FeatureTypeId"].ToString() == item.ToString())
                                        {
                                            editItem = row;
                                            break;
                                        }
                                    }
                                    if (editItem != null)
                                    {
                                        this.ToggleViewModel.GridDynamicViewModel.IsSetSelectedItem = false;
                                        int index = this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.IndexOf(editItem);
                                        this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.RemoveAt(index);
                                    }
                                    this.ToggleViewModel.SetSelectedItem(null);
                                }
                            }
                        }
                    }
                    break;
                #endregion

                #region AssetClassesMake
                case EnumScreen.AssetClassesMake:
                    var makeViewModel =
                        this.ScreenDetailViewModel as MainAssetClassesViewModel;
                    if (makeViewModel != null)
                    {
                        var assetClassesMakeViewModel = makeViewModel.AssetClassesMakeViewModel.ScreenDetailViewModel as AssetClassesMakeViewModel;

                        AssetClassesMakeRowItem makeTypeMapping = new AssetClassesMakeRowItem();
                        if (assetClassesMakeViewModel != null)
                        {
                            var make =
                                assetClassesMakeViewModel.AllAssetMake.FirstOrDefault(x => x.EquipMakeId == (int)item);

                            if (make != null)
                            {
                                makeTypeMapping.EquipMakeId = make.EquipMakeId;
                                makeTypeMapping.Description = make.Description;
                                makeTypeMapping.Enabled = make.Enabled;
                                DataRow editItem = null;
                                foreach (var row in this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows)
                                {
                                    if (row["EquipMakeId"].ToString() == item.ToString())
                                    {
                                        editItem = row;
                                        break;
                                    }
                                }

                                if (editItem != null)
                                {
                                    this.ToggleViewModel.GridDynamicViewModel.IsSetSelectedItem = true;
                                    int index =
                                        this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.IndexOf(editItem);
                                    this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.RemoveAt(index);
                                    this.ToggleViewModel.GridDynamicViewModel.InsertRow(index, makeTypeMapping);
                                }
                                else
                                {
                                    this.ToggleViewModel.GridDynamicViewModel.AddRow(makeTypeMapping);
                                }
                                this.ToggleViewModel.SetSelectedItem(make);
                            }
                        }
                    }
                    break;
                #endregion

                #region Asset Collateral Classes
                case EnumScreen.AssetCollateralClasses:
                    var collateralViewModel =
                        this.ScreenDetailViewModel as MainWindowDetailsViewModel;
                    if (collateralViewModel != null)
                    {
                        var assetCollateralViewModel =
                            collateralViewModel.ScreenDetailViewModel as
                            AssetCollateralClassesViewModel;

                        AssetCollateralRowItem collateralMapping =
                                new AssetCollateralRowItem();
                        if (assetCollateralViewModel != null)
                        {
                            var collateral =
                                assetCollateralViewModel.AllCollateralClasses.FirstOrDefault(x => x.CollateralClassID == (int)item);

                            if (collateral != null)
                            {
                                collateralMapping.Description = collateral.Description;
                                collateralMapping.CollateralClassID = collateral.CollateralClassID;
                                DataRow editItem = null;
                                foreach (var row in this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows)
                                {
                                    if (row["CollateralClassID"].ToString() == item.ToString())
                                    {
                                        editItem = row;
                                        break;
                                    }
                                }

                                if (editItem != null)
                                {
                                    this.ToggleViewModel.GridDynamicViewModel.IsSetSelectedItem = true;
                                    int index = this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.IndexOf(editItem);
                                    this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.RemoveAt(index);
                                    this.ToggleViewModel.GridDynamicViewModel.InsertRow(
                                            index,
                                            collateralMapping);
                                }
                                else
                                {
                                    this.ToggleViewModel.GridDynamicViewModel.AddRow(collateralMapping);
                                }
                                this.ToggleViewModel.SetSelectedItem(collateral);
                            }
                        }
                    }
                    break;
                #endregion

                #region AssetRegister
                case EnumScreen.AssetRegisters:
                    var registerViewModel =
                        this.ScreenDetailViewModel as MainWindowDetailsViewModel;
                    if (registerViewModel != null)
                    {
                        var assetRegisterViewModel =
                            registerViewModel.ScreenDetailViewModel as AssetRegistersViewModel;

                        AssetRegisterRowItem registerMapping = new AssetRegisterRowItem();
                        if (assetRegisterViewModel != null)
                        {
                            var register = assetRegisterViewModel.AllAssetRegister.FirstOrDefault(x => x.ID == (int)item);

                            if (register != null)
                            {
                                registerMapping.ID = register.ID;
                                registerMapping.RegisterName = register.RegisterName;
                                registerMapping.InternalOnly = register.InternalOnly;

                                DataRow editItem = null;
                                foreach (var row in this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows)
                                {
                                    if (row["ID"].ToString() == item.ToString())
                                    {
                                        editItem = row;
                                        break;
                                    }
                                }

                                if (editItem != null)
                                {
                                    this.ToggleViewModel.GridDynamicViewModel.IsSetSelectedItem = true;
                                    int index = this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.IndexOf(editItem);
                                    this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.RemoveAt(index);
                                    this.ToggleViewModel.GridDynamicViewModel.InsertRow(index, registerMapping);
                                }
                                else
                                {
                                    this.ToggleViewModel.GridDynamicViewModel.AddRow(registerMapping);
                                }
                                this.ToggleViewModel.SetSelectedItem(register);
                            }
                            else
                            {
                                DataRow editItem = null;
                                foreach (var row in this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows)
                                {
                                    if (row["ID"].ToString() == item.ToString())
                                    {
                                        editItem = row;
                                        break;
                                    }
                                }
                                if (editItem != null)
                                {
                                    this.ToggleViewModel.GridDynamicViewModel.IsSetSelectedItem = false;
                                    int index = this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.IndexOf(editItem);
                                    this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.RemoveAt(index);
                                }
                                this.ToggleViewModel.SetSelectedItem(null);
                            }
                        }
                    }
                    break;
                #endregion

                #region RegisteredAsset
                case EnumScreen.RegisteredAsset:
                    var registeredAssetViewModel =
                        this.ScreenDetailViewModel as MainWindowDetailsViewModel;
                    if (registeredAssetViewModel != null)
                    {
                        var assetRegisterViewModel =
                            registeredAssetViewModel.ScreenDetailViewModel as RegisteredAssetViewModel;

                        RegisteredAssetRowItem registerMapping = new RegisteredAssetRowItem();
                        if (assetRegisterViewModel != null)
                        {
                            var register = assetRegisterViewModel.AllRegisteredAsset.FirstOrDefault(x => x.Id == (int)item);

                            if (register != null)
                            {
                                registerMapping.Id = register.Id;
                                registerMapping.AssetRegisterId = register.AssetRegisterId;
                                registerMapping.AssetState = register.AssetState;

                                DataRow editItem = null;
                                foreach (var row in this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows)
                                {
                                    if (row["Id"].ToString() == item.ToString())
                                    {
                                        editItem = row;
                                        break;
                                    }
                                }

                                if (editItem != null)
                                {
                                    this.ToggleViewModel.GridDynamicViewModel.IsSetSelectedItem = true;
                                    int index = this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.IndexOf(editItem);
                                    this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.RemoveAt(index);
                                    this.ToggleViewModel.GridDynamicViewModel.InsertRow(index, registerMapping);
                                }
                                else
                                {
                                    this.ToggleViewModel.GridDynamicViewModel.AddRow(registerMapping);
                                }
                                this.ToggleViewModel.SetSelectedItem(register);
                            }
                            else
                            {
                                DataRow editItem = null;
                                foreach (var row in this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows)
                                {
                                    if (row["Id"].ToString() == item.ToString())
                                    {
                                        editItem = row;
                                        break;
                                    }
                                }
                                if (editItem != null)
                                {
                                    this.ToggleViewModel.GridDynamicViewModel.IsSetSelectedItem = false;
                                    int index = this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.IndexOf(editItem);
                                    this.ToggleViewModel.GridDynamicViewModel.MembersTable.Rows.RemoveAt(index);
                                }
                                this.ToggleViewModel.SetSelectedItem(null);
                            }
                        }
                    }
                    break;
                #endregion
            }
        }