/// <summary>
        /// All steps that represents an asynchronous operation.
        /// </summary>
        /// <param name="stepName">The step's name that should be invoke</param>
        /// <returns>A instance of the <see cref="Task" /> class</returns>
        public override async Task OnStepAsync(object stepName)
        {
            int queueTempID;

            if (this.OnCheckOutChanged != null)
            {
                this.OnCheckOutChanged(false);
            }
            
            this._CurrentEnumStep = (EnumSteps)Enum.Parse(typeof(EnumSteps), stepName.ToString());
            switch (this._CurrentEnumStep)
            {
                case EnumSteps.Start:
                    this.BusyContent = LoadingText;
                    this.IsBusy = true;
                    await Task.WhenAll(
                        this.PopulateAllCollectionsQueuesAsync(),
                        this.GetClientFinancialAsync());
                    await Instance();
                    this.BusyContent = string.Empty;
                    this.IsBusy = false;
                    break;
                case EnumSteps.SelectQueue:
                    this.BusyContent = LoadingText;
                    this.IsBusy = true;
                    this.GridStyle = (Brush)Application.Current.FindResource("GridStyleNotEdit");
                    if (this.SelectedQueue.IsNewQueue == false)
                    {
                        this.SelectedQueue.CollectionQueue = await QueueManagmentFunctions.GetCollectionQueueAsync(this.SelectedQueue.QueueDetailId);
                    }

                    // check if the Client Financial's value of the currently Queue is not assign to default value.
                    if (this.SelectedQueue.CollectionQueue.ClientFinancialsTypeID <= 0)
                    {
                        // assign the default value for ClientFinancialsTypeID.
                        this.SelectedQueue.CollectionQueue.ClientFinancialsTypeID = -1;
                    }

                    LoadAllDetailOnView(SelectedQueue.QueueDetailId);

                    this.SelectedQueue.ClientFinancials = this.ClientFinancials;

                    if (this.OnCollectorsChanged != null)
                    {
                        this.OnCollectorsChanged(CollectionsQueueCollectorsFunctions.QueueList());
                    }

                    this.ActiveViewModel = this;
                    this.SetActionCommandsAsync();

                    if (this.IsCheckedOut)
                    {
                        await this.OnStepAsync(EnumSteps.Edit.ToString());
                    }
                    this.BusyContent = string.Empty;
                    this.IsBusy = false;
                    if (this.SelectedQueue.IsNewQueue == false)
                    {
                        this.RaiseActionsWhenChangeStep(EnumScreen.ColletionQueues, EnumSteps.SelectQueue, this.SelectedQueue.QueueDetailId);
                    }
                    break;
                case EnumSteps.Details:
                    this._IsDetailStepped = true;
                    if (this.OnStoryBoardChanged != null)
                    {
                        this.OnStoryBoardChanged(this._CurrentEnumStep.ToString());
                    }
                    this.OnCheckOutChanged(this.Edit.IsCheckedOut);
                    break;
                case EnumSteps.Collectors:
                    this._IsDetailStepped = false;
                    if (this.OnStoryBoardChanged != null)
                    {
                        this.OnStoryBoardChanged(this._CurrentEnumStep.ToString());
                    }
                    this.OnCheckOutChanged(this.Edit.IsCheckedOut);
                    break;
                case EnumSteps.Add:
                    var newQueue = await QueueManagmentFunctions.AddNewQueueAsync(0);
                    newQueue.ClientFinancials = this.ClientFinancials;

                    await SetSelectedQueueAsync(newQueue);
                    this.RaiseActionsWhenChangeStep(EnumScreen.ColletionQueues, EnumSteps.Add);
                    await this.OnStepAsync(EnumSteps.Edit);
                    if (this.OnStoryBoardChanged != null)
                    {
                        this.OnStoryBoardChanged(EnumSteps.Details.ToString());
                    }
                    if (this.OnCheckOutChanged != null)
                    {
                        this.OnCheckOutChanged(true);
                    }
                    break;
                case EnumSteps.Process:
                    this.BusyContent = LoadingText;
                    this.IsBusy = true;
                    Task task = new Task(ProcessData);
                    task.ContinueWith(async t =>
                    {
                        await this.PopulateAllCollectionsQueuesAsync();
                        this.BusyContent = string.Empty;
                        this.IsBusy = false;
                    });
                    task.Start();
                    break;
                case EnumSteps.Edit:
                    //if (await this.LockAsync() == false)
                    //{
                    //    return;
                    //}
                    this.GridStyle = (Brush)Application.Current.FindResource("GridStyleEdit");
                    this.RaiseActionsWhenChangeStep(EnumScreen.ColletionQueues, EnumSteps.Edit);
                    if (this.isCopy == false)
                    {
                        this.Edit.SelectedQueue = this.SelectedQueue;
                    }

                    if (this.OnCheckOutChanged != null)
                    {
                        this.OnCheckOutChanged(true);
                    }
                    this.Edit.InstanceGUID = this.InstanceGUID;
                    await this.Edit.OnStepAsync(EditQueueViewModel.EnumSteps.Start);
                    break;
                case EnumSteps.CurrentQueue:
                    this.ActiveViewModel = this;
                    await Instance();
                    if (this.OnCollectorsChanged != null)
                    {
                        this.OnCollectorsChanged(CollectionsQueueCollectorsFunctions.QueueList());
                    }
                    this.SetActionCommandsAsync();
                    break;
                case EnumSteps.RefreshQueue:

                    queueTempID = this.SelectedQueue.CollectionQueue.ID;
                    if (null == this.SelectedQueue.ClientFinancials || !this.SelectedQueue.ClientFinancials.Any())
                    {
                        this.SelectedQueue.ClientFinancials = this.ClientFinancials;
                    }

                    await Task.WhenAll(this.PopulateAllCollectionsQueuesAsync());
                    this.SelectedQueue = this.AllQueueManagementDetails.Where(item => item.CollectionQueue.ID == queueTempID).FirstOrDefault();
                    await Instance();
                    break;
                case EnumSteps.Copy:
                    this.isCopy = true;
                    QueueDetailsModel copyQueue = await QueueManagmentFunctions.CopyQueueAsync(this.SelectedQueue);
                    copyQueue.IsNewQueue = true;
                    
                    this.Edit.SelectedQueue = copyQueue;
                    await SetSelectedQueueAsync(copyQueue);
                    this.RaiseActionsWhenChangeStep(EnumScreen.ColletionQueues, EnumSteps.Copy);
                    await this.OnStepAsync(EnumSteps.Edit);
                    if (this.OnStoryBoardChanged != null)
                    {
                        this.OnStoryBoardChanged(EnumSteps.Details.ToString());
                    }
                    break;
            }
            
            this.SetActionCommandsAsync();
            this.OnStepChanged(_CurrentEnumStep.ToString());
        }
 /// <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 = (EnumSteps)Enum.Parse(typeof(EnumSteps), stepName.ToString());
     switch (this._currentEnumStep)
     {
         case EnumSteps.Start:
             this.SetBusyAction("Please Wait Loading ...");
             AvailableUsersList = new ObservableCollection<Membership>();
             await Task.WhenAll(this.PopulateAllUsersAsync(), this.PopulateAllGroupsAsync());
             await Instance();
             if (this.OnUsersInGroupChanged != null)
             {
                 this.OnUsersInGroupChanged(this.Groups.ToList(), this.AllUsers.ToList());
             }
             this.ResetBusyAction();
             break;
         case EnumSteps.Edit:
             //if (await this.LockAsync() == false)
             //{
             //    return;
             //}
             
             if (this.OnCheckOutChanged != null)
             {
                 this.OnCheckOutChanged(true);
             }
             this.Edit.InstanceGUID = this.InstanceGUID;
             await this.Edit.OnStepAsync(EditMembershipViewModel.EnumSteps.Start);
             break;
         case EnumSteps.Reset:
             this.ActiveViewModel = this;
             await Instance();
             if (this.OnUsersInGroupChanged != null)
             {
                 this.OnUsersInGroupChanged(this.Groups.ToList(), this.AllUsers.ToList());
             }
             break;
         case EnumSteps.Refresh:
             this.ActiveViewModel = this;
             await Task.WhenAll(this.PopulateAllUsersAsync(), this.PopulateAllGroupsAsync());
             if (this.OnUsersInGroupChanged != null)
             {
                 this.OnUsersInGroupChanged(this.Groups.ToList(), this.AllUsers.ToList());
             }
             if (this.OnCheckOutChanged != null)
             {
                 this.OnCheckOutChanged(this.Edit.IsCheckedOut);
             }
             break;
     }
     SetActionCommandsAsync();
     this.OnStepChanged(_currentEnumStep.ToString());
 }
        public override async Task OnStepAsync(object stepName)
        {
            GroupDetails group;
            this._CurrentEnumStep = (EnumSteps)Enum.Parse(typeof(EnumSteps), stepName.ToString());
            switch (this._CurrentEnumStep)
            {
                case EnumSteps.Start:
                    await Task.WhenAll(this.PopulateAllUsersAsync(), this.PopulateAllGroupsAsync());
                    this.Managers = null;
                    break;
                case EnumSteps.SelectGroup:
                    if (this.SelectedGroup.IsNewGroup == false)
                    {
                        this.SelectedGroup.LXMGroup = await GroupFunctions.GetGroupAsync(this.SelectedGroup.UserEntityId);
                    }

                    if (this.AllUsers != null && this.Managers == null)
                    {
                        this.Managers = this.AllUsers.Select(user => new DropdownList { Description = string.Format("{0}{1}{2}", user.Lastname, string.IsNullOrEmpty(user.Lastname) == false ? ", " : "", user.Firstname), ID = user.UserEntityId }).ToList();
                    }

                    if (this.isCopy == false)
                    {
                        await this.PopulateUsersAndPermissionsForGroupAsync();
                    }
                    this.ActiveViewModel = this;
                    this.SetActionCommandsAsync();

                    if (this.IsCheckedOut)
                    {
                        await this.OnStepAsync(EnumSteps.Edit.ToString());
                    }
                    this.SelectedGroup.SystemOptionPermissionChanged -= SelectedGroup_SystemOptionPermissionChanged;
                    this.SelectedGroup.SystemOptionPermissionChanged += SelectedGroup_SystemOptionPermissionChanged;
                    break;
                case EnumSteps.CurrentGroup:
                    this.ActiveViewModel = this;
                    this.SetActionCommandsAsync();
                    break;
                case EnumSteps.DetailsState:
                case EnumSteps.UsersState:
                case EnumSteps.PermissionsState:
                    if (this.OnStoryBoardChanged != null)
                    {
                        this.OnStoryBoardChanged(this._CurrentEnumStep.ToString());
                    }
                    break;
                case EnumSteps.Edit:
                    this.Edit.SelectedGroup = this.SelectedGroup;
                    this.Edit.NotMembers = new ObservableCollection<LXMUserDetail>(this.AllUsers.Except(this.SelectedGroup.Users));
                    await this.Edit.OnStepAsync(EditUserViewModel.EnumSteps.Start);
                    break;
                case EnumSteps.Add:
                    GroupDetails newGroup = await GroupFunctions.AddNewGroupAsync();
                    await SetSelectedGroupAsync(newGroup);                    
                    
                    await this.OnStepAsync(EnumSteps.Edit);
                    this.OnStoryBoardChanged(EnumSteps.DetailsState.ToString());
                    break;
                case EnumSteps.Copy:
                    this.isCopy = true;
                    GroupDetails copyGroup = await GroupFunctions.CopyGroupAsync(this.SelectedGroup);
                    copyGroup.IsNewGroup = true;
                    await SetSelectedGroupAsync(copyGroup);                   
                    await this.OnStepAsync(EnumSteps.Edit);
                    this.OnStoryBoardChanged(EnumSteps.DetailsState.ToString());
                    break;
                case EnumSteps.RefreshGroup:
                    group = this.Groups.Where(item => item.UserEntityId == this.SelectedGroup.UserEntityId).FirstOrDefault();

                    if (group == null)
                    {
                        group = this.SelectedGroup;
                        this.Groups.Add(group);
                    }

                    group.ManagerName = this.Managers.Where(manager => manager.ID == this.SelectedGroup.LXMGroup.ManagerUserEntityId).FirstOrDefault().Description;
                    break;
            }
            this.SetActionCommandsAsync();
            this.OnStepChanged(_CurrentEnumStep.ToString());
        }
        /// <summary>
        /// All steps that represents an asynchronous operation.
        /// </summary>
        /// <param name="stepName">The step's name that should be invoke</param>
        /// <returns>A instance of the <see cref="Task" /> class</returns>
        public override async Task OnStepAsync(object stepName)
        {
            int queueTempID;

            if (this.OnCheckOutChanged != null)
            {
                this.OnCheckOutChanged(false);
            }
            
            this._CurrentEnumStep = (EnumSteps)Enum.Parse(typeof(EnumSteps), stepName.ToString());
            switch (this._CurrentEnumStep)
            {
                case EnumSteps.Start:
                    this.BusyContent = "Please Wait Loading ...";
                    this.IsBusy = true;
                    AvailableCollectorList = new ObservableCollection<Collectors>();
                    await Task.WhenAll(
                        this.PopulateAllCollectionsQueuesAsync(),
                        this.GetClientFinancialAsync());
                    await Instance();
                    if (this.OnCollectorsChanged != null)
                    {
                        this.OnCollectorsChanged(CollectionsQueueCollectorsFunctions.QueueList());
                    }
                    this.BusyContent = string.Empty;
                    this.IsBusy = false;
                    break;
                case EnumSteps.ResetCollectors:
                    if (this.OnCollectorsChanged != null)
                    {
                        this.OnCollectorsChanged(CollectionsQueueCollectorsFunctions.QueueList());
                    }

                    this.ActiveViewModel = this;
                    this.SetActionCommandsAsync();

                    if (this.IsCheckedOut)
                    {
                        await this.OnStepAsync(EnumSteps.Edit.ToString());
                    }
                    break;             
                case EnumSteps.Edit:
                    //if (await this.LockAsync() == false)
                    //{
                    //    return;
                    //}
                    this.RaiseActionsWhenChangeStep(EnumScreen.Collectors, EnumSteps.Edit);
                    if (this.OnCheckOutChanged != null)
                    {
                        this.OnCheckOutChanged(true);
                    }
                    this.Edit.InstanceGUID = this.InstanceGUID;
                    await this.Edit.OnStepAsync(EditQueueViewModel.EnumSteps.Start);
                    break;
                case EnumSteps.RefreshQueue:
                    this.ActiveViewModel = this;
                    await Task.WhenAll(this.PopulateAllCollectionsQueuesAsync());
                    if (this.OnCollectorsChanged != null)
                    {
                        this.OnCollectorsChanged(CollectionsQueueCollectorsFunctions.QueueList());
                    }
                    // await Instance();
                    break;
            }
            
            this.SetActionCommandsAsync();
            this.OnStepChanged(_CurrentEnumStep.ToString());
        }
        public override async Task OnStepAsync(object stepName)
        {
            UserDetails user;

            EnumSteps previousStep = (EnumSteps)Enum.Parse(typeof(EnumSteps), stepName.ToString());

            this._CurrentEnumStep = (EnumSteps)Enum.Parse(typeof(EnumSteps), stepName.ToString());
            switch (this._CurrentEnumStep)
            {
                case EnumSteps.Start:
                    await Task.WhenAll(this.PopulateStatesAsync(), this.PopulateAllGroupsAsync());
                    await this.PopulateAllUsersForViewAsync();
                    //this._OnLoadUserContent();
                    break;
                case EnumSteps.SelectUser:
                    GetSelectUser(EnumSteps.SelectUser);
                    if (this.SelectedUser.IsNewUser == false)
                    {
                        this.SelectedUser.LXMUserDetails = await UserFunctions.GetUserDetailsAsync(this.SelectedUser.UserEntityId);
                        await this.PopulateGroupsForUserAsync();
                    }

                    await this.PopulateCredentialsForUserAsync();

                    if (this.isCopy == false)
                    {
                        await this.PopulatePermissionsForUserAsync();
                    }

                    this.ActiveViewModel = this;
                    this.SetActionCommandsAsync();
                    if (this.IsCheckedOut)
                    {
                        await this.OnStepAsync(EnumSteps.Edit.ToString());
                    }
                    this.SelectedUser.SystemOptionPermissionChanged -= SelectedUser_SystemOptionPermissionChanged;
                    this.SelectedUser.SystemOptionPermissionChanged += SelectedUser_SystemOptionPermissionChanged;
                    break;
                case EnumSteps.PersonalDetailsState:
                case EnumSteps.CredentialsState:
                case EnumSteps.GroupsState:
                case EnumSteps.PermissionsState:
                case EnumSteps.SummaryState:
                    if (this.OnStoryBoardChanged != null)
                    {
                        this.OnStoryBoardChanged(this._CurrentEnumStep.ToString());
                    }
                    break;
                case EnumSteps.Edit:
                    this.Edit.SelectedUser = this.SelectedUser;
                    this.Edit.NotAMemberOfGroups = new ObservableCollection<LXMGroup>(this.AllGroups.Except(this.SelectedUser.LXMUserGroups));
                    await this.Edit.OnStepAsync(EditUserViewModel.EnumSteps.Start);
                    break;
                case EnumSteps.Add:
                    UserDetails newUser = await UserFunctions.AddNewUserAsync();
                    await SetSelectedUserAsync(newUser);
                    await this.OnStepAsync(EnumSteps.Edit);
                    if (this.OnStoryBoardChanged != null)
                    {
                        this.OnStoryBoardChanged(EnumSteps.PersonalDetailsState.ToString());
                    }
                    break;
                case EnumSteps.Copy:
                    this.isCopy = true;
                    UserDetails copyUser = await UserFunctions.CopyUserAsync(this.SelectedUser);
                    copyUser.IsNewUser = true;
                    await SetSelectedUserAsync(copyUser);
                    await this.OnStepAsync(EnumSteps.Edit);
                    if (this.OnStoryBoardChanged != null)
                    {
                        this.OnStoryBoardChanged(EnumSteps.PersonalDetailsState.ToString());
                    }
                    break;
                case EnumSteps.RefreshUser:
                    user = this.AllUsers.Where(item => item.UserEntityId == this.SelectedUser.UserEntityId).FirstOrDefault();

                    if (user == null)
                    {
                        user = this.SelectedUser;
                        this.AllUsers.Add(user);
                    }
                    break;
            }
            this.SetActionCommandsAsync();
            this.OnStepChanged(_CurrentEnumStep.ToString());
        }