private async void Collateral_Loaded(object sender, RoutedEventArgs e)
 {
     AssetCollateralRowItem item1 = new AssetCollateralRowItem
     {
         CollateralClassID = 601,
         Description = "Agriculture"
     };
     AssetCollateralRowItem item2 = new AssetCollateralRowItem
     {
         CollateralClassID = 602,
         Description = "Crops"
     };
     ObservableCollection<AssetCollateralRowItem> typeItems;
     typeItems = new ObservableCollection<AssetCollateralRowItem>();
     typeItems.Add(item1);
     typeItems.Add(item2);
     this.DataContext = new AssetCollateralAssignTypeViewModel();
     await (DataContext as AssetCollateralAssignTypeViewModel).GetListCollateralItems(typeItems);
 }
        /// <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
            }
        }
        public async Task GetDataSourceForDetailScreen(AssetCollateralRowItem selectedCollateral)
        {
            if (selectedCollateral != null)
            {
                this.AssetCollateralName = selectedCollateral.Description;
                
                this.DynamicAssignAssetTypeViewModel = new DynamicGridViewModel(typeof(AssetClassesTypeRowItem));
                //DynamicAssignAssetTypeViewModel.IsSelectAllRow = false;
                this.DynamicAssignAssetTypeViewModel.GridColumns = new List<DynamicColumn>
                                                                      {
                                                                          new DynamicColumn
                                                                              {
                                                                                  ColumnName = "TypeDescription",
                                                                                  Header = "ASSET TYPES",
                                                                                  IsSelectedColumn = true,
                                                                                  Width = 400,
                                                                                  MinWidth = 90,
                                                                              },
                                                                      };
                List<AssetClassesTypeRowItem> data =
                    await AssetCollateralClassesFunction.GetDataOnEquipTypeGrid(selectedCollateral.CollateralClassID);

                data = (from item in data
                        orderby item.IsSelected descending, item.TypeDescription
                        select item).ToList();

                this.DynamicAssignAssetTypeViewModel.GridDataRows = data.ToList<object>();
                this.DynamicAssignAssetTypeViewModel.IsEnableHoverRow = false;
                this.DynamicAssignAssetTypeViewModel.LoadRadGridView();
                if (this.DynamicAssignAssetTypeViewModel.SelectedItems != null && this.DynamicAssignAssetTypeViewModel.MembersTable.Rows != null
                    && this.DynamicAssignAssetTypeViewModel.SelectedItems.Count() == this.DynamicAssignAssetTypeViewModel.MembersTable.Rows.Count())
                {
                    this._isSelectAllRowType = true;
                    this.OnPropertyChanged(() => this.IsSelectAllRowType);
                }
                else
                {
                    this._isSelectAllRowType = false;
                    this.OnPropertyChanged(() => this.IsSelectAllRowType);
                }
            }
        }
 /// <summary>
 /// The get data source for asset types screen.
 /// </summary>
 /// <returns>
 /// The <see cref="Task"/>.
 /// </returns>
 private async Task GetDataSourceForAssetTypesScreen()
 {
     if (this.SelectedCollateral != null)
     {
         AssetCollateralRowItem collateralRow = new AssetCollateralRowItem
         {
             Description = this.SelectedCollateral.Description,
             CollateralClassID = this.SelectedCollateral.CollateralClassID
         };
         await this.AssetCollateralTypeViewModel.GetDataSourceForDetailScreen(collateralRow);
         this.AssetCollateralTypeViewModel.DetailContentChanged = this.AssetClassesTypeDetailViewModel_PropertyChanged;
     }
 }