public override async Task OnStepAsync(object stepName)
        {
            bool canProcess = true;
            EnumSteps step = (EnumSteps)Enum.Parse(typeof(EnumSteps), stepName.ToString());
            switch (step)
            {
                case EnumSteps.Start:                    
                    this._CurrentEnumStep = EnumSteps.Start;
                    this.SystemSettings = await SystemSettingsFunctions.ReadSystemSettingsAsync();
                    if (this.SystemSettings == null)
                    {
                        this.SystemSettings = new LXMUserSystemSetting();
                    }
                    this.SetActionCommandsAsync();
                    break;
                case EnumSteps.Edit:
                    this.GridStyle = (Brush)Application.Current.FindResource("GridStyleEdit");
                    this.RaiseActionsWhenChangeStep(EnumScreen.SecuritySetting, EnumSteps.Edit);
                    this._CurrentEnumStep = EnumSteps.Edit;
                    this.IsCheckedOut = true;
                    this.SetActionCommandsAsync();
                    break;
                case EnumSteps.Save:
                    this.Validate();

                    if (this.HasErrors == false)
                    {
                        this.ValidateNotError();
                        this.GridStyle = (Brush)Application.Current.FindResource("GridStyleNotEdit");
                        this._CurrentEnumStep = EnumSteps.Save;
                        SystemSettingsFunctions.UpdateSystemSettings(this.SystemSettings);
                        this.RaiseActionsWhenChangeStep(EnumScreen.SecuritySetting, EnumSteps.Save);
                        this.IsCheckedOut = false;
                        this.IsChanged = false;
                        this.SetActionCommandsAsync();
                    }
                    else
                    {
                        this._CurrentEnumStep = EnumSteps.Error;
                        this.SetActionCommandsAsync();
                        this.OnErrorHyperlinkSelected();
                    }
                    break;
                case EnumSteps.Cancel:
                    canProcess = await this.CheckIfUnSavedChanges();
                    if (canProcess)
                    {
                        this.GridStyle = (Brush)Application.Current.FindResource("GridStyleNotEdit");
                        this._CurrentEnumStep = EnumSteps.Cancel;
                        this.SystemSettings = await SystemSettingsFunctions.ReadSystemSettingsAsync();
                        this.RaiseActionsWhenChangeStep(EnumScreen.SecuritySetting, EnumSteps.Cancel);
                        this.IsCheckedOut = false;
                        this.IsChanged = false;
                        this.SetActionCommandsAsync();
                    }
                    break;
                case EnumSteps.Error:
                    NotificationErrorView errorPopup = new NotificationErrorView();
                    NotificationErrorViewModel errorPopupViewModel = new NotificationErrorViewModel();
                    errorPopupViewModel.listCustomHyperlink = this.ListErrorHyperlink;
                    errorPopup.DataContext = errorPopupViewModel;

                    errorPopup.Style = (Style)Application.Current.FindResource("RadWindowStyleNew");

                    errorPopup.ShowDialog();
                    break;
            }
        }
        /// <summary>
        /// The on step async.
        /// </summary>
        /// <param name="stepName">
        /// The step name.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public override async Task OnStepAsync(object stepName)
        {
            this._currentEnumStep = (Asset.EnumSteps)Enum.Parse(typeof(Asset.EnumSteps), stepName.ToString());
            switch (this._currentEnumStep)
            {
                case Asset.EnumSteps.Start:
                    this.SetBusyAction(LoadingText);
                    this.GetPermission();
                    this.CurrentState = Asset.EnumSteps.Start;
                    this.OnStepChanged("MainViewState");
                    this.ActiveViewModel = this;
                    await this.LoadData();
                    await this.GenerateDataForAllControl();
                    this.ResetBusyAction();
                    break;
                case Asset.EnumSteps.MainViewState:
                    this.CurrentState = Asset.EnumSteps.MainViewState;
                    this.OnStepChanged("MainViewState");
                    break;
                case Asset.EnumSteps.SelectedAssetClassesCategoryItem:
                    this.SetBusyAction(LoadingText);
                    this.CurrentState = Asset.EnumSteps.SelectedAssetClassesCategoryItem;
                    await this.GetDataSourceForDetailScreen();
                    if (!this.OnLoaded)
                    {
                        this.OnStepChanged("MainContentState");
                        this.OnLoaded = true;
                    }

                    await this.GetDataSourceForFeaturesScreen();
                    await this.GetDataSourceForAssetTypesScreen();
                    this.ResetBusyAction();
                    this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesCategory, Asset.EnumSteps.SelectedAssetClassesCategoryItem, this.DynamicMainGridViewModel.SelectedItem);
                    break;
                case Asset.EnumSteps.AssetClassesCategoryDetailState:
                    this.CurrentState = Asset.EnumSteps.AssetClassesCategoryDetailState;
                    this.CurrentTab = Asset.EnumSteps.AssetClassesCategoryDetailState;
                    if (this.OnStoryBoardChanged != null)
                    {
                        this.OnStoryBoardChanged(this._currentEnumStep.ToString());
                    }

                    break;
                case Asset.EnumSteps.AssetClassesCategoryFeaturesState:
                    this.CurrentState = Asset.EnumSteps.AssetClassesCategoryFeaturesState;
                    this.CurrentTab = Asset.EnumSteps.AssetClassesCategoryFeaturesState;
                    if (this.OnStoryBoardChanged != null)
                    {
                        this.OnStoryBoardChanged(this._currentEnumStep.ToString());
                    }

                    break;
                case Asset.EnumSteps.AssetClassesCategoryAssetTypesState:
                    bool canProcess = true;
                    if (this.IsCheckedOut)
                    {
                        canProcess = await this.LockAssetClassesCategoryAsync();
                    }

                    if (canProcess)
                    {
                        if (this.ListItemLocks.Count > 0)
                        {
                            this.IsCheckedOut = true;
                        }

                        this.CurrentState = Asset.EnumSteps.AssetClassesCategoryAssetTypesState;
                        this.CurrentTab = Asset.EnumSteps.AssetClassesCategoryAssetTypesState;
                        if (this.OnStoryBoardChanged != null)
                        {
                            this.OnStoryBoardChanged(this._currentEnumStep.ToString());
                        }
                    }
                    else
                    {
                        this.IsCheckedOut = true;
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesCategory, EnumSteps.SelectOldTabHyperlink);
                    }

                    break;
                case Asset.EnumSteps.AssetClassesCategoryAssignFeaturesState:
                    this.SetBusyAction(LoadingText);
                    if (this.DynamicMainGridViewModel.SelectedItems.Count() > 0)
                    {
                        if (await this.LockAssetClassesCategoryAsync())
                        {
                            if (this.OnStoryBoardChanged != null)
                            {
                                this.OnStoryBoardChanged(this._currentEnumStep.ToString());
                            }

                            this.OnStepChanged("BulkUpdateState");
                            this.SetBackgroundToEdit();
                            this.CurrentState = Asset.EnumSteps.AssetClassesCategoryAssignFeaturesState;
                            this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesCategory, Asset.EnumSteps.AssetClassesCategoryAssignFeaturesState);
                            await this.GetListFeatureItemsForAssignFeaturesScreen();
                            this.IsCheckedOut = true;
                        }
                    }
                    else
                    {
                        this.ShowMessageAsync("Select one or more record to Assign Features.", "Confirm - Asset Classes Category");
                    }

                    this.ResetBusyAction();
                    break;
                case Asset.EnumSteps.AssetClassesCategoryAssignTypesState:
                    this.SetBusyAction(LoadingText);
                    if (this.DynamicMainGridViewModel.SelectedItems.Count() > 0)
                    {
                        if (await this.LockAssetClassesCategoryAsync())
                        {
                            if (this.OnStoryBoardChanged != null)
                            {
                                this.OnStoryBoardChanged(this._currentEnumStep.ToString());
                            }

                            this.OnStepChanged("BulkUpdateState");
                            this.SetBackgroundToEdit();
                            this.CurrentState = Asset.EnumSteps.AssetClassesCategoryAssignTypesState;
                            this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesCategory, Asset.EnumSteps.AssetClassesCategoryAssignTypesState);
                            await this.GetListTypesItemsForAssignTypesScreen();
                            this.IsCheckedOut = true;
                        }
                    }
                    else
                    {
                        this.ShowMessageAsync("Select one or more record to Assign Types.", "Confirm - Asset Classes Category");
                    }

                    this.ResetBusyAction();
                    break;
                case Asset.EnumSteps.AssetClassesCategoryUpdateDepreciationState:
                    this.SetBusyAction(LoadingText);
                    if (this.DynamicMainGridViewModel.SelectedItems.Count() > 0)
                    {
                        if (await this.LockAssetClassesCategoryAsync())
                        {
                            if (this.OnStoryBoardChanged != null)
                            {
                                this.OnStoryBoardChanged(this._currentEnumStep.ToString());
                            }

                            this.OnStepChanged("BulkUpdateState");
                            this.SetBackgroundToEdit();
                            this.CurrentState = Asset.EnumSteps.AssetClassesCategoryUpdateDepreciationState;
                            this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesCategory, Asset.EnumSteps.AssetClassesCategoryUpdateDepreciationState);
                            await this.GetDataSourceForUpdateDepreciationScreen();
                            this.IsCheckedOut = true;
                        }
                    }
                    else
                    {
                        this.ShowMessageAsync("Select one or more record to Update Depreciation.", "Confirm - Asset Classes Category");
                    }

                    this.ResetBusyAction();
                    break;
                case Asset.EnumSteps.BulkUpdate:
                    this.CurrentState = Asset.EnumSteps.BulkUpdate;
                    this.InModeBulkUpdate = true;
                    this.DynamicMainGridViewModel.IsEnableHoverRow = true;
                    break;
                case Asset.EnumSteps.Add:
                    this.InModeAdd = true;
                    this.SetBusyAction(LoadingText);

                    // Change story board to screen detail
                    if (this.OnStoryBoardChanged != null)
                    {
                        this.OnStoryBoardChanged("AssetClassesCategoryDetailState");
                    }

                    this.OnStepChanged("MainContentState");
                    this.CurrentState = Asset.EnumSteps.Add;
                    this.SetBackgroundToEdit();
                    await this.SetSelectedCategoryItem(new AssetClassesCategoryRowItem { EquipCategoryId = 0, Enabled = true });
                    this.IsNewItem = true;
                    this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesCategory, EnumSteps.Add);
                    await this.OnStepAsync(Asset.EnumSteps.Edit);
                    this.ResetBusyAction();
                    break;
                case Asset.EnumSteps.Edit:
                    this.SetBusyAction(LoadingText);
                    if (await this.LockAssetClassesCategoryAsync())
                    {
                        this.SetBackgroundToEdit();

                        this.CurrentState = Asset.EnumSteps.Edit;
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesCategory, Asset.EnumSteps.Edit);
                        if (this.CategoryFeaturesViewModel.FeaturesTabViewModel != null)
                        {
                            if (this.PermissionCategoryFeature.CanEdit)
                            {
                                this.CategoryFeaturesViewModel.FeaturesTabViewModel.IsEnableHoverRow = true;
                            }
                        }

                        if (this.CategoryAssetTypesViewModel.AssetTypesTabViewModel != null)
                        {
                            if (this.PermissionCategoryType.CanEdit)
                            {
                                this.CategoryAssetTypesViewModel.AssetTypesTabViewModel.IsEnableHoverRow = true;
                            }
                        }

                        this.IsCheckedOut = true;
                    }

                    this.ResetBusyAction();
                    break;
                case Asset.EnumSteps.EditAssignFeature:
                    if (await this.LockAssetClassesCategoryAsync())
                    {
                        this.SetBackgroundToEdit();
                        this.CurrentState = Asset.EnumSteps.EditAssignFeature;
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesCategory, Asset.EnumSteps.AssetClassesCategoryAssignFeaturesState);
                        this.IsCheckedOut = true;
                    }

                    break;
                case Asset.EnumSteps.EditAssignTypes:
                    if (this.DynamicMainGridViewModel.SelectedItems != null)
                    {
                        if (await this.LockAssetClassesCategoryAsync())
                        {
                            this.SetBackgroundToEdit();
                            this.CurrentState = Asset.EnumSteps.EditAssignTypes;
                            this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesCategory, Asset.EnumSteps.AssetClassesCategoryAssignTypesState);
                            this.IsCheckedOut = true;
                        }
                    }

                    break;
                case Asset.EnumSteps.EditUpdateDepreciation:
                    if (this.DynamicMainGridViewModel.SelectedItems != null)
                    {
                        if (await this.LockAssetClassesCategoryAsync())
                        {
                            this.SetBackgroundToEdit();
                            this.CurrentState = Asset.EnumSteps.EditUpdateDepreciation;
                            this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesCategory, Asset.EnumSteps.AssetClassesCategoryUpdateDepreciationState);
                            this.IsCheckedOut = true;
                        }
                    }

                    break;
                case Asset.EnumSteps.Save:
                    this.CategoryDetailViewModel.Validate();
                    if (this.CategoryDetailViewModel.HasErrors == false)
                    {
                        if (!this.IsNewItem)
                        {
                            await this.UnLockAssetClassesCategoryAsync();
                        }

                        this.ListErrorHyperlink.Clear();
                        this.CategoryDetailViewModel.ListErrorHyperlink.Clear();
                        this.InError = false;
                        this.ValidateNotError();
                        this.SetBusyAction(LoadingText);
                        this.CurrentState = Asset.EnumSteps.Save;

                        this.CategoryDetailViewModel.ClearNotifyErrors();
                        this.SetBackgroundToNotEdit();
                        
                        string previousCate = this._selectedCategoryItem.Category;
                        EquipCategory catItemSaved = await this.SaveAllDataForDetailScreen();
                        await this.SetSelectedNewItem(catItemSaved);
                        if (this.IsNewItem)
                        {
                            this.UpdateSourceForGrid();
                            this.IsNewItem = false;
                            this.InModeAdd = false;
                            await this.CategoryFeaturesViewModel.GetFeatureDataSource(catItemSaved.EquipCatId, catItemSaved.Enabled);
                            await this.CategoryAssetTypesViewModel.GetAssetTypesDataSource(catItemSaved.EquipCatId, catItemSaved.Enabled);
                        }
                        else
                        {
                            this.UpdateSourceForGrid(previousCate);
                            await this.CategoryFeaturesViewModel.GetFeatureDataSource(catItemSaved.EquipCatId, catItemSaved.Enabled);
                            await this.CategoryAssetTypesViewModel.GetAssetTypesDataSource(catItemSaved.EquipCatId, catItemSaved.Enabled);
                        }

                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesCategory, Asset.EnumSteps.Save, catItemSaved);
                        this.CategoryFeaturesViewModel.FeaturesTabViewModel.IsEnableHoverRow = false;
                        this.CategoryAssetTypesViewModel.AssetTypesTabViewModel.IsEnableHoverRow = false;
                    }
                    else
                    {
                        this.InError = true;
                        this.CurrentState = Asset.EnumSteps.Error;
                        this.ListErrorHyperlink = this.CategoryDetailViewModel.ListErrorHyperlink;
                        foreach (var itemError in this.ListErrorHyperlink)
                        {
                            itemError.Action = HyperLinkAction.AssetClassesCategoryDetailState;
                            itemError.SelectedStyle = (Style)Application.Current.FindResource("HyperlinkLikeButton");
                        }

                        this.OnErrorHyperlinkSelected();
                    }

                    this.ResetBusyAction();
                    break;
                case Asset.EnumSteps.SaveAndAdd:
                    this.CategoryDetailViewModel.Validate();
                    if (this.CategoryDetailViewModel.HasErrors == false)
                    {
                        await this.OnStepAsync(Asset.EnumSteps.Save);
                        await this.OnStepAsync(Asset.EnumSteps.Add);
                    }
                    else
                    {
                        this.InError = true;
                        this.CurrentState = Asset.EnumSteps.Error;
                        this.ListErrorHyperlink = this.CategoryDetailViewModel.ListErrorHyperlink;
                        foreach (var itemError in this.ListErrorHyperlink)
                        {
                            itemError.Action = HyperLinkAction.AssetClassesCategoryDetailState;
                            itemError.SelectedStyle = (Style)Application.Current.FindResource("HyperlinkLikeButton");
                        }

                        this.OnErrorHyperlinkSelected();
                    }

                    break;
                case Asset.EnumSteps.SaveAssignFeature:
                    this.CurrentState = Asset.EnumSteps.SaveAssignFeature;
                    await this.UnLockAssetClassesCategoryAsync();
                    this.SetBackgroundToNotEdit();
                    await this.SaveAllDataForAssignFeatureScreen();
                    this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesCategory, Asset.EnumSteps.SaveAssignFeature);
                    break;
                case Asset.EnumSteps.SaveAssignTypes:
                    this.CurrentState = Asset.EnumSteps.SaveAssignTypes;
                    await this.UnLockAssetClassesCategoryAsync();
                    this.SetBackgroundToNotEdit();
                    await this.SaveAllDataForAssignTypesScreen();
                    this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesCategory, Asset.EnumSteps.SaveAssignTypes);
                    break;
                case Asset.EnumSteps.SaveUpdateDepreciation:
                    this.CategoryUpdateDepreciationViewModel.Validate();
                    if (this.CategoryUpdateDepreciationViewModel.HasErrors == false)
                    {
                        this.InError = false;
                        this.ListErrorHyperlink.Clear();
                        this.CategoryUpdateDepreciationViewModel.ListErrorHyperlink.Clear();
                        this.SetBusyAction(LoadingText);
                        this.CurrentState = Asset.EnumSteps.SaveUpdateDepreciation;
                        await this.UnLockAssetClassesCategoryAsync();
                        this.CategoryUpdateDepreciationViewModel.ClearNotifyErrors();
                        this.SetBackgroundToNotEdit();
                        await this.SaveAllDataForUpdateDepreciationScreen();
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesCategory, Asset.EnumSteps.SaveUpdateDepreciation);
                    }
                    else
                    {
                        this.InError = true;
                        this.CurrentState = Asset.EnumSteps.ErrorUpdateDepreciation;
                        this.ListErrorHyperlink = this.CategoryUpdateDepreciationViewModel.ListErrorHyperlink;
                        this.OnErrorHyperlinkSelected();
                    }

                    this.ResetBusyAction();
                    break;
                case Asset.EnumSteps.Cancel:
                    if (await this.CheckIfUnSavedChanges())
                    {
                        this.InError = false;
                        this.ListErrorHyperlink.Clear();
                        this.CategoryDetailViewModel.ListErrorHyperlink.Clear();
                        this.ValidateNotError();
                        this.SetBusyAction();
                        this.CurrentState = Asset.EnumSteps.Cancel;
                        this.CategoryDetailViewModel.ClearNotifyErrors();
                        await this.UnLockAssetClassesCategoryAsync();
                        this.SetBackgroundToNotEdit();

                        if (!this.IsCheckedOut)
                        {
                            if (this.CategoryFeaturesViewModel.FeaturesTabViewModel != null)
                            {
                                this.CategoryFeaturesViewModel.FeaturesTabViewModel.IsEnableHoverRow = false;
                            }

                            if (this.CategoryAssetTypesViewModel.AssetTypesTabViewModel != null)
                            {
                                this.CategoryAssetTypesViewModel.AssetTypesTabViewModel.IsEnableHoverRow = false;
                            }
                        }

                        if (this.IsNewItem)
                        {
                            this.IsNewItem = false;
                            this.OnCancelNewItem(EnumScreen.AssetClassesCategory);
                            await this.OnStepAsync(Asset.EnumSteps.MainViewState);
                            this.InModeAdd = false;
                        }
                        else
                        {
                            this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesCategory, Asset.EnumSteps.Cancel);
                            await this.OnStepAsync(Asset.EnumSteps.SelectedAssetClassesCategoryItem);
                        }

                        this.IsCheckedOut = false;
                        this.IsChanged = false;
                    }

                    this.ResetBusyAction();
                    break;
                case Asset.EnumSteps.CancelAssignFeature:
                    if (await this.CheckIfUnSavedChanges())
                    {
                        await this.UnLockAssetClassesCategoryAsync();
                        await this.GetListFeatureItemsForAssignFeaturesScreen();
                        this.CurrentState = Asset.EnumSteps.CancelAssignFeature;
                        this.SetBackgroundToNotEdit();
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesCategory, Asset.EnumSteps.CancelAssignFeature);
                        this.IsCheckedOut = false;
                        this.IsChanged = false;
                    }

                    break;
                case Asset.EnumSteps.CancelAssignTypes:
                    if (await this.CheckIfUnSavedChanges())
                    {
                        await this.UnLockAssetClassesCategoryAsync();
                        await this.GetListTypesItemsForAssignTypesScreen();
                        this.CurrentState = Asset.EnumSteps.CancelAssignTypes;
                        this.SetBackgroundToNotEdit();
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesCategory, Asset.EnumSteps.CancelAssignTypes);
                        this.IsCheckedOut = false;
                        this.IsChanged = false;
                    }

                    break;
                case Asset.EnumSteps.CancelUpdateDepreciation:
                    if (await this.CheckIfUnSavedChanges())
                    {
                        this.InError = false;
                        this.ListErrorHyperlink.Clear();
                        this.CategoryUpdateDepreciationViewModel.ListErrorHyperlink.Clear();
                        this.SetBusyAction(LoadingText);
                        await this.UnLockAssetClassesCategoryAsync();
                        await this.GetDataSourceForUpdateDepreciationScreen();
                        this.CurrentState = Asset.EnumSteps.CancelUpdateDepreciation;
                        this.SetBackgroundToNotEdit();
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesCategory, Asset.EnumSteps.CancelUpdateDepreciation);
                        this.IsCheckedOut = false;
                        this.IsChanged = false;
                    }

                    this.ResetBusyAction();
                    break;
                case Asset.EnumSteps.CancelBulkUpdate:
                    if (await this.CheckIfUnSavedChanges())
                    {
                        this.CurrentState = Asset.EnumSteps.CancelBulkUpdate;
                        this.InModeBulkUpdate = true;
                        this.DynamicMainGridViewModel.SelectedRows = new List<object>();
                        this.DynamicMainGridViewModel.IsEnableHoverRow = false;
                        this.InModeBulkUpdate = false;
                    }

                    break;
                case Asset.EnumSteps.Error:
                    // Show NotificationWindow when click Error button.
                    NotificationErrorView errorPopup = new NotificationErrorView();
                    NotificationErrorViewModel errorPopupViewModel = new NotificationErrorViewModel();
                    errorPopupViewModel.listCustomHyperlink = this.ListErrorHyperlink;
                    errorPopup.DataContext = errorPopupViewModel;

                    errorPopup.Style = (Style)Application.Current.FindResource("RadWindowStyleNew");

                    errorPopup.ShowDialog();
                    break;
            }

            this.SetActionCommandsAsync();
        }
        /// <summary>
        /// The on step async.
        /// </summary>
        /// <param name="stepName">
        /// The step name.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public override async Task OnStepAsync(object stepName)
        {
            bool canProcess;
            this._currentEnumStep = (Asset.EnumSteps)Enum.Parse(typeof(Asset.EnumSteps), stepName.ToString());
            if (this._currentEnumStep != Asset.EnumSteps.DetailsState && this._currentEnumStep != Asset.EnumSteps.AssignedToState)
            {
                this.CurrentStep = this._currentEnumStep;
            }

            switch (this._currentEnumStep)
            {
                case Asset.EnumSteps.Start:
                    this.SetBusyAction(LoadingText);
                    this.ActiveViewModel = this;
                    this.IsAdd = false;
                    this.GetPermission();
                    await this.PopulateAllFeatureTypesForViewAsync();
                    this.RaiseSelectedItemChanged();
                    this.ResetBusyAction();
                    break;
                case Asset.EnumSteps.SelectedFeatureType:
                    this.SetBusyAction(LoadingText);
                    if (this.OnStoryBoardChanged != null)
                    {
                        this.OnStoryBoardChanged(Asset.EnumSteps.GridContentState.ToString());
                    }

                    this.SetGridStype(false);
                    this.SetValueForAssetFeaturesDetail(this.SelectedFeatureType);
                    await this.SetValueForAssetFeaturesAssignedTo(this.SelectedFeatureType);
                    if (this.IsCheckedOut && this.AssetFeaturesDetailViewModel.Enabled)
                    {
                        this.AssetFeaturesAssignedToViewModel.DynamicAssetCategoriesViewModel.IsEnableHoverRow = true;
                        this.AssetFeaturesAssignedToViewModel.DynamicAssetTypesViewModel.IsEnableHoverRow = true;
                    }

                    this.SetActionCommandsAsync();
                    this.RaiseActionsWhenChangeStep(EnumScreen.AssetFeatures, EnumSteps.SelectedFeatureType, this.SelectedFeatureType);
                    this.ResetBusyAction();
                    break;
                case Asset.EnumSteps.GridContentState:
                    if (this.OnStoryBoardChanged != null)
                    {
                        this.OnStoryBoardChanged(this._currentEnumStep.ToString());
                    }

                    break;
                case Asset.EnumSteps.DetailsState:
                    this.OnStepChanged(Asset.EnumSteps.DetailsState.ToString());
                    this.CurrentTab = Asset.EnumSteps.DetailsState;
                    
                    break;
                case Asset.EnumSteps.AssignedToState:
                    this.OnStepChanged(Asset.EnumSteps.AssignedToState.ToString());
                    this.CurrentTab = Asset.EnumSteps.AssignedToState;
                    break;
                case Asset.EnumSteps.GridSummaryState:
                    if (this.OnStoryBoardChanged != null)
                    {
                        this.OnStoryBoardChanged(this._currentEnumStep.ToString());
                    }

                    break;
                case Asset.EnumSteps.AssignFeatureState:
                    var items = new ObservableCollection<AssetFeatureTypeRowItem>(this.DynamicFeatureTypeViewModel.SelectedItems.Cast<AssetFeatureTypeRowItem>());
                    if (items.Count > 0)
                    {
                        bool result;
                        List<int> list = new List<int>(items.Select(x => x.FeatureTypeId));
                        result = await this.LockBulkUpdateAssetFeaturesAsync(list);
                        if (!result)
                        {
                            // Raise event to visible FormMenu if record selected is locked.
                            this.RaiseActionsWhenChangeStep(EnumScreen.AssetFeatures, EnumSteps.ItemLocked);
                            return;
                        }

                        this.IsCheckedOut = true;
                        this.SetIsCheckedOut();
                        this.SetGridStype(true);
                        var selectedFeatureTypes =
                            new ObservableCollection<AssetFeatureTypeRowItem>(
                                this.DynamicFeatureTypeViewModel.SelectedItems.Cast<AssetFeatureTypeRowItem>());
                        await
                            this.AssetFeaturesAssignFeatureViewModel.PopulateAssignFeatureDrogDrag(selectedFeatureTypes);
                        if (this.OnStoryBoardChanged != null)
                        {
                            this.OnStoryBoardChanged(this._currentEnumStep.ToString());
                        }

                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetFeatures, EnumSteps.EditBulkUpdate);
                        this.SetActionCommandsAsync();
                    }
                    else
                    {
                        this.ShowMessageAsync("Select one or more record to Assign Features.", "Confirm - Asset Feature");
                        this.CurrentStep = Asset.EnumSteps.None;
                    }
                    
                    break;
                case Asset.EnumSteps.BulkUpdate:
                    this.DynamicFeatureTypeViewModel.IsEnableHoverRow = true;
                    this.IsBulkUpdate = true;
                    this.SetActionCommandsAsync();
                    break;
                case Asset.EnumSteps.Add:
                    this.IsAdd = true;
                    this.SetNewFeatureType();
                    if (this.OnStoryBoardChanged != null)
                    {
                        this.OnStoryBoardChanged(Asset.EnumSteps.GridContentState.ToString());
                    }

                    this.OnStepChanged(Asset.EnumSteps.DetailsState.ToString());
                    this.CurrentTab = Asset.EnumSteps.DetailsState;
                    this.SetValueForAssetFeaturesDetail(this.SelectedFeatureType);
                    await this.SetValueForAssetFeaturesAssignedTo(this.SelectedFeatureType);
                    this.RaiseActionsWhenChangeStep(EnumScreen.AssetFeatures, EnumSteps.Add);
                    await this.OnStepAsync(Asset.EnumSteps.Edit);
                    break;
                case Asset.EnumSteps.Edit:
                    if (this.SelectedFeatureType != null && !this.SelectedFeatureType.IsNewFeatureType)
                    {
                        this.IsAdd = false;
                        bool checkLock =
                            await
                            this.LockBulkUpdateAssetFeaturesAsync(
                                new List<int> { this.SelectedFeatureType.FeatureTypeId },
                                true);
                        if (!checkLock)
                        {
                            // Raise event to visible FormMenu if record selected is locked.
                            this.RaiseActionsWhenChangeStep(EnumScreen.AssetFeatures, EnumSteps.ItemLocked);

                            // Change background if record selected is locked when editing.
                            this.SetGridStype(false);
                            this.CurrentStep = Asset.EnumSteps.None;
                            return;
                        }
                    }

                    this.IsCheckedOut = true;
                    this.SetIsCheckedOut();
                    this.SetGridStype(true);
                    if (this.AssetFeaturesAssignedToViewModel.IsCheckedOut)
                    {
                        this.AssetFeaturesAssignedToViewModel.DynamicAssetCategoriesViewModel.IsEnableHoverRow = true;
                        this.AssetFeaturesAssignedToViewModel.DynamicAssetTypesViewModel.IsEnableHoverRow = true;
                    }

                    this.RaiseActionsWhenChangeStep(EnumScreen.AssetFeatures, EnumSteps.Edit);
                    break;
                case Asset.EnumSteps.EditBulkUpdate:
                    var item2S = new ObservableCollection<AssetFeatureTypeRowItem>(this.DynamicFeatureTypeViewModel.SelectedItems.Cast<AssetFeatureTypeRowItem>());
                    if (item2S.Count != 0)
                    {
                        this.IsBulkUpdate = true;
                        bool result;
                        List<int> list = new List<int>(item2S.Select(x => x.FeatureTypeId));
                        result = await this.LockBulkUpdateAssetFeaturesAsync(list);
                        if (!result)
                        {
                            // Raise event to visible FormMenu if record selected is locked.
                            this.RaiseActionsWhenChangeStep(EnumScreen.AssetFeatures, EnumSteps.ItemLocked);
                            return;
                        }
                    }

                    this.IsCheckedOut = true;
                    this.SetIsCheckedOut();
                    this.SetGridStype(true);
                    this.RaiseActionsWhenChangeStep(EnumScreen.AssetFeatures, EnumSteps.EditBulkUpdate);
                    break;
                case Asset.EnumSteps.SaveBulkUpdate:
                    try
                    {
                        await this.SaveFeatureBulkUpdateAsync();
                        await this.UnLockBulkUpdateAssetFeaturesAsync();
                        this.IsBulkUpdate = false;
                        this.IsCheckedOut = false;
                        this.SetIsCheckedOut();
                        this.SetGridStype(false);
                        this.IsChanged = false;
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetFeatures, EnumSteps.SaveAssignFeature);
                    }
                    catch (Exception exc)
                    {
                        ExceptionLogger.WriteLog(exc);
                        this.ShowErrorMessage("Error encountered while Saving Asset Feature Bulk Update.", "Asset Features");
                    }

                    break;
                case Asset.EnumSteps.Save:
                    try
                    {
                        this.AssetFeaturesDetailViewModel.Validate();
                        if (this.AssetFeaturesDetailViewModel.HasErrors == false)
                        {
                            this.IsAdd = false;
                            if (this.SelectedFeatureType != null && !this.SelectedFeatureType.IsNewFeatureType)
                            {
                                await this.UnLockBulkUpdateAssetFeaturesAsync();
                            }
                            else
                            {
                                this.IsCheckedOut = false;
                                this.SetIsCheckedOut();
                                this.IsChanged = false;
                            }

                            this.IsCheckedOut = false;
                            this.SetIsCheckedOut();
                            this.IsChanged = false;
                            this.SelectedFeatureType = await this.SaveFeatureAsync();
                            this.UpdateDataFeatureTypesAsync();
                            this.SelectedFeatureType.IsNewFeatureType = false;

                            this.ValidateNotError();
                            this.AllFeatureTypes = new ObservableCollection<FeatureType>(await AssetFeatureFunction.GetAllFeatureTypesAsync());
                            await this.OnStepAsync(Asset.EnumSteps.SelectedFeatureType);
                            this.RaiseActionsWhenChangeStep(EnumScreen.AssetFeatures, EnumSteps.Save, this.SelectedFeatureType.FeatureTypeId);
                        }
                        else
                        {
                            this.CurrentStep = Asset.EnumSteps.Error;
                            this.SetActionCommandsAsync();
                            this.ListErrorHyperlink = this.AssetFeaturesDetailViewModel.ListErrorHyperlink;
                            this.OnErrorHyperlinkSelected();
                        }
                    }
                    catch (Exception exc)
                    {
                        ExceptionLogger.WriteLog(exc);
                        this.ShowErrorMessage("Error encountered while Saving Asset Feature Details.", "Asset Features");
                    }

                    break;
                case Asset.EnumSteps.SaveAndAdd:
                    await this.OnStepAsync(Asset.EnumSteps.Save);
                    if (this.AssetFeaturesDetailViewModel.HasErrors == false)
                    {
                        await this.OnStepAsync(Asset.EnumSteps.Add);
                    }

                    break;
                case Asset.EnumSteps.Delete:
                    this.AssetFeaturesDetailViewModel.ClearNotifyErrors();
                    this.ValidateNotError();
                    this.Validate();
                    if (this.HasErrors == false)
                    {
                        bool canProceed = false;
                        ConfirmationWindowView confirm = new ConfirmationWindowView();
                        ConfirmmationViewModel confirmViewModel = new ConfirmmationViewModel();
                        confirmViewModel.Content = "Select OK to confirm deletion?";
                        confirmViewModel.Title = "Delete - Asset Feature";
                        confirm.DataContext = confirmViewModel;

                        confirm.ShowDialog();
                        if (confirm.DialogResult == true)
                        {
                            canProceed = true;
                        }

                        if (canProceed)
                        {
                            if (this.SelectedFeatureType != null && !this.SelectedFeatureType.IsNewFeatureType)
                            {
                                await
                                    AssetFeatureFunction.DeleteSelectedFeatureTypeAsync(
                                        this.SelectedFeatureType.FeatureTypeId);
                                await this.UnLockBulkUpdateAssetFeaturesAsync();
                                this.AllFeatureTypes =
                                   new ObservableCollection<FeatureType>(
                                       await AssetFeatureFunction.GetAllFeatureTypesAsync());
                                this.RaiseActionsWhenChangeStep(
                                    EnumScreen.AssetFeatures,
                                    EnumSteps.Delete,
                                    this.SelectedFeatureType.FeatureTypeId);
                                await this.UnLockBulkUpdateAssetFeaturesAsync();
                                this.UpdateDataFeatureTypesAsync(true);
                                this.IsCheckedOut = false;
                                this.SetIsCheckedOut();
                                this.IsChanged = false;
                                this.OnCancelNewItem(EnumScreen.AssetFeatures);
                                if (this.OnStoryBoardChanged != null)
                                {
                                    this.OnStoryBoardChanged(Asset.EnumSteps.GridSummaryState.ToString());
                                    this.CurrentStep = Asset.EnumSteps.GridSummaryState;
                                }
                            }
                        }
                        else
                        {
                            this.CurrentStep = Asset.EnumSteps.None;
                        }
                    }
                    else
                    {
                        this.CurrentStep = Asset.EnumSteps.Error;
                        this.SetActionCommandsAsync();

                        if (!_permissionFeatureAssignTo.CanSee)
                        {
                            foreach (var itemError in this.ListErrorHyperlink)
                            {
                                itemError.SelectedStyle = (Style)Application.Current.FindResource("HyperlinkLikeButton2");
                                itemError.Action = HyperLinkAction.DetailsState;
                            }
                        }
                        
                        this.OnErrorHyperlinkSelected();
                    }

                    break;
                case Asset.EnumSteps.Cancel:
                    canProcess = await this.CheckIfUnSavedChanges();
                    if (canProcess)
                    {
                        this.AssetFeaturesDetailViewModel.ClearNotifyErrors();
                        this.ValidateNotError();

                        // Just do UnLockAsync if not in mode Add.
                        if (this.SelectedFeatureType != null && !this.SelectedFeatureType.IsNewFeatureType)
                        {
                            await this.UnLockBulkUpdateAssetFeaturesAsync();
                        }
                        else
                        {
                            this.IsCheckedOut = false;
                            this.SetIsCheckedOut();
                            this.IsChanged = false;
                        }

                        this.IsCheckedOut = false;
                        this.IsChanged = false;
                        this.SetIsCheckedOut();
                        this.SetGridStype(false);
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetFeatures, EnumSteps.Cancel);
                        if (this.SelectedFeatureType == null
                            || (this.SelectedFeatureType != null && this.SelectedFeatureType.IsNewFeatureType))
                        {
                            this.OnCancelNewItem(EnumScreen.AssetFeatures);
                            if (this.OnStoryBoardChanged != null)
                            {
                                this.OnStoryBoardChanged(Asset.EnumSteps.GridSummaryState.ToString());
                                this.CurrentStep = Asset.EnumSteps.GridSummaryState;
                            }
                        }
                        else
                        {
                            this.AssetFeaturesAssignedToViewModel.DynamicAssetCategoriesViewModel.IsEnableHoverRow =
                                false;
                            this.AssetFeaturesAssignedToViewModel.DynamicAssetTypesViewModel.IsEnableHoverRow = false;
                            this.SetValueForAssetFeaturesDetail(this.SelectedFeatureType);
                            await this.SetValueForAssetFeaturesAssignedTo(this.SelectedFeatureType);
                        }
                    }
                    else
                    {
                        this.CurrentStep = Asset.EnumSteps.None;
                    }

                    break;
                case Asset.EnumSteps.CancelAssignFeature:
                    canProcess = await this.CheckIfUnSavedChanges();
                    if (canProcess)
                    {
                        // await this.UnLockAsync();
                        this.IsChanged = false;
                        var selectedFeatureTypesCancel = new ObservableCollection<AssetFeatureTypeRowItem>(this.DynamicFeatureTypeViewModel.SelectedItems.Cast<AssetFeatureTypeRowItem>());
                        if (selectedFeatureTypesCancel.Count() != 0)
                        {
                            await this.UnLockBulkUpdateAssetFeaturesAsync();
                        }
                        else
                        {
                            this.IsCheckedOut = false;
                            this.SetIsCheckedOut();
                            this.IsChanged = false;
                        }

                        await this.AssetFeaturesAssignFeatureViewModel.PopulateAssignFeatureDrogDrag(selectedFeatureTypesCancel);
                        this.IsCheckedOut = false;
                        this.IsBulkUpdate = false;
                        this.SetIsCheckedOut();
                        this.SetGridStype(false);
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetFeatures, EnumSteps.CancelAssignFeature);
                    }
                    else
                    {
                        this.CurrentStep = Asset.EnumSteps.None;
                    }

                    break;
                case Asset.EnumSteps.CancelBulkUpdate:
                    canProcess = await this.CheckIfUnSavedChanges();
                    if (canProcess)
                    {
                        this.IsBulkUpdate = false;
                        this.DynamicFeatureTypeViewModel.SelectedItem = null;
                        this.DynamicFeatureTypeViewModel.IsEnableHoverRow = false;
                        this.DynamicFeatureTypeViewModel.SelectedRows = new List<object>();

                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetFeatures, EnumSteps.CancelBulkUpdate);
                    }

                    break;
                case Asset.EnumSteps.Error:
                    // Show NotificationWindow when click Error button.
                    NotificationErrorView errorPopup = new NotificationErrorView();
                    NotificationErrorViewModel errorPopupViewModel = new NotificationErrorViewModel();
                    errorPopupViewModel.listCustomHyperlink = this.ListErrorHyperlink;
                    errorPopup.DataContext = errorPopupViewModel;

                    errorPopup.Style = (Style)Application.Current.FindResource("RadWindowStyleNew");

                    errorPopup.ShowDialog();
                    break;
            }

            this.SetActionCommandsAsync();
        }
        public override async Task OnStepAsync(object stepName)
        {
            this.CurrentStep = (EnumStep)Enum.Parse(typeof(EnumStep), stepName.ToString());

            switch (this.CurrentStep)
            {
                case EnumStep.TrancheSelected:
                    this._Failures.Clear();
                    this.MainViewModel.ValidateNotError();
                    await PopulateTrancheProfile();
                    this.IsChanged = false;
                    this.IsError = false;
                    this.IsFundingDateInvalid = false;
                    this.SelectedTrancheProfile.PropertyChanged -= this.SelectedTrancheProfile_PropertyChanged;
                    this.SelectedTrancheProfile.PropertyChanged += this.SelectedTrancheProfile_PropertyChanged;
                    this.TrancheDateText = this.SelectedTrancheProfile.TrancheDate;
                    break;
                case EnumStep.Edit:
                    if ((TrancheStatus)FundingFunctions.GetFundingTrancheStatus(this.SelectedTrancheProfile.TrancheId)
                        != TrancheStatus.Confirmed)
                    {
                        if (await this.LockAsync())
                        {
                            // Remove errors about confirm or edit a record confirmed.
                            CustomHyperlink error1 = this.MainViewModel.ListErrorHyperlink.FirstOrDefault(x => x.HyperlinkHeader.Contains("Only Pending record is allowed to edit"));
                            CustomHyperlink error2 = this.MainViewModel.ListErrorHyperlink.FirstOrDefault(x => x.HyperlinkHeader.Contains("Only one Confirmed record per Contract is allowed"));
                            if (!this.IsConfirmError || error1 != null || error2 != null)
                            {
                                if (this.MainViewModel.ListErrorHyperlink.Count > 1)
                                {
                                    if (error1 != null && error2 != null)
                                    {
                                        if (this.MainViewModel.ListErrorHyperlink.Count == 2)
                                        {
                                            this.IsConfirmError = false;
                                            this.MainViewModel.ClearNotifyErrors();
                                            this.MainViewModel.ListErrorHyperlink.Clear();
                                            this.IsError = false;
                                            this.MainViewModel.ValidateNotError();
                                        }
                                        else
                                        {
                                            this.MainViewModel.ListErrorHyperlink.Remove(error1);
                                            this.MainViewModel.ListErrorHyperlink.Remove(error2);
                                        }
                                    }
                                    else
                                    {
                                        if (error1 != null)
                                        {
                                            this.MainViewModel.ListErrorHyperlink.Remove(error1);
                                        }

                                        if (error2 != null)
                                        {
                                            this.MainViewModel.ListErrorHyperlink.Remove(error2);
                                        }
                                    }
                                }
                                else
                                {
                                    this.IsConfirmError = false;
                                    this.MainViewModel.ClearNotifyErrors();
                                    this.MainViewModel.ListErrorHyperlink.Clear();
                                    this.IsError = false;
                                    this.MainViewModel.ValidateNotError();
                                }
                                this._Failures.Clear();
                                this.IsFundingDateInvalid = false;
                            }

                            this.MainViewModel.RaiseActionsWhenChangeStep(EnumScreen.FundingSummary, EnumSteps.Edit);
                            this.BusyContent = "Please Wait Loading ...";
                            this.IsBusy = true;


                            this.IsCheckedOut = false;
                            await PopulateTrancheProfile();
                            if (this.IsConfirmError)
                            {
                                await this.BuildBaseQueryNotIncludedAsync();
                            }
                            else
                            {
                                await this.BuildBaseQueryAsync();
                            }
                            this.IsCheckedOut = true;
                            this.CurrentStep = EnumStep.Edit;
                            this.IsChanged = false;

                            // Store the list of selected contract to set list inclucded contract turn to origin when changing FundingDate.
                            List<TrancheContractSummary> _includedInTrancheContracts = new List<TrancheContractSummary>();

                            foreach (var item in this.IncludedInTrancheContracts)
                            {
                                _includedInTrancheContracts.Add(new TrancheContractSummary
                                                                    {
                                                                        FrequencyId = item.FrequencyId,
                                                                        FinanceTypeId = item.FinanceTypeId,
                                                                        FundingStatus = item.FundingStatus,
                                                                        InstalmentType = item.InstalmentType,
                                                                        InternalCompanyId = item.InternalCompanyId,
                                                                        SupplierId = item.SupplierId,
                                                                        Term = item.Term,
                                                                        StartDate = item.StartDate,
                                                                        InvestmentBalance = item.InvestmentBalance,
                                                                        GrossAmountOverDue = item.GrossAmountOverDue,
                                                                        ClientName = item.ClientName,
                                                                        FunderId = item.FunderId,
                                                                        ContractReference = item.ContractReference,
                                                                        ContractId = item.ContractId,
                                                                        ContractPrefix = item.ContractPrefix,
                                                                        NumberOfPayments = item.NumberOfPayments,
                                                                        FirmTermDate = item.FirmTermDate,
                                                                        IsSelected = item.IsSelected,
                                                                        IsExisting = item.IsExisting,
                                                                        FundingStartDate = item.FundingStartDate,
                                                                        IsValid = item.IsValid,
                                                                        FundingStatusId = item.FundingStatusId,
                                                                        LastPaymentDate = item.LastPaymentDate,
                                                                    });
                            }
                            this.IncludedInTrancheContractsOrigin = new List<TrancheContractSummary>(_includedInTrancheContracts.ToList());

                            this.BusyContent = string.Empty;
                            this.IsBusy = false;

                            this.SetupConfirmValidator(false);
                        }
                    }
                    else
                    {
                        if (this.MainViewModel.ListErrorHyperlink != null)
                        {
                            if (this.MainViewModel.ListErrorHyperlink.FirstOrDefault(x => x.HyperlinkHeader.Contains("Only Pending record is allowed to edit")) == null)
                            {
                                this.MainViewModel.ListErrorHyperlink.Add(new CustomHyperlink
                                {
                                    HyperlinkHeader = "Only Pending record is allowed to edit.",
                                    SelectedStyle = (Style)Application.Current.FindResource("HyperlinkLikeButton2"),
                                    Action = HyperLinkAction.None,
                                });
                                this.IsConfirmError = true;
                            }
                        }
                    }
                    break;

                case EnumStep.Cancel:
                    this.BusyContent = "Please Wait Loading ...";
                    this.IsBusy = true;
                    this.IsFundingDateError = false;
                    if (this.CheckIfUnSavedChanges())
                    {
                        this.IsConfirmError = false;
                        this.MainViewModel.RaiseActionsWhenChangeStep(EnumScreen.FundingSummary, EnumSteps.Cancel); 
                        this._Failures.Clear();
                        this.MainViewModel.ValidateNotError();
                        await this.UnLockAsync();
                        await PopulateTrancheProfile();
                        await this.BuildBaseQueryAsync();
                        await this.MainViewModel.OnStepAsync(FundingSummaryViewModel.EnumStep.SelectTranche);
                        this.IsError = false;
                        this.IsFundingDateInvalid = false;
                        this.StillError = false;
                    }
                    this.BusyContent = string.Empty;
                    this.IsBusy = false;
                    break;
                case EnumStep.Save:
                    // Set list Included Tranche to origin.
                    List<TrancheContractSummary> _includedInTrancheContractsOrigin = new List<TrancheContractSummary>();

                    foreach (var item in this.IncludedInTrancheContractsOrigin)
                    {
                        _includedInTrancheContractsOrigin.Add(new TrancheContractSummary
                        {
                            FrequencyId = item.FrequencyId,
                            FinanceTypeId = item.FinanceTypeId,
                            FundingStatus = item.FundingStatus,
                            InstalmentType = item.InstalmentType,
                            InternalCompanyId = item.InternalCompanyId,
                            SupplierId = item.SupplierId,
                            Term = item.Term,
                            StartDate = item.StartDate,
                            InvestmentBalance = item.InvestmentBalance,
                            GrossAmountOverDue = item.GrossAmountOverDue,
                            ClientName = item.ClientName,
                            FunderId = item.FunderId,
                            ContractReference = item.ContractReference,
                            ContractId = item.ContractId,
                            ContractPrefix = item.ContractPrefix,
                            NumberOfPayments = item.NumberOfPayments,
                            FirmTermDate = item.FirmTermDate,
                            IsSelected = item.IsSelected,
                            IsExisting = item.IsExisting,
                            FundingStartDate = item.FundingStartDate,
                            IsValid = item.IsValid,
                            FundingStatusId = item.FundingStatusId,
                            LastPaymentDate = item.LastPaymentDate,
                        });
                    }
                    
                    this.IncludedInTrancheContracts = new ObservableModelCollection<TrancheContractSummary>(_includedInTrancheContractsOrigin.ToList());

                    this.IsConfirmError = false;
                    this.IsFundingDateError = false;
                    this.StillError = true;
                    this.IncludedInTrancheContracts.ForEach(x => x.IsValid = true);
                    this._Failures.RemoveAll(x => x.PropertyName.EndsWith("StartDate"));
                    if (this.Validate() == true)
                    {
                        this.ClearNotifyErrors();
                        this.MainViewModel.ClearNotifyErrors();
                        this.IsFundingDateInvalid = false;
                        this.IsError = false;
                        this.MainViewModel.ListErrorHyperlink.Clear();
                        await this.SaveAsync();
                        await this.UnLockAsync();
                        this.IsChanged = false;
                        this.MainViewModel.ValidateNotError();
                        await this.MainViewModel.OnStepAsync(FundingSummaryViewModel.EnumStep.TrancheSaved);
                        this.MainViewModel.RaiseActionsWhenChangeStep(EnumScreen.FundingSummary, EnumStep.Save, this.SelectedTrancheProfile.TrancheId);
                        this.StillError = false;
                        this.TrancheDateText = this.SelectedTrancheProfile.TrancheDate;
                        await this.BuildBaseQueryAsync();
                    }
                    else
                    {
                        if (this.TrancheDateText == null)
                        {
                            this.IsFundingDateInvalid = true;
                        }
                        else
                        {
                            this.IsFundingDateInvalid = false;
                        }
                        this.SetActionCommandsAsync();
                        this.IsError = false;
                        foreach (var error in this.ListErrorHyperlink)
                        {

                            if (
                                error.HyperlinkHeader.Equals(
                                    "The new Funding Date requires selected records to be removed from the Tranche. Please check the Results page for errors.") &&
                                    this.IsFundingDateInvalid == false)
                            {
                                error.Action = HyperLinkAction.ResultState;
                            }
                        }
                        if (this.ListErrorHyperlink != null)
                        {
                            this.ListErrorHyperlink.RemoveAll(
                                x =>
                                x.HyperlinkHeader.Equals(
                                    "The new Funding Date requires selected records to be removed from the Tranche. Please check the Results page for errors."));
                        }
                        this.MainViewModel.ListErrorHyperlink = this.ListErrorHyperlink;
                        this.MainViewModel.OnErrorHyperlinkSelected();
                    }
                    break;

                case EnumStep.CreateNew:
                    this.IsError = false;
                    this.IsFundingDateInvalid = false;
                    await this.UnLockAsync();
                    await this.MainViewModel.OnStepAsync(FundingSummaryViewModel.EnumStep.CreateNew);
                    break;
                case EnumStep.FunderSelected:
                    this.IsError = false;

                    //this.IsFundingDateInvalid = false;
                    await Task.WhenAll(this.FetchDefaultFundingStatusesByFunderAsync(),
                    this.FetchDefaultFinanceTypesByFunderAsync(),
                    this.FetchDefaultInternalCompaniesByFunderAsync(),
                    this.FetchDefaultSuppliersByFunderAsync(),
                    this.FetchDefaultFundersByFunderAsync());
                    this.TrancheDateText = this.SelectedTrancheProfile.TrancheDate;
                    await this.SetDefaultsByFundingProfileAsync();

                    if (this.IsConfirmError)
                    {
                        if (this.SelectedFunder.Id != -1)
                        {
                            var itemError =
                                this.ListErrorHyperlink.FirstOrDefault(
                                    x => x.HyperlinkHeader.Contains("Cannot proceed as Funder is <None>"));
                            if (itemError != null)
                            {
                                this.ListErrorHyperlink.Remove(itemError);
                                this.MainViewModel.ListErrorHyperlink = this.ListErrorHyperlink;
                                this.MainViewModel.OnErrorHyperlinkSelected();
                                if (this.ListErrorHyperlink.Count == 0)
                                {
                                    this.IsConfirmError = false;
                                }
                                this.SetActionCommandsAsync();
                            }
                        }
                    }
                    break;
                case EnumStep.StatusToConfirmed:
                    this.SetupConfirmValidator(true);
                    this.BusyContent = "Please Wait Loading ...";
                    this.IsBusy = true;
                    this.IsError = false;
                    this.IsFundingDateInvalid = false;
                    if (await this.LockAsync())
                    {
                        this.IsCheckedOut = false;
                        await PopulateTrancheProfile();
                        await this.BuildBaseQueryAsync();

                        this.CurrentStep = EnumStep.StatusToConfirmed;
                        this.OriginalTrancheStatus = TrancheStatus.Confirmed;
                        this.IncludedInTrancheContracts.ForEach(x => x.IsValid = true);
                        if (this.Validate())
                        {
                            this.MainViewModel.ListErrorHyperlink.Clear();
                            this.MainViewModel.ValidateNotError();
                            this.IsConfirmError = false;
                            if (
                                await
                                FundingFunctions.ChangeStatusToConfirmedAsync(
                                    this.SelectedTrancheProfile,
                                    this.IncludedInTrancheContracts.ToList()))
                            {
                                this.SelectedTrancheProfile.TrancheStatusId = (int)TrancheStatus.Confirmed;
                            }
                            else
                            {
                                this.OriginalTrancheStatus =
                                    (TrancheStatus)this.SelectedTrancheProfile.TrancheStatusId;
                            }
                        }
                        else
                        {
                            // this.IsFundingDateInvalid = true;
                            this.IsConfirmError = true;
                            this.OriginalTrancheStatus = (TrancheStatus)this.SelectedTrancheProfile.TrancheStatusId;
                            this.SetActionCommandsAsync();

                            CustomHyperlink itemError =
                                this.ListErrorHyperlink.FirstOrDefault(
                                    x => x.HyperlinkHeader.Contains("Cannot proceed as there is no existing contract"));
                            if (itemError != null)
                            {
                                itemError.Action = HyperLinkAction.ResultState;
                            }

                            CustomHyperlink itemErrorInvalidContract =
                                this.ListErrorHyperlink.FirstOrDefault(
                                    x => x.HyperlinkHeader.Contains("Cannot change the status to Confirmed as there are Invalid Contracts"));
                            if (itemErrorInvalidContract != null)
                            {
                                itemErrorInvalidContract.Action = HyperLinkAction.ResultState;
                                itemErrorInvalidContract.SelectedStyle = (Style)Application.Current.FindResource("HyperlinkLikeButton");
                            }

                            if (itemErrorInvalidContract != null)
                            {
                                this.ListErrorHyperlink.RemoveAll(
                                x =>
                                x.HyperlinkHeader.Contains(
                                    "Cannot change the status to Confirmed as there are Invalid Contracts"));
                                this.ListErrorHyperlink.Add(itemErrorInvalidContract);
                            }

                            CustomHyperlink itemContractError =
                                this.ListErrorHyperlink.FirstOrDefault(
                                    x =>
                                    x.HyperlinkHeader.Contains(
                                        "Contracts are locked in Operations therefore this Tranche cannot be Confirmed"));
                            if (itemContractError != null)
                            {
                                itemContractError.Action = HyperLinkAction.None;
                                itemContractError.SelectedStyle = (Style)Application.Current.FindResource("HyperlinkLikeButton2");
                            }

                            CustomHyperlink itemErrorInvalidConfirm =
                               this.ListErrorHyperlink.FirstOrDefault(
                                   x => x.HyperlinkHeader.Contains("Only one Confirmed record per Contract is allowed."));
                            if (itemErrorInvalidConfirm != null)
                            {
                                itemErrorInvalidConfirm.Action = HyperLinkAction.None;
                                itemErrorInvalidConfirm.SelectedStyle = (Style)Application.Current.FindResource("HyperlinkLikeButton2");
                            }
                            this.MainViewModel.ListErrorHyperlink = this.ListErrorHyperlink;

                            this.MainViewModel.OnErrorHyperlinkSelected();
                            if (this.SelectedTrancheProfile.NodeId == -1)
                            {
                                this.IsError = true;
                            }
                        }
                        await this.UnLockAsync();
                    }
                    this.BusyContent = string.Empty;
                    this.IsBusy = false;
                    break;
                case EnumStep.StatusToPending:
                    this.BusyContent = "Please Wait Loading ...";
                    this.IsBusy = true;
                    if (await this.LockAsync())
                    {
                        await PopulateTrancheProfile();
                        await this.BuildBaseQueryAsync();

                        this.CurrentStep = EnumStep.StatusToPending;
                        if (await FundingFunctions.ChangeStatusToPendingAsync(this.SelectedTrancheProfile))
                        {
                            this.OriginalTrancheStatus = TrancheStatus.Pending;
                            this.SelectedTrancheProfile.TrancheStatusId = (int)TrancheStatus.Pending;
                        }
                        await this.UnLockAsync();
                    }
                    this.BusyContent = string.Empty;
                    this.IsBusy = false;
                    break;
                case EnumStep.StatusToFunded:
                    this.BusyContent = "Please Wait Loading ...";
                    this.IsBusy = true;
                    if (await this.LockAsync())
                    {
                        await PopulateTrancheProfile();
                        await this.BuildBaseQueryAsync();

                        this.CurrentStep = EnumStep.StatusToFunded;
                        this.OriginalTrancheStatus = TrancheStatus.Funded;

                        this.IncludedInTrancheContracts.ForEach(x => x.IsValid = true);
                        if (this.Validate() == true)
                        {
                            if (await FundingFunctions.ChangeStatusToFundedAsync(this.SelectedTrancheProfile, this.IncludedInTrancheContracts.ToList()) == true)
                            {
                                this.SelectedTrancheProfile.TrancheStatusId = (int)TrancheStatus.Funded;
                            }
                            else
                            {
                                this.OriginalTrancheStatus = (TrancheStatus)this.SelectedTrancheProfile.TrancheStatusId;
                            }
                        }
                        else
                        {
                            this.OriginalTrancheStatus = (TrancheStatus)this.SelectedTrancheProfile.TrancheStatusId;
                        }
                        await this.UnLockAsync();
                    }
                    this.BusyContent = string.Empty;
                    this.IsBusy = false;
                    break;
                case EnumStep.Delete:                   
                    if (await this.LockAsync())
                    {
                        bool canProceed = false;
                        ConfirmationWindowView confirm = new ConfirmationWindowView();
                        ConfirmmationViewModel confirmViewModel = new ConfirmmationViewModel();
                        confirmViewModel.Content = "Are you sure you want to delete?";
                        confirmViewModel.Title = "Delete - Funding";
                        confirm.DataContext = confirmViewModel;

                        confirm.ShowDialog();
                        if (confirm.DialogResult == false)
                        {
                            canProceed = false;
                        }
                        else
                        {
                            canProceed = true;
                        }

                        if (canProceed)
                        {
                            this.IsError = false;
                            this.IsFundingDateInvalid = false;
                            await FundingFunctions.DeleteTrancheAsync(this.SelectedTrancheProfile.TrancheId);
                            await this.UnLockAsync();
                            this.IsCheckedOut = this.MainViewModel.IsCheckedOut;
                            this.MainViewModel.OnCancelNewItem(EnumScreen.FundingSummary);
                            await this.MainViewModel.OnStepAsync(FundingSummaryViewModel.EnumStep.Start);
                            this.MainViewModel.RaiseActionsWhenChangeStep(EnumScreen.FundingSummary, EnumStep.Delete, this.SelectedTrancheProfile.TrancheId);
                            this.IsConfirmError = false;
                        }
                        else
                        {
                            await this.UnLockAsync();
                        }
                    }
                    break;
                case EnumStep.Error:
                    NotificationErrorView errorPopup = new NotificationErrorView();
                    NotificationErrorViewModel errorPopupViewModel = new NotificationErrorViewModel();
                    errorPopupViewModel.listCustomHyperlink = this.MainViewModel.ListErrorHyperlink;
                    errorPopup.DataContext = errorPopupViewModel;

                    errorPopup.Style = (Style)Application.Current.FindResource("RadWindowStyleNew");

                    errorPopup.ShowDialog();
                    break;
            }
            await base.OnStepAsync(stepName);
            if (!this.CurrentStep.Equals(EnumStep.SelectTrancheDate)
                && !this.CurrentStep.Equals(EnumStep.FunderSelected)
                && !this.CurrentStep.Equals(EnumStep.TrancheSelected))
            {
                this.SetActionCommandsAsync();
            }
        }
        /// <summary>
        /// The on step async.
        /// </summary>
        /// <param name="stepName">
        /// The step name.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public override async Task OnStepAsync(object stepName)
        {
            bool canProcess;
            this._currentEnumStep = (Asset.EnumSteps)Enum.Parse(typeof(Asset.EnumSteps), stepName.ToString());
            if (this._currentEnumStep != Asset.EnumSteps.DetailsState && this._currentEnumStep != Asset.EnumSteps.AssignedToState)
            {
                this.CurrentStep = this._currentEnumStep;
            }

            switch (this._currentEnumStep)
            {
                case Asset.EnumSteps.Start:
                    this.SetBusyAction(LoadingText);
                    this.GetPermssion();
                    this.ActiveViewModel = this;
                    await this.PopulateAllCollateralsForViewAsync();
                    this.RaiseSelectedItemChanged();
                    this.ResetBusyAction();
                    break;
                case Asset.EnumSteps.SelectedCollateral:
                    this.SetBusyAction(LoadingText);
                    if (this.OnStoryBoardChanged != null)
                    {
                        this.OnStoryBoardChanged(Asset.EnumSteps.GridContentState.ToString());
                    }

                    this.SetGridStype(false);
                    this.SetValueForAssetCollateralDetail(this.SelectedCollateral);

                    await this.GetDataSourceForAssetTypesScreen();
                    await this.AssetCollateralDetailViewModel.PopulateCollateralClasses(this.SelectedCollateral);
                    if (this.AssetCollateralDetailViewModel.ListCollateralDetail != null)
                    {
                        this.NotifySelectComboboxChanged();
                    }

                    this.SetActionCommandsAsync();
                    this.RaiseActionsWhenChangeStep(EnumScreen.AssetCollateralClasses, EnumSteps.SelectedCollateral, this.SelectedCollateral);
                    this.ResetBusyAction();
                    break;
                case Asset.EnumSteps.GridContentState:
                    if (this.OnStoryBoardChanged != null)
                    {
                        this.OnStoryBoardChanged(this._currentEnumStep.ToString());
                    }

                    break;
                case Asset.EnumSteps.DetailsState:
                    this.OnStepChanged(Asset.EnumSteps.DetailsState.ToString());
                    this.CurrentTab = Asset.EnumSteps.DetailsState;
                    break;
                case Asset.EnumSteps.AssignedToState:
                    this.OnStepChanged(Asset.EnumSteps.AssignedToState.ToString());
                    this.CurrentTab = Asset.EnumSteps.AssignedToState;
                    break;
                case Asset.EnumSteps.GridSummaryState:
                    if (this.OnStoryBoardChanged != null)
                    {
                        this.OnStoryBoardChanged(this._currentEnumStep.ToString());
                    }

                    break;
                case Asset.EnumSteps.AssignFeatureState:
                    this.AssetCollateralAssignTypeViewModel.SetBusyAction(LoadingText);
                    var items = new ObservableCollection<AssetCollateralRowItem>(this.DynamicCollateralViewModel.SelectedItems.Cast<AssetCollateralRowItem>());
                    if (items.Count != 0)
                    {
                        bool result;
                        List<int> list = new List<int>(items.Select(x => x.CollateralClassID));
                        result = await this.LockBulkUpdateAssetFeaturesAsync(list);
                        if (!result)
                        {
                            // Raise event to visible FormMenu if record selected is locked.
                            this.RaiseActionsWhenChangeStep(EnumScreen.AssetCollateralClasses, EnumSteps.ItemLocked);

                            // Change background if record selected is locked when editing.
                            this.SetGridStype(false);

                            return;
                        }

                        this.IsCheckedOut = true;
                        this.SetIsCheckedOut();
                        this.SetGridStype(true);
                        var selectedCollaterals = new ObservableCollection<AssetCollateralRowItem>(this.DynamicCollateralViewModel.SelectedItems.Cast<AssetCollateralRowItem>());
                        await this.AssetCollateralAssignTypeViewModel.GetListCollateralItems(selectedCollaterals);
                        this.AssetCollateralAssignTypeViewModel.SelectedItemChanged +=
                            this.AssetClassesTypeDetailViewModel_PropertyChanged;
                        if (this.OnStoryBoardChanged != null)
                        {
                            this.OnStoryBoardChanged(this._currentEnumStep.ToString());
                        }

                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetCollateralClasses, EnumSteps.EditBulkUpdate);
                        this.SetActionCommandsAsync();
                    }
                    else
                    {
                        this.ShowMessageAsync("Select one or more record to Assign Features.", "Confirm - Asset Feature");
                        this.CurrentStep = Asset.EnumSteps.None;
                    }

                    this.AssetCollateralAssignTypeViewModel.ResetBusyAction();
                    break;
                case Asset.EnumSteps.BulkUpdate:
                    this.DynamicCollateralViewModel.IsEnableHoverRow = true;
                    this.IsBulkUpdate = true;
                    this.SetActionCommandsAsync();
                    break;
                case Asset.EnumSteps.Edit:
                    if (this.SelectedCollateral != null && await this.LockBulkUpdateAssetFeaturesAsync(new List<int> { this.SelectedCollateral.CollateralClassID }, true) == false)
                    {
                        // Raise event to visible FormMenu if record selected is locked.
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetCollateralClasses, EnumSteps.ItemLocked);

                        // Change background if record selected is locked when editing.
                        this.SetGridStype(false);

                        return;
                    }

                    this.IsCheckedOut = true;
                    this.SetIsCheckedOut();
                    this.SetGridStype(true);
                    if (this.AssetCollateralTypeViewModel.IsCheckedOut)
                    {
                        this.AssetCollateralTypeViewModel.DynamicAssignAssetTypeViewModel.IsEnableHoverRow = true;
                    }

                    this.RaiseActionsWhenChangeStep(EnumScreen.AssetCollateralClasses, EnumSteps.Edit);
                    break;
                case Asset.EnumSteps.EditBulkUpdate:
                    items = new ObservableCollection<AssetCollateralRowItem>(this.DynamicCollateralViewModel.SelectedItems.Cast<AssetCollateralRowItem>());
                    if (items.Count != 0)
                    {
                        this.IsBulkUpdate = true;
                        bool result;
                        List<int> list = new List<int>(items.Select(x => x.CollateralClassID));
                        result = await this.LockBulkUpdateAssetFeaturesAsync(list);
                        if (!result)
                        {
                            // Raise event to visible FormMenu if record selected is locked.
                            this.RaiseActionsWhenChangeStep(EnumScreen.AssetCollateralClasses, EnumSteps.ItemLocked);

                            // Change background if record selected is locked when editing.
                            this.SetGridStype(false);

                            return;
                        }
                    }

                    this.IsCheckedOut = true;
                    this.SetIsCheckedOut();
                    this.SetGridStype(true);
                    this.RaiseActionsWhenChangeStep(EnumScreen.AssetCollateralClasses, EnumSteps.EditBulkUpdate);
                    break;
                case Asset.EnumSteps.SaveBulkUpdate:
                    try
                    {
                        this.AssetCollateralAssignTypeViewModel.SetBusyAction(LoadingText);
                        await this.SaveCollateralBulkUpdateAsync();
                        await this.UnLockBulkUpdateAssetFeaturesAsync();
                        this.IsBulkUpdate = false;
                        this.IsCheckedOut = false;
                        this.SetIsCheckedOut();
                        this.IsChanged = false;
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetCollateralClasses, EnumSteps.SaveAssignTypes);
                        this.SetGridStype(false);
                        this.AssetCollateralAssignTypeViewModel.ResetBusyAction();
                    }
                    catch (Exception exc)
                    {
                        ExceptionLogger.WriteLog(exc);
                        this.ShowErrorMessage("Error encountered while Saving Asset Feature Bulk Update.", "Asset Features");
                    }

                    break;
                case Asset.EnumSteps.Save:
                    try
                    {
                        this.Validate();
                        if (this.HasErrors == false)
                        {
                            if (!this.SelectedCollateral.IsNewCollateral)
                            {
                                await this.UnLockBulkUpdateAssetFeaturesAsync();
                            }
                            else
                            {
                                this.IsCheckedOut = false;
                                this.SetIsCheckedOut();
                                this.IsChanged = false;
                            }

                            this.IsCheckedOut = false;
                            this.SetIsCheckedOut();
                            this.IsChanged = false;
                            await this.SaveCollateralClassesAsync();

                            this.ValidateNotError();

                            await this.OnStepAsync(Asset.EnumSteps.SelectedCollateral);
                            
                            // this.AllCollateralClasses = new ObservableCollection<PPSRCollateralClass>(await AssetCollateralClassesFunction.GetAllPPSRCollateralClassesAsync());
                            this.UpdateDataCollateralsAsync();
                            this.RaiseActionsWhenChangeStep(EnumScreen.AssetCollateralClasses, EnumSteps.Save, this.SelectedCollateral.CollateralClassID);
                        }
                        else
                        {
                            this._currentEnumStep = Asset.EnumSteps.Error;
                            this.SetActionCommandsAsync();
                            this.OnErrorHyperlinkSelected();
                        }
                    }
                    catch (Exception exc)
                    {
                        ExceptionLogger.WriteLog(exc);
                        this.ShowErrorMessage("Error encountered while Saving Asset Feature Details.", "Asset Features");
                    }

                    break;
                case Asset.EnumSteps.Cancel:
                    canProcess = await this.CheckIfUnSavedChanges();
                    if (canProcess)
                    {
                        this.AssetCollateralDetailViewModel.ClearNotifyErrors();
                        this.ValidateNotError();

                        // Just do UnLockAsync if not in mode Add.
                        if (this.SelectedCollateral != null && !this.SelectedCollateral.IsNewCollateral)
                        {
                            await this.UnLockBulkUpdateAssetFeaturesAsync();
                        }
                        else
                        {
                            this.IsCheckedOut = false;
                            this.SetIsCheckedOut();
                            this.IsChanged = false;
                        }

                        this.IsCheckedOut = false;
                        this.IsChanged = false;
                        this.SetIsCheckedOut();
                        this.SetGridStype(false);
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetCollateralClasses, EnumSteps.Cancel);
                        if (this.SelectedCollateral == null || (this.SelectedCollateral != null && this.SelectedCollateral.IsNewCollateral))
                        {
                            this.OnCancelNewItem(EnumScreen.AssetCollateralClasses);
                            if (this.OnStoryBoardChanged != null)
                            {
                                this.OnStoryBoardChanged(Asset.EnumSteps.GridSummaryState.ToString());
                                this._currentEnumStep = Asset.EnumSteps.GridSummaryState;
                            }
                        }
                        else
                        {
                            await this.OnStepAsync(EnumSteps.SelectedCollateral);
                        }
                    }
                    else
                    {
                        this.CurrentStep = Asset.EnumSteps.None;
                    }

                    break;
                case Asset.EnumSteps.CancelAssignFeature:
                    canProcess = await this.CheckIfUnSavedChanges();
                    if (canProcess)
                    {
                        await this.UnLockBulkUpdateAssetFeaturesAsync();
                        this.IsChanged = false;
                        var selectedCollateralsCancel = new ObservableCollection<AssetCollateralRowItem>(this.DynamicCollateralViewModel.SelectedItems.Cast<AssetCollateralRowItem>());

                        this.IsCheckedOut = false;
                        this.SetIsCheckedOut();
                        this.IsChanged = false;
                        this.IsBulkUpdate = false;
                        await this.AssetCollateralAssignTypeViewModel.GetListCollateralItems(selectedCollateralsCancel);
                        this.IsCheckedOut = false;
                        this.SetIsCheckedOut();
                        this.SetGridStype(false);
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetCollateralClasses, EnumSteps.CancelAssignFeature);
                    }
                    else
                    {
                        this.CurrentStep = Asset.EnumSteps.None;
                    }

                    break;
                case Asset.EnumSteps.CancelBulkUpdate:
                    canProcess = await this.CheckIfUnSavedChanges();
                    if (canProcess)
                    {
                        this.IsBulkUpdate = false;
                        this.DynamicCollateralViewModel.SelectedItem = null;
                        this.DynamicCollateralViewModel.IsEnableHoverRow = false;
                        this.DynamicCollateralViewModel.SelectedRows = new List<object>();
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetCollateralClasses, EnumSteps.CancelBulkUpdate);
                    }

                    break;
                case Asset.EnumSteps.Error:
                    // Show NotificationWindow when click Error button.
                    NotificationErrorView errorPopup = new NotificationErrorView();
                    NotificationErrorViewModel errorPopupViewModel = new NotificationErrorViewModel();
                    errorPopupViewModel.listCustomHyperlink = this.ListErrorHyperlink;
                    errorPopup.DataContext = errorPopupViewModel;

                    errorPopup.Style = (Style)Application.Current.FindResource("RadWindowStyleNew");

                    errorPopup.ShowDialog();
                    break;
            }

            this.SetActionCommandsAsync();
        }
        /// <summary>
        /// The on step async.
        /// </summary>
        /// <param name="stepName">
        /// The step name.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public override async Task OnStepAsync(object stepName)
        {
            this.CurrentStep = (Asset.EnumSteps)Enum.Parse(typeof(Asset.EnumSteps), stepName.ToString());
            switch (this.CurrentStep)
            {
                case Asset.EnumSteps.Start:
                    this.SetBusyAction(LoadingText);            
                    this.ActiveViewModel = this;
                    this.GetPermission();
                    await this.GetDataSourceForGrid();
                    this.ResetBusyAction();
                    this.IsAdd = false;
                    this.SetActionCommandsAsync();
                    break;
                case Asset.EnumSteps.SelectModel:
                    this.SetBusyAction(LoadingText);
                    this.AssetModelDetail.GridStyle = (Brush)Application.Current.FindResource("GridStyleNotEdit");
                    this.RaiseActionsWhenChangeStep(
                        EnumScreen.AssetClassesModel,
                        Asset.EnumSteps.SelectModel,
                        this.SelectedModel);
                    this.AssetModelDetail.PopulateAllField();
                    this.ResetBusyAction();
                    this.SetActionCommandsAsync();
                    break;
                case Asset.EnumSteps.Add:
                    this.IsAdd = true;
                    EquipModel newModel = new EquipModel { IsNewModel = true, Enabled = true };
                    await this.SetSelectedModelAsync(newModel);
                    this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesModel, Asset.EnumSteps.Add);

                    await this.OnStepAsync(Asset.EnumSteps.Edit);
                    this.SetActionCommandsAsync();
                    break;
                case Asset.EnumSteps.Edit:
                    if (await this.LockAsync() == false)
                    {
                        this.RaiseActionsWhenChangeStep(EnumScreen.Users, Asset.EnumSteps.ItemLocked);
                        this.AssetModelDetail.GridStyle = (Brush)Application.Current.FindResource("GridStyleNotEdit");
                        await this.OnStepAsync(Asset.EnumSteps.SelectModel);
                    }
                    else
                    {
                        this.AssetModelDetail.GridStyle = (Brush)Application.Current.FindResource("GridStyleEdit");
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesModel, Asset.EnumSteps.Edit);
                        this.AssetModelDetail.IsCheckedOut = true;
                        this.SetEnableComboBox(true);
                        this.SetActionCommandsAsync();
                    }

                    break;
                case Asset.EnumSteps.Cancel:
                    bool canProcess;
                    canProcess = this.CheckIfUnSavedChanges();
                    if (canProcess)
                    {
                        var assetModelDetailViewModel = this.AssetModelDetail;
                        if (assetModelDetailViewModel != null)
                        {
                            assetModelDetailViewModel.IsCheckedOut = false;
                            this.SetEnableComboBox(false);
                            assetModelDetailViewModel.IsChanged = false;
                        }

                        if (!this.SelectedModel.IsNewModel)
                        {
                            await this.UnLockAsync();
                            this.SelectedModel = await AssetModelFunctions.GetEquipModelDetail(this.SelectedModel.EquipModelId);
                        }

                        this.ValidateNotError();
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesModel, Asset.EnumSteps.Cancel);
                        if (this.SelectedModel.IsNewModel)
                        {
                            this.OnCancelNewItem(EnumScreen.AssetClassesModel);
                            await this.OnStepAsync(Asset.EnumSteps.GridSummaryState);
                        }
                    }

                    this.SetActionCommandsAsync();
                    break;
                case Asset.EnumSteps.Save:
                    this.Validate();
                    if (this.HasErrors == false)
                    {
                        this.IsAdd = false;
                        this.ValidateNotError();
                        await Task.WhenAll(this.GetSelectedMake(), this.GetSelectedType(), this.GetSelectedCategory());
                        string previousModel = this.SelectedModel.Description;
                        this.SelectedModel.Description = this.AssetModelDetail.ModelDescription;
                        this.SelectedModel.Enabled = this.AssetModelDetail.ModelEnabled;
                        await
                            AssetModelFunctions.SaveAsync(
                                this.SelectedModel,
                                this.SelectedMake,
                                this.SelectedType,
                                this.SelectedCategory);

                        if (!this.SelectedModel.IsNewModel)
                        {
                            await this.UnLockAsync();
                            await this.GetAllModel();
                            this.UpdateSourceForGrid(previousModel);
                        }
                        else
                        {
                            this.AssetModelDetail.IsCheckedOut = false;
                            this.SetEnableComboBox(false);
                            this.AssetModelDetail.IsChanged = false;
                            AssetClassesModelRowItem addModel = new AssetClassesModelRowItem
                            {
                                EquipModelId = this.SelectedModel.EquipModelId,
                                Description = this.SelectedModel.Description,
                                Enabled = this.SelectedModel.Enabled,
                                IsMouseHover = this.SelectedModel.Enabled,
                            };
                            this.AllAssetModel.Add(addModel);
                            this.UpdateSourceForGrid();
                        }

                        this.AssetModelDetail.ResetSelectedComboBox();
                        this.AssetModelDetail.ModelId = this.SelectedItem.EquipModelId;
                        this.AssetModelDetail.PopulateAllField();

                        this.SelectedModel.IsNewModel = false;
                        this.AssetModelDetail.IsCheckedOut = false;
                        this.SetEnableComboBox(false);
                        this.AssetModelDetail.IsChanged = false;
                        this.AssetModelDetail.GridStyle = (Brush)Application.Current.FindResource("GridStyleNotEdit");
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesModel, Asset.EnumSteps.Save, this.SelectedModel);
                    }
                    else
                    {
                        this.CurrentStep = Asset.EnumSteps.Error;
                        this.OnErrorHyperlinkSelected();
                    }

                    this.SetActionCommandsAsync();
                    break;
                case Asset.EnumSteps.Error:
                    // Show NotificationWindow when click Error button.
                    NotificationErrorView errorPopup = new NotificationErrorView();
                    NotificationErrorViewModel errorPopupViewModel = new NotificationErrorViewModel();
                    errorPopupViewModel.listCustomHyperlink = this.ListErrorHyperlink;
                    errorPopup.DataContext = errorPopupViewModel;

                    errorPopup.Style = (Style)Application.Current.FindResource("RadWindowStyleNew");

                    errorPopup.ShowDialog();
                    this.SetActionCommandsAsync();
                    break;
                case Asset.EnumSteps.SaveAndAdd:
                    await this.OnStepAsync(Asset.EnumSteps.Save);
                    if (this.HasErrors == false)
                    {
                        await this.OnStepAsync(Asset.EnumSteps.Add);
                    }

                    this.SetActionCommandsAsync();
                    break;
                case Asset.EnumSteps.GridSummaryState:
                    this.DynamicAssetClassModelViewModel.IsEnableHoverRow = false;
                    if (this.DynamicAssetClassModelViewModel.SelectedRows != null)
                    {
                        this.DynamicAssetClassModelViewModel.SelectedRows = new List<object>();
                    }

                    this.StepChanged("MainGridState");
                    this.SetActionCommandsAsync();
                    break;
            }
        }
        /// <summary>
        /// The on step async.
        /// </summary>
        /// <param name="stepName">
        /// The step name.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public override async Task OnStepAsync(object stepName)
        {
            bool canProcess;
            this._currentEnumStep = (Asset.EnumSteps)Enum.Parse(typeof(Asset.EnumSteps), stepName.ToString());
            switch (this._currentEnumStep)
            {
                case Asset.EnumSteps.Start:
                    this.SetBusyAction(LoadingText);
                    this.GetPermission();
                    this._currentEnumStep = Asset.EnumSteps.Start;
                    this.ActiveViewModel = this;
                    await this.GetDataSourceForGrid();
                    this.SetActionCommandsAsync();
                    this.ResetBusyAction();
                    break;
                case Asset.EnumSteps.MainViewState:
                    this._currentEnumStep = Asset.EnumSteps.MainViewState;
                    this.DynamicAssetClassMakeViewModel.IsEnableHoverRow = false;
                    this.DynamicAssetClassMakeViewModel.SelectedRows = new List<object>();
                    this.IsStepBulkUpdate = false;
                    this.StepChanged("MainViewState");
                    this.SetActionCommandsAsync();
                    break;
                case Asset.EnumSteps.SelectedMake:
                    this.SetBusyAction(LoadingText);
                    if (this.ListItemLocks != null && this.ListItemLocks.Count > 0)
                    {
                        await this.UnLockAsync();
                    }

                    this.ClearNotifyErrors();
                    this.ValidateNotError();
                    this.SetBackgroundToNotEdit();
                    this._currentEnumStep = Asset.EnumSteps.SelectedMake;
                    this.StepChanged("MainContentState");
                    this.OnStoryBoardChanged(Asset.EnumSteps.DetailState.ToString());
                    this.GetDataSelectedMakeForDetailScreen();
                    await this.LoadDataForDetailScreen();
                    this.RaiseActionsWhenChangeStep(
                        EnumScreen.AssetClassesMake, 
                        Asset.EnumSteps.SelectedMake, 
                        this.SelectedMake);
                    this.SetActionCommandsAsync();
                    this.ResetBusyAction();
                    break;
                case Asset.EnumSteps.Edit:
                    if (await this.LockAsync())
                    {
                        this.SetBackgroundToEdit();
                        this.AssetMakeDetailViewModel.DynamicAssignAssetTypeViewModel.IsEnableHoverRow = true;
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesMake, Asset.EnumSteps.Edit);
                        this._currentEnumStep = Asset.EnumSteps.Edit;

                        this.IsCheckedOut = true;
                        this.SetActionCommandsAsync();
                    }

                    break;
                case Asset.EnumSteps.Add:
                    this.SetNewMakeClass();
                    this.SetBackgroundToEdit();
                    await this.AssetMakeDetailViewModel.GetDataSourceForAddScreen();
                    this.StepChanged("MainContentState");
                    this.OnStoryBoardChanged(Asset.EnumSteps.DetailState.ToString());
                    this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesMake, Asset.EnumSteps.Add);
                    await this.OnStepAsync(Asset.EnumSteps.Edit);
                    this._currentEnumStep = Asset.EnumSteps.Add;
                    this.SetActionCommandsAsync();
                    break;
                case Asset.EnumSteps.CancelAdd:
                    canProcess = await this.CheckIfUnSavedChanges();
                    if (canProcess)
                    {
                        this._currentEnumStep = Asset.EnumSteps.CancelAdd;
                        this.ValidateNotError();
                        this.ClearNotifyErrors();
                        this.DynamicAssetClassMakeViewModel.IsEnableHoverRow = false;
                        this.DynamicAssetClassMakeViewModel.SelectedItem = null;
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesMake, Asset.EnumSteps.Cancel);
                        this.OnCancelNewItem(EnumScreen.AssetClassesMake);
                        this.StepChanged("MainViewState");
                        this.IsCheckedOut = false;
                        this.IsChanged = false;
                        this.SetActionCommandsAsync();
                    }

                    break;
                case Asset.EnumSteps.Cancel:
                    canProcess = await this.CheckIfUnSavedChanges();

                    if (canProcess)
                    {
                        this.SetBusyAction(LoadingText);
                        if (this.SelectedMake != null && !this.SelectedMake.IsNewMakeClass)
                        {
                            await this.UnLockAsync();
                        }

                        this.SetBusyAction(LoadingText);
                        this.GetDataSelectedMakeForDetailScreen();
                        if (this.AssetMakeDetailViewModel != null)
                        {
                            await this.AssetMakeDetailViewModel.GetDataSourceForDetailScreen(this.SelectedMake);
                        }

                        this._currentEnumStep = Asset.EnumSteps.Cancel;
                        var assetMakeDetailViewModel = this.AssetMakeDetailViewModel;
                        if (assetMakeDetailViewModel != null)
                        {
                            assetMakeDetailViewModel.DynamicAssignAssetTypeViewModel.IsEnableHoverRow = false;
                            this.SetBackgroundToNotEdit();
                            this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesMake, Asset.EnumSteps.Cancel);
                            this.GetDataSelectedMakeForDetailScreen();
                            this.StepChanged("MainContentState");
                            this.OnStoryBoardChanged(Asset.EnumSteps.DetailState.ToString());
                            this.ValidateNotError();
                            this.ClearNotifyErrors();
                            assetMakeDetailViewModel.IsCheckedOut = false;
                            assetMakeDetailViewModel.IsChanged = false;
                        }

                        this.IsCheckedOut = false;
                        this.IsChanged = false;
                        this.ResetBusyAction();
                    }
                    else
                    {
                        this._currentEnumStep = Asset.EnumSteps.Edit;
                        this.Validate();
                        if (this.HasErrors)
                        {
                            this._currentEnumStep = Asset.EnumSteps.Error;
                        }
                    }

                    this.ResetBusyAction();
                    this.SetActionCommandsAsync();
                    break;
                case Asset.EnumSteps.Save:
                    this.Validate();
                    if (this.HasErrors == false)
                    {
                        this.SetBusyAction(LoadingText);
                        this.ValidateNotError();
                        this.ClearNotifyErrors();
                        string previousMake = this.SelectedMake.Description;
                        EquipMake selectMake = await this.SaveAllDataForDetailScreen();
                        this.SelectedMake.EquipMakeId = selectMake.EquipMakeId;
                        this.SelectedMake.IsMouseHover = true;
                        this.AllAssetMake = await AssetClassesMakeFunctions.GetDataOnGrid();
                        if (!this.SelectedMake.IsNewMakeClass)
                        {
                            await this.UnLockAsync();
                            this.UpdateSourceForGrid(previousMake);
                        }
                        else
                        {
                            this._selectedMake.Enabled = selectMake.Enabled;
                            this.UpdateSourceForGrid();
                            this.IsCheckedOut = false;
                            this.AssetMakeDetailViewModel.IsCheckedOut = false;
                            this.IsChanged = false;
                        }

                        this.AssetMakeDetailViewModel.IsModeEdit = true;
                        this.SelectedMake.IsNewMakeClass = false;
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesMake, Asset.EnumSteps.Save, selectMake.EquipMakeId);
                        await this.OnStepAsync(Asset.EnumSteps.SelectedMake.ToString());
                        this.ResetBusyAction();
                    }
                    else
                    {
                        this._currentEnumStep = Asset.EnumSteps.Error;
                        this.OnErrorHyperlinkSelected();
                    }

                    this.SetActionCommandsAsync();
                    break;

                case Asset.EnumSteps.SaveAndAdd:
                    this.Validate();
                    if (!this.HasErrors)
                    {
                        this._currentEnumStep = Asset.EnumSteps.SaveAndAdd;
                        await this.OnStepAsync(Asset.EnumSteps.Save.ToString());
                        await this.OnStepAsync(Asset.EnumSteps.Add.ToString());
                    }
                    else
                    {
                        this._currentEnumStep = Asset.EnumSteps.Error;
                        this.OnErrorHyperlinkSelected();
                    }

                    this.SetActionCommandsAsync();
                    break;
                case Asset.EnumSteps.BulkUpdate:
                    this._currentEnumStep = Asset.EnumSteps.BulkUpdate;
                    this.DynamicAssetClassMakeViewModel.IsEnableHoverRow = true;
                    this.IsStepBulkUpdate = true;
                    this.SetActionCommandsAsync();
                    break;
                case Asset.EnumSteps.AssignModel:
                    if (this.DynamicAssetClassMakeViewModel.SelectedItems.Count() > 0)
                    {
                        if (await this.LockAsync())
                        {
                            this.SetBusyAction(LoadingText);
                            if (this.AssetMakeAssignModelViewModel != null)
                            {
                                await this.GetListModelItemsForAssignModelScreen();
                            }

                            this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesMake, Asset.EnumSteps.AssignModel);
                            this.SetBackgroundToEdit();
                            this.StepChanged("MainContentState");
                            this.OnStoryBoardChanged(Asset.EnumSteps.BulkState.ToString());
                            this.IsCheckedOut = true;
                            this.IsChanged = false;
                            this.AssetMakeAssignModelViewModel.IsCheckedOut = true;
                            this.SetActionCommandsAsync();
                            this.ResetBusyAction();
                        }
                    }
                    else
                    {
                        this.ShowMessageAsync("Select one or more record to Assign Model.", "Confirm - Asset Classes Make");
                    }

                    break;
                case Asset.EnumSteps.CancelBulkUpdate:
                    canProcess = await this.CheckIfUnSavedChanges();
                    if (canProcess)
                    {
                        this.SetBusyAction(LoadingText);
                        this.DynamicAssetClassMakeViewModel.IsEnableHoverRow = false;
                        this.DynamicAssetClassMakeViewModel.SelectedRows = new List<object>();
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesMake, Asset.EnumSteps.Cancel);
                        this.OnCancelNewItem(EnumScreen.AssetClassesMake);
                        this._currentEnumStep = Asset.EnumSteps.CancelBulkUpdate;
                        this.IsStepBulkUpdate = false;
                        this.IsCheckedOut = false;
                        this.IsChanged = false;
                        this.ResetBusyAction();
                    }
                    else
                    {
                        this._currentEnumStep = Asset.EnumSteps.BulkUpdate;
                    }

                    this.SetActionCommandsAsync();
                    break;
                case Asset.EnumSteps.EditBulkUpdate:
                    this.DynamicAssetClassMakeViewModel.IsEnableHoverRow = true;
                    this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesMake, Asset.EnumSteps.Edit);
                    this._currentEnumStep = Asset.EnumSteps.EditBulkUpdate;
                    this.IsCheckedOut = true;
                    this.SetActionCommandsAsync();
                    break;
                case Asset.EnumSteps.EditAssignModel:
                    if (await this.LockAsync())
                    {
                        this.SetBusyAction(LoadingText);
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesMake, Asset.EnumSteps.AssignModel);
                        this.SetBackgroundToEdit();
                        this._currentEnumStep = Asset.EnumSteps.EditAssignModel;
                        this.AssetMakeAssignModelViewModel.IsCheckedOut = true;
                        this.IsCheckedOut = true;
                        this.SetActionCommandsAsync();
                        this.ResetBusyAction();
                    }

                    break;
                case Asset.EnumSteps.CancelAssignModel:
                    canProcess = await this.CheckIfUnSavedChanges();
                    if (canProcess)
                    {
                        this.SetBusyAction(LoadingText);
                        await this.UnLockAsync();
                        await this.GetListModelItemsForAssignModelScreen();
                        this.DynamicAssetClassMakeViewModel.IsEnableHoverRow = false;
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesMake, Asset.EnumSteps.CancelAssignModel);
                        this.SetBackgroundToNotEdit();
                        this._currentEnumStep = Asset.EnumSteps.CancelAssignModel;
                        this.AssetMakeAssignModelViewModel.IsCheckedOut = false;
                        this.IsCheckedOut = false;
                        this.IsChanged = false;
                        this.ResetBusyAction();
                    }
                    else
                    {
                        this._currentEnumStep = Asset.EnumSteps.EditAssignModel;
                    }

                    this.SetActionCommandsAsync();
                    break;
                case Asset.EnumSteps.SaveAssignModel:
                    this.SetBusyAction(LoadingText);
                    await this.UnLockAsync();
                    await this.SaveAllDataForAssignModelScreen();
                    this._currentEnumStep = Asset.EnumSteps.SaveAssignModel;
                    this.RaiseActionsWhenChangeStep(EnumScreen.AssetClassesMake, Asset.EnumSteps.SaveAssignModel);
                    this.SetBackgroundToNotEdit();
                    this.IsCheckedOut = false;
                    this.AssetMakeAssignModelViewModel.IsCheckedOut = false;
                    this.IsChanged = false;
                    this.SetActionCommandsAsync();
                    this.ResetBusyAction();
                    break;
                case Asset.EnumSteps.Error:
                    // Show NotificationWindow when click Error button.
                    NotificationErrorView errorPopup = new NotificationErrorView();
                    NotificationErrorViewModel errorPopupViewModel = new NotificationErrorViewModel();
                    errorPopupViewModel.listCustomHyperlink = this.ListErrorHyperlink;
                    errorPopup.DataContext = errorPopupViewModel;
                    errorPopup.Style = (Style)Application.Current.FindResource("RadWindowStyleNew");
                    errorPopup.ShowDialog();
                    this.SetActionCommandsAsync();
                    break;
            }  
        }
        /// <summary>
        /// The on step async.
        /// </summary>
        /// <param name="stepName">
        /// The step name.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public override async Task OnStepAsync(object stepName)
        {
            bool canProcess;
            this._currentEnumStep = (Asset.EnumSteps)Enum.Parse(typeof(Asset.EnumSteps), stepName.ToString());
            switch (this._currentEnumStep)
            {
                case Asset.EnumSteps.Start:
                    this.SetBusyAction(LoadingText);
                    this._currentEnumStep = Asset.EnumSteps.Start;
                    this.ActiveViewModel = this;
                    this.IsAdd = false;
                    this.GetPermission();
                    await this.GetDataSourceForGrid();
                    this.RaiseSelectedItemChanged();
                    this.SetActionCommandsAsync();
                    this.ResetBusyAction();
                    break;
                case Asset.EnumSteps.SelectRegister:
                    this._currentEnumStep = Asset.EnumSteps.SelectRegister;
                    this.StepChanged("MainContentState");
                    this.AssetRegistersDetailViewModel.ClearNotifyErrors();
                    this.ValidateNotError();
                    this.OnStoryBoardChanged(Asset.EnumSteps.DetailState.ToString());
                    await AssetRegistersDetailViewModel.GetDetailDataSource(this.SelectedRegister.ID);
                    this.SetBackgroundToNotEdit();
                    this.RaiseActionsWhenChangeStep(EnumScreen.AssetRegisters, Asset.EnumSteps.SelectRegister, this.SelectedRegister);
                    this.SetActionCommandsAsync();
                    break;
                case Asset.EnumSteps.Add:
                    this.IsAdd = true;
                    this.SetNewRegister();
                    this.SetBackgroundToEdit();
                    this.StepChanged("MainContentState");
                    await AssetRegistersDetailViewModel.GetDataSourceForAddScreen();
                    this.AssetRegistersDetailViewModel.DynamicRegisterAssignViewModel.IsEnableHoverRow = true;
                    this.OnStoryBoardChanged(Asset.EnumSteps.DetailState.ToString());
                    this.RaiseActionsWhenChangeStep(EnumScreen.AssetRegisters, Asset.EnumSteps.Add);
                    await this.OnStepAsync(Asset.EnumSteps.EditRegisterDetail);
                    this.IsAdd = false;
                    this._currentEnumStep = Asset.EnumSteps.Add;
                    this.AssetRegistersDetailViewModel.IsChanged = false;
                    this.SetActionCommandsAsync();
                    break;
                case Asset.EnumSteps.MainViewState:
                    this._currentEnumStep = Asset.EnumSteps.MainViewState;
                    this.DynamicAssetRegisterViewModel.IsEnableHoverRow = false;
                    this.DynamicAssetRegisterViewModel.SelectedRows = new List<object>();

                    this.StepChanged("MainViewState");
                    this.SetActionCommandsAsync();
                    break;
                case Asset.EnumSteps.CancelAdd:
                    canProcess = await this.CheckIfUnSavedChanges();
                    if (canProcess)
                    {
                        this._currentEnumStep = Asset.EnumSteps.CancelAdd;
                        this.ValidateNotError();
                        this.AssetRegistersDetailViewModel.ClearNotifyErrors();
                        this.DynamicAssetRegisterViewModel.IsEnableHoverRow = false;
                        this.DynamicAssetRegisterViewModel.SelectedItem = null;
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetRegisters, Asset.EnumSteps.Cancel);
                        this.OnCancelNewItem(EnumScreen.AssetRegisters);
                        this.StepChanged("MainViewState");
                        this.AssetRegistersDetailViewModel.IsCheckedOut = false;
                        this.AssetRegistersDetailViewModel.IsChanged = false;
                        this.SetActionCommandsAsync();
                        if (this.SelectedRegister.IsNewRegister)
                        {
                            this.AssetRegistersDetailViewModel.AssetRegisterLocations =
                                new ObservableCollection<AssetRegisterLocationRowItem>();
                        }
                    }

                    break;
                case Asset.EnumSteps.EditRegisterSummary:
                    this.SetBusyAction(LoadingText);
                    this._currentEnumStep = Asset.EnumSteps.EditRegisterSummary;
                    if (await this.LockAsync() == false)
                    {
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetRegisters, Asset.EnumSteps.ItemLocked);
                    }
                    else
                    {
                        
                        this.InEditSummaryGrid = true;
                        this.SetBackgroundToEdit();
                        this.IsCheckedOut = true;
                        var defaultReg = this.DynamicAssetRegisterViewModel.MembersTable.Rows.FirstOrDefault(a =>
                            {
                                var assetRegisterRowItem = a.RowObject as AssetRegisterRowItem;
                                return assetRegisterRowItem != null && assetRegisterRowItem.IsRadioSelected;
                            });
                        if (defaultReg != null)
                        {
                            this.DefaultAssetRegister = (AssetRegisterRowItem)defaultReg.RowObject;
                        }

                        this.DynamicAssetRegisterViewModel.IsEnableRadioButtonRow = true;
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetRegisters, Asset.EnumSteps.Edit);
                        this.SetActionCommandsAsync();
                    }

                    this.ResetBusyAction();
                    break;
                case Asset.EnumSteps.CancelRegisterSummary:
                    this.SetBusyAction(LoadingText);
                    this._currentEnumStep = Asset.EnumSteps.CancelRegisterSummary;
                    canProcess = await this.CheckIfUnSavedChanges();
                    if (canProcess)
                    {
                        await this.UnLockAsync();
                        this.DynamicAssetRegisterViewModel.MaxWidthGrid = 700;
                        this.DynamicAssetRegisterViewModel.IsEnableHoverRow = false;
                        this.DynamicAssetRegisterViewModel.IsShowGroupPanel = true;
                        this.DynamicAssetRegisterViewModel.IsEnableRadioButtonRow = false;

                        // make sure that only one radio button is checked belong to DefaultAssetRegister
                        this.DefaultAssetRegister.IsRadioSelected = false;
                        this.DynamicAssetRegisterViewModel.SelectedRadioRows = null;
                        this.DynamicAssetRegisterViewModel.SelectedRadioRows = this.DefaultAssetRegister;
                        this.DefaultAssetRegister.IsRadioSelected = true;
                        this.DynamicAssetRegisterViewModel.SelectedRadioItems = this.DefaultAssetRegister;
                        this.DynamicAssetRegisterViewModelOnSelectedRadioChange(this.DefaultAssetRegister, null);

                        // update default row
                        this.InEditSummaryGrid = false;
                        this.SetBackgroundToNotEdit();
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetRegisters, Asset.EnumSteps.Cancel);
                        this.SetActionCommandsAsync();
                    }

                    this.ResetBusyAction();
                    break;
                case Asset.EnumSteps.SaveRegisterSummary:
                    this.SetBusyAction(LoadingText);
                    await this.UnLockAsync();
                    this._currentEnumStep = Asset.EnumSteps.SaveRegisterSummary;
                    var item = this.DynamicAssetRegisterViewModel.SelectedRadioItems as AssetRegisterRowItem;
                    await AssetRegisterFunction.SaveSumaryGridEdit(item);
                    this.RaiseActionsWhenChangeStep(EnumScreen.AssetRegisters, Asset.EnumSteps.SaveRegisterSummary);
                    this.DynamicAssetRegisterViewModel.MaxWidthGrid = 700;
                    this.DynamicAssetRegisterViewModel.IsEnableHoverRow = false;
                    this.DynamicAssetRegisterViewModel.IsShowGroupPanel = true;
                    this.DynamicAssetRegisterViewModel.IsEnableRadioButtonRow = false;

                    // make sure that only one radio button is checked belong to item
                    if (item != null)
                    {
                        item.IsRadioSelected = false;
                        this.DynamicAssetRegisterViewModel.SelectedRadioRows = null;
                        this.DynamicAssetRegisterViewModel.SelectedRadioRows = item;
                        item.IsRadioSelected = true;
                        this.DynamicAssetRegisterViewModelOnSelectedRadioChange(item, null);
                    }

                    this.InEditSummaryGrid = false;
                    this.SetActionCommandsAsync();
                    this.ResetBusyAction();
                    break;
                case Asset.EnumSteps.EditRegisterDetail:
                    this._currentEnumStep = Asset.EnumSteps.EditRegisterDetail;
                    if (await this.LockAsync() == false)
                    {
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetRegisters, Asset.EnumSteps.ItemLocked);
                        this.SetBackgroundToNotEdit();
                        await this.OnStepAsync(Asset.EnumSteps.SelectRegister);
                    }
                    else
                    {
                        this.SetBackgroundToEdit();
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetRegisters, Asset.EnumSteps.Edit);
                        this.AssetRegistersDetailViewModel.DynamicRegisterAssignViewModel.IsEnableHoverRow = true;
                        this.AssetRegistersDetailViewModel.DynamicRegisterLocationViewModel.IsEnableHoverRow = true;
                        this.AssetRegistersDetailViewModel.IsCheckedOut = true;
                        this.AssetRegistersDetailViewModel.DynamicRegisterLocationViewModel.ToolbarVisibilityChanged =
                        Visibility.Visible;
                        this.IsCheckedOut = false;
                        SetActionCommandsAsync();
                    }

                    break;
                case Asset.EnumSteps.CancelRegisterDetail:
                    this._currentEnumStep = Asset.EnumSteps.CancelRegisterDetail;
                    canProcess = await this.AssetRegistersDetailViewModel.CheckIfUnSavedChanges();
                    if (canProcess)
                    {
                        this.SetBusyAction(LoadingText);
                        if (!this.SelectedRegister.IsNewRegister)
                        {
                            await this.UnLockAsync();
                            await AssetRegistersDetailViewModel.GetDetailDataSource(this.SelectedRegister.ID);
                            this.AssetRegistersDetailViewModel.DynamicRegisterAssignViewModel.IsEnableHoverRow = false;
                            this.AssetRegistersDetailViewModel.IsCheckedOut = false;
                        }
                        else
                        {
                            this.AssetRegistersDetailViewModel.IsCheckedOut = false;
                            this.AssetRegistersDetailViewModel.IsChanged = false;
                        }

                        this.ValidateNotError();
                        this.AssetRegistersDetailViewModel.ClearNotifyErrors();
                        this.SetBackgroundToNotEdit();
                        this.AssetRegistersDetailViewModel.IsChanged = false;
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetRegisters, Asset.EnumSteps.Cancel);
                        this.AssetRegistersDetailViewModel.DynamicRegisterLocationViewModel.ToolbarVisibilityChanged =
                        Visibility.Collapsed;
                        if (this.SelectedRegister.IsNewRegister)
                        {
                            this.AssetRegistersDetailViewModel.AssetRegisterLocations = new ObservableCollection<AssetRegisterLocationRowItem>();
                            this.OnCancelNewItem(EnumScreen.AssetRegisters);
                            await this.OnStepAsync(Asset.EnumSteps.MainViewState);
                        }

                        this.SetActionCommandsAsync();
                        this.ResetBusyAction();
                    }

                    break;
                case Asset.EnumSteps.SaveRegisterDetail:
                    this.SetBusyAction(LoadingText);
                    this._currentEnumStep = Asset.EnumSteps.SaveRegisterDetail;
                    this.AssetRegistersDetailViewModel.Validate();
                    if (this.AssetRegistersDetailViewModel.HasErrors == false)
                    {
                        this.ValidateNotError();
                        this.AssetRegistersDetailViewModel.ClearNotifyErrors();
                        AssetRegister selectedRegister = await this.SaveAllDataForDetailScreen();
                        this.AssetRegistersDetailViewModel.IsCheckedOut = false;
                        this.AssetRegistersDetailViewModel.IsChanged = false;
                        this.AssetRegistersDetailViewModel.DynamicRegisterLocationViewModel.ToolbarVisibilityChanged = Visibility.Collapsed;
                        if (!this.IsAdd)
                        {
                            await this.UnLockAsync();
                        }

                        this.SetBackgroundToNotEdit();
                        if (AssetRegisterFunction.GetCategory() == 7)
                        {
                            this.AllAssetRegister = await AssetRegisterFunction.GetDataOnGridInternalCompany();
                        }
                        else
                        {
                            if (AssetRegisterFunction.GetCategory() == 5)
                            {
                                this.AllAssetRegister = await AssetRegisterFunction.GetDataOnGridFinancier();
                            }
                        }

                        // Update selected 
                        this.SelectedRegister.ID = selectedRegister.ID;
                        this.SelectedRegister.RegisterName = selectedRegister.RegisterName;

                        // Update record on grid
                        this.UpdateDataRegisters();
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetRegisters, Asset.EnumSteps.Save, selectedRegister.ID);
                        await AssetRegistersDetailViewModel.GetDetailDataSource(selectedRegister.ID);
                        this.AssetRegistersDetailViewModel.DynamicRegisterAssignViewModel.IsEnableHoverRow = false;
                        await this.OnStepAsync(Asset.EnumSteps.SelectRegister);
                        this.AssetRegistersDetailViewModel.IsEditMode = true;
                    }
                    else
                    {
                        this._currentEnumStep = Asset.EnumSteps.Error;
                        this.SetActionCommandsAsync();
                        this.ListErrorHyperlink = this.AssetRegistersDetailViewModel.ListErrorHyperlink;
                        this.OnErrorHyperlinkSelected();
                    }

                    this.SetActionCommandsAsync();
                    this.ResetBusyAction();
                    break;
                case Asset.EnumSteps.Error:
                    this._currentEnumStep = Asset.EnumSteps.Error;
                    NotificationErrorView errorPopup = new NotificationErrorView();
                    NotificationErrorViewModel errorPopupViewModel = new NotificationErrorViewModel();
                    errorPopupViewModel.listCustomHyperlink = this.ListErrorHyperlink;
                    errorPopup.DataContext = errorPopupViewModel;
                    errorPopup.Style = (Style)Application.Current.FindResource("RadWindowStyleNew");
                    errorPopup.ShowDialog();
                    this.SetActionCommandsAsync();
                    break;
            }
        }
        public override async Task OnStepAsync(object stepName)
        {
            this.CurrentStep = (EnumStep)Enum.Parse(typeof(EnumStep), stepName.ToString());
            switch (this.CurrentStep)
            {
                case EnumStep.Start:
                    this._Failures.Clear();
                    this.ValidationSummary.Clear();
                    this.MainViewModel.ValidateNotError();
                    this.MainViewModel.ListErrorHyperlink.Clear();
                    this.IsError = false;
                    this.IsFundingDateInvalid = false;
                    this.StillError = false;
                    if (this.IncludedInTrancheContractsOrigin != null)
                    {
                        this.IncludedInTrancheContractsOrigin = new List<TrancheContractSummary>();
                    }
                    this.MainViewModel.RaiseActionsWhenChangeStep(EnumScreen.FundingSummary, EnumSteps.Edit);
                    this.SelectedTrancheProfile = new FundingTranche { NodeId = -1, EntityId = -1, TrancheDate = DateTime.Today, TrancheStatusId = (int)TrancheStatus.Pending, AssumedRate = 0, LossReserve = 0, DDProfile = -1 };
                    this.TrancheDateText = this.SelectedTrancheProfile.TrancheDate;
                    await base.OnStepAsync(EnumStep.Start);
                    this.InternalSelectedFunder = this.AllFunders.FirstOrDefault(f => f.Id == this.SelectedTrancheProfile.NodeId);
                    this.IsCheckedOut = true;
                    this.IsChanged = false;
                    this.AllTrancheStatuses.Remove(this.AllTrancheStatuses.Where(status => status.Id == (int)TrancheStatus.Confirmed).FirstOrDefault());
                    this.AllTrancheStatuses.Remove(this.AllTrancheStatuses.Where(status => status.Id == (int)TrancheStatus.Funded).FirstOrDefault());
                    this.OriginalTrancheStatus = TrancheStatus.Pending;
                    this.SelectedTrancheProfile.PropertyChanged -= this.SelectedTrancheProfile_PropertyChanged;
                    this.SelectedTrancheProfile.PropertyChanged += this.SelectedTrancheProfile_PropertyChanged;

                    break;
                case EnumStep.ResultState:
                    this.IsFundingDateError = false;
                    if (Validate(() => CurrentStep) == false)
                    {
                        this.MainViewModel.RaiseActionsWhenChangeStep(EnumScreen.FundingSummary, EnumStep.ResultState);

                        if (this.SelectedFunder == null)
                        {
                            this.IsError = true;
                        }
                        else
                        {
                            this.IsError = false;
                        }
                        if (this.TrancheDateText == null)
                        {
                            this.IsFundingDateInvalid = true;
                        }
                        else
                        {
                            this.IsFundingDateInvalid = false;
                        }
                        string tabHyperlinkError = string.Empty;
                        this.ListErrorHyperlink = new List<CustomHyperlink>();

                        foreach (var error in this.ValidationSummary)
                        {
                            var errorHyperlink = new CustomHyperlink();
                            errorHyperlink.HyperlinkHeader = error.ErrorMessage;

                            // gets the action for the error ErrorHyperlink
                            var arrayProperiesError = error.PropertyName.Split('.');
                            if (arrayProperiesError.Length > 2)
                            {
                                tabHyperlinkError = arrayProperiesError[2];
                            }
                            else if (arrayProperiesError.Length > 0)
                            {
                                tabHyperlinkError = arrayProperiesError[0];
                            }

                            switch (tabHyperlinkError)
                            {
                                case "CurrentStep":
                                    errorHyperlink.Action = HyperLinkAction.SummaryState;
                                    errorHyperlink.SelectedStyle = (Style)Application.Current.FindResource("HyperlinkLikeButton");
                                    break;
                                default:
                                    errorHyperlink.Action = HyperLinkAction.None;
                                    errorHyperlink.SelectedStyle = (Style)Application.Current.FindResource("HyperlinkLikeButton");
                                    break;
                            }
                            this.ListErrorHyperlink.Add(errorHyperlink);
                        }

                        this.SetActionCommandsAsync();
                        this.MainViewModel.ListErrorHyperlink = this.ListErrorHyperlink;
                        this.MainViewModel.OnErrorHyperlinkSelected();
                        this.MainViewModel.RaiseActionsWhenChangeStep(EnumScreen.FundingSummary, EnumSteps.Edit);
                        return;
                    }
                    if (this.ValidationSummary.Count == 0)
                    {
                        this.MainViewModel.ValidateNotError();
                        this.IsError = false;
                        this.IsFundingDateInvalid = false;
                    }

                    this.MainViewModel.RaiseActionsWhenChangeStep(EnumScreen.FundingSummary, EnumSteps.Edit);
                    break;

                case EnumStep.FunderSelected:
                    await Task.WhenAll(this.FetchDefaultFundingStatusesByFunderAsync(),
                    this.FetchDefaultFinanceTypesByFunderAsync(),
                    this.FetchDefaultInternalCompaniesByFunderAsync(),
                    this.FetchDefaultSuppliersByFunderAsync(),
                    this.FetchDefaultFundersByFunderAsync());
                    this.TrancheDateText = this.SelectedTrancheProfile.TrancheDate;
                    await this.SetDefaultsByFundingProfileAsync();
                    break;
                case EnumStep.Cancel:
                    this.IsFundingDateError = false;
                    if (this.CheckIfUnSavedChanges())
                    {
                        this.IsCheckedOut = this.MainViewModel.IsCheckedOut;
                        this.MainViewModel.OnCancelNewItem(EnumScreen.FundingSummary);
                        await this.MainViewModel.OnStepAsync(FundingSummaryViewModel.EnumStep.Start);
                        this.MainViewModel.ValidateNotError();
                        this.IsError = false;
                        this.IsFundingDateInvalid = false;
                    }
                    break;
                case EnumStep.Save:
                    this.StillError = true;
                    this.IsFundingDateError = false;
                    this.IncludedInTrancheContracts.ForEach(x => x.IsValid = true);
                    if (this.Validate())
                    {
                        this.MainViewModel.ValidateNotError();
                        this.IsError = false;
                        this.IsFundingDateInvalid = false;
                        await this.SaveAsync();
                        this.IsCheckedOut = false;
                        this.IsChanged = false;
                        this.MainViewModel.AddedTrancheId = this.SelectedTrancheProfile.TrancheId;
                        await this.MainViewModel.OnStepAsync(FundingSummaryViewModel.EnumStep.TrancheAdded);
                        this.MainViewModel.RaiseActionsWhenChangeStep(EnumScreen.FundingSummary, EnumStep.Save, this.SelectedTrancheProfile.TrancheId);
                    }
                    else
                    {
                        this.SetActionCommandsAsync();
                        foreach (var error in this.ListErrorHyperlink)
                        {
                            if (
                                error.HyperlinkHeader.Equals(
                                    "The new Funding Date requires selected records to be removed from the Tranche. Please check the Results page for errors."))
                            {
                                error.Action = HyperLinkAction.ResultState;
                            }
                        }
                        this.MainViewModel.ListErrorHyperlink = this.ListErrorHyperlink;
                        this.MainViewModel.OnErrorHyperlinkSelected();
                        if (this.SelectedFunder == null)
                        {
                            this.IsError = true;
                        }
                        else
                        {
                            this.IsError = false;
                        }
                        if (this.TrancheDateText == null)
                        {
                            this.IsFundingDateInvalid = true;
                        }
                        else
                        {
                            this.IsFundingDateInvalid = false;
                        }
                    }
                    break;

                case EnumStep.Error:
                    NotificationErrorView errorPopup = new NotificationErrorView();
                    NotificationErrorViewModel errorPopupViewModel = new NotificationErrorViewModel();
                    errorPopupViewModel.listCustomHyperlink = this.MainViewModel.ListErrorHyperlink;
                    errorPopup.DataContext = errorPopupViewModel;

                    errorPopup.Style = (Style)Application.Current.FindResource("RadWindowStyleNew");

                    errorPopup.ShowDialog();
                    break;

            }
            await base.OnStepAsync(stepName);
            if (!this.CurrentStep.Equals(EnumStep.SelectTrancheDate)
                && !this.CurrentStep.Equals(EnumStep.FunderSelected))
            {
                this.SetActionCommandsAsync();
            }
        }
        /// <summary>
        /// The on step async.
        /// </summary>
        /// <param name="stepName">
        /// The step name.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public override async Task OnStepAsync(object stepName)
        {
            bool canProcess;
            var step = (EnumSteps)Enum.Parse(typeof(EnumSteps), stepName.ToString());
            switch (step)
            {
                case EnumSteps.Start:
                    this._CurrentEnumStep = EnumSteps.Start;
                    this.AssetSettings = await AssetSettingsFunctions.ReadAssetClassSettings();
                    var allCategoryDefault = new ObservableCollection<EquipCategory>(await AssetSettingsFunctions.ReadAllCategoryDefaultAssetSystemSettingsAsync());
                    allCategoryDefault.Add(new EquipCategory
                    {
                        EquipCatId = -1,
                        Description = "<None>",
                    });
                    this.Category =
                    allCategoryDefault.Select(
                    cate => new DropdownList { Description = cate.Description, ID = cate.EquipCatId })
                    .OrderBy(item => item.Description)
                    .ToList();
                    if (this.AssetSettings != null)
                    {
                        this.SelectedCategory = this.Category.FirstOrDefault(x => x.ID == this.AssetSettings.DefaultCategoryID);
                    }

                    this.SetBackgroundToNotEdit();
                    this.SetActionCommandsAsync();
                    break;
                case EnumSteps.Edit:
                    if (await this.LockAsync())
                    {
                        this.SetBackgroundToEdit();
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetSettings, EnumSteps.Edit);
                        this._CurrentEnumStep = EnumSteps.Edit;
                        this.SetActionCommandsAsync();
                    }

                    break;
                case EnumSteps.Save:
                    this.Validate();
                    if (this.HasErrors == false)
                    {
                        this.ValidateNotError();
                        this.ClearNotifyErrors();
                        await this.UnLockAsync();
                        this.SetBackgroundToNotEdit();
                        if (this.SelectedCategory != null)
                        {
                            this.AssetSettings.DefaultCategoryID = this.SelectedCategory.ID;
                        }
                        else
                        {
                            await this.CheckCategoryIsEnalbe(this.CurrentCategory);
                            this.AssetSettings.DefaultCategoryID = this.SelectedCategory.ID;
                        }

                        if (!this.AssetSettings.IncludeMake)
                        {
                            this.AssetSettings.IncludeModel = false;
                        }

                        await AssetSettingsFunctions.UpdateAssetClassSettings(this.AssetSettings);
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetSettings, EnumSteps.Save);
                        this._CurrentEnumStep = EnumSteps.Save;
                        await this.OnStepAsync(EnumSteps.Start);
                        this.SetActionCommandsAsync();
                    }
                    else
                    {
                        this._CurrentEnumStep = EnumSteps.Error;
                        this.SetActionCommandsAsync();
                        this.OnErrorHyperlinkSelected();
                    }

                    break;
                case EnumSteps.Cancel:
                    canProcess = await this.CheckIfUnSavedChanges();
                    if (canProcess)
                    {
                        this.ValidateNotError();
                        this.ClearNotifyErrors();
                        await this.UnLockAsync();
                        this.SetBackgroundToNotEdit();
                        this._CurrentEnumStep = EnumSteps.Cancel;
                        await this.OnStepAsync(EnumSteps.Start);
                        this.RaiseActionsWhenChangeStep(EnumScreen.AssetSettings, EnumSteps.Cancel);
                        this.SetActionCommandsAsync();
                    }

                    break;
                case EnumSteps.Error:
                    NotificationErrorView errorPopup = new NotificationErrorView();
                    NotificationErrorViewModel errorPopupViewModel = new NotificationErrorViewModel();
                    errorPopupViewModel.listCustomHyperlink = this.ListErrorHyperlink;
                    errorPopup.DataContext = errorPopupViewModel;
                    errorPopup.Style = (Style)Application.Current.FindResource("RadWindowStyleNew");
                    errorPopup.ShowDialog();
                    break;
            }
        }
        public override async Task OnStepAsync(object stepName)
        {
            bool canProcess = true;
            var step = (EnumSteps)Enum.Parse(typeof(EnumSteps), stepName.ToString());
            switch (step)
            {
                case EnumSteps.Start:
                    _CurrentEnumStep = EnumSteps.Start;
                    CollectionQueueSetting = await CollectionsQueueSettingsFunctions.ReadCollectionsSystemSettingsAsync() ??
                                             new CollectionSetting();

                    CollectionSystemDefault = await CollectionsQueueSettingsFunctions.ReadCollectionSystemDefaultAsync() ??
                                              new CollectionSystemDefault();

                    var allSystemParam = new ObservableCollection<SystemParam>(await CollectionsQueueSettingsFunctions.ReadAllSystemParamAsync());
                    Category = allSystemParam
                        .Select(cate => new DropdownList { Description = cate.ParamDesc, ID = cate.ParamId })
                        .OrderBy(item => item.Description)
                        .ToList();

                    SetActionCommandsAsync();
                    break;

                case EnumSteps.Edit:
                    this.GridStyle = (Brush)Application.Current.FindResource("GridStyleEdit");
                    this.RaiseActionsWhenChangeStep(EnumScreen.CollectionSettings, EnumSteps.Edit);
                    _CurrentEnumStep = EnumSteps.Edit;
                    IsCheckedOut = true;
                    SetActionCommandsAsync();
                    break;

                case EnumSteps.Save:
                    if (IsPercentaged)
                    {
                        CollectionQueueSetting.MinimumArrearsAmount = 0;
                    }
                    else
                    {
                        CollectionQueueSetting.MinimumArrearsPercent = 0;
                    }
                    Validate();

                    if (HasErrors == false)
                    {
                        this.ValidateNotError();
                        this.GridStyle = (Brush)Application.Current.FindResource("GridStyleNotEdit");
                        _CurrentEnumStep = EnumSteps.Save;
                        await CollectionsQueueSettingsFunctions.UpdateCollectionsSystemSettings(CollectionQueueSetting, CollectionSystemDefault);
                        this.RaiseActionsWhenChangeStep(EnumScreen.CollectionSettings, EnumSteps.Save);
                        IsCheckedOut = false;
                        this.IsChanged = false;
                        SetActionCommandsAsync();
                    }
                    else
                    {
                        _CurrentEnumStep = EnumSteps.Error;
                        this.SetActionCommandsAsync();
                        this.ListErrorHyperlink = this.ListErrorHyperlink;
                        this.OnErrorHyperlinkSelected();
                    }
                    break;

                case EnumSteps.Cancel:
                    canProcess = await this.CheckIfUnSavedChanges();
                    if (canProcess)
                    {
                        this.ValidateNotError();
                        this.GridStyle = (Brush)Application.Current.FindResource("GridStyleNotEdit");
                        _CurrentEnumStep = EnumSteps.Cancel;
                        CollectionQueueSetting =
                            await CollectionsQueueSettingsFunctions.ReadCollectionsSystemSettingsAsync();
                        CollectionQueueSetting.tempMinimumArrearsPercent =
                            CollectionQueueSetting.MinimumArrearsPercent.HasValue
                                ? CollectionQueueSetting.MinimumArrearsPercent.Value.ToString(
                                    CultureInfo.InvariantCulture)
                                : "0";
                        CollectionQueueSetting.tempMinimumArrearsAmount =
                            CollectionQueueSetting.MinimumArrearsAmount.HasValue
                                ? CollectionQueueSetting.MinimumArrearsAmount.Value.ToString(
                                    CultureInfo.InvariantCulture)
                                : "0";
                        CollectionQueueSetting.tempMinimumArrearsDays =
                            CollectionQueueSetting.MinimumArrearsDays.HasValue
                                ? CollectionQueueSetting.MinimumArrearsDays.Value.ToString(CultureInfo.InvariantCulture)
                                : "0";
                        CollectionSystemDefault =
                            await CollectionsQueueSettingsFunctions.ReadCollectionSystemDefaultAsync();
                        this.RaiseActionsWhenChangeStep(EnumScreen.CollectionSettings, EnumSteps.Cancel);
                        IsCheckedOut = false;
                        this.IsChanged = false;
                        SetActionCommandsAsync();
                    }
                    break;
                case EnumSteps.Error:
                    NotificationErrorView errorPopup = new NotificationErrorView();
                    NotificationErrorViewModel errorPopupViewModel = new NotificationErrorViewModel();
                    errorPopupViewModel.listCustomHyperlink = this.ListErrorHyperlink;
                    errorPopup.DataContext = errorPopupViewModel;

                    errorPopup.Style = (Style)Application.Current.FindResource("RadWindowStyleNew");

                    errorPopup.ShowDialog();
                    break;
            }
        }