Beispiel #1
0
        private void SetSelectedSupervisors()
        {
            if (UserData.IsUserStateScope)
            {
                if (formView.FindControl("ddlReviewers") != null)
                {
                    DropDownList ReviewerDDL = (DropDownList)formView.FindControl("ddlReviewers");

                    if (!IsPostBack)
                    {
                        //Get the current supervisor and set as selected from list of Reviewers.
                        //Per business rule, currently only one Supervisor is allowed. Thats why we use dropdownlist.
                        //Lets pick the first and assign to user.
                        var Reviewer = UserBLL.GetReviewersForUser(UserData.UserId, null);
                        if (Reviewer != null && Reviewer.Count() > 0)
                        {
                            ReviewerDDL.SelectedValue = Reviewer.ElementAt(0).Key.ToString();
                            UserIdOfOldReviewer       = Reviewer.ElementAt(0).Key;
                        }
                        else
                        {
                            UserIdOfOldReviewer = 0;
                        }
                    }
                    else
                    {
                        ReviewerDDL.SelectedValue = NewSupervisorId.ToString();
                    }
                }
            }
        }
        private void SetSelectedReviewers()
        {
            if (formView.FindControl("ddlReviewers") != null)
            {
                //At present, only one supervisor is assigned to a User.
                //Is possible to have multiple in future - the original idea. Code is good for all scenarios.
                DropDownList ReviewersDDL      = (DropDownList)formView.FindControl("ddlReviewers");
                var          SelectedReviewers = UserBLL.GetReviewersForUser(UserProfileUserId, AgencyId);

                if (ReviewersDDL.Items.Count == 0)
                {
                    ReviewersDDL.Items.Add(new ListItem("No supervisors found for your Agency.", "0"));
                }
                else
                {
                    ReviewersDDL.Items.Insert(0, new ListItem("--Supervisor not selected--", "0"));
                }

                //When post back occurs, we need to set the Reviewer that was chosen, but not saved as the selected Reviewer in DDL
                //This is important when the updated data is not saved in database due to error.
                if (IsPostBack)
                {
                    ListItem newSupervisorItem = ReviewersDDL.Items.FindByValue(NewSupervisorId.ToString());
                    if (newSupervisorItem != null)
                    {
                        newSupervisorItem.Selected = true;
                        UserIdOfOldReviewer        = NewSupervisorId;
                    }
                }
                else
                {
                    bool ReviewerSelected = false;
                    foreach (ListItem item in ReviewersDDL.Items)
                    {
                        foreach (var pair in SelectedReviewers)
                        {
                            //Set Selected here
                            if (pair.Key == int.Parse(item.Value))
                            {
                                item.Selected       = true;
                                UserIdOfOldReviewer = pair.Key;
                                ReviewerSelected    = true;
                                break;
                            }
                        }

                        //Need to ensure that the above foreach break doesn't get into another loop.
                        if (ReviewerSelected)
                        {
                            break;
                        }
                    }
                }
            }
        }