コード例 #1
0
        /// <summary>
        /// Loads the drop downs.
        /// </summary>
        private void LoadDropDowns()
        {
            var projectQry = new ResidencyService <Project>().Queryable();

            int competencyPersonId            = hfCompetencyPersonId.ValueAsInt();
            CompetencyPerson competencyPerson = new ResidencyService <CompetencyPerson>().Get(competencyPersonId);

            projectQry = projectQry.Where(a => a.CompetencyId == competencyPerson.CompetencyId);

            // list
            List <int> assignedProjectIds = new ResidencyService <CompetencyPersonProject>().Queryable()
                                            .Where(a => a.CompetencyPersonId.Equals(competencyPersonId))
                                            .Select(a => a.ProjectId).ToList();

            var list = projectQry.Where(a => !assignedProjectIds.Contains(a.Id)).OrderBy(a => a.Name).ToList();

            ddlProject.DataSource = list;
            ddlProject.DataBind();

            bool addMode = hfCompetencyPersonProjectId.ValueAsInt() == 0;

            if (addMode)
            {
                // if Adding a project, warn if there are no Projects left to add
                pnlEditProject.Visible            = list.Any();
                nbAllProjectsAlreadyAdded.Visible = !list.Any();
                btnSave.Visible = list.Any();
            }
            else
            {
                pnlEditProject.Visible            = true;
                nbAllProjectsAlreadyAdded.Visible = false;
                btnSave.Visible = true;
            }
        }
コード例 #2
0
        /// <summary>
        /// Handles the SelectedIndexChanged event of the ddlTrack control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void ddlTrack_SelectedIndexChanged(object sender, EventArgs e)
        {
            int trackId       = ddlTrack.SelectedValueAsInt() ?? 0;
            var competencyQry = new ResidencyService <Competency>().Queryable().Where(a => a.TrackId == trackId);

            // list
            int        personId = hfPersonId.ValueAsInt();
            List <int> assignedCompetencyIds = new ResidencyService <CompetencyPerson>().Queryable().Where(a => a.PersonId.Equals(personId)).Select(a => a.CompetencyId).ToList();

            var competencyNotYetAssignedList = competencyQry.Where(a => !assignedCompetencyIds.Contains(a.Id)).OrderBy(a => a.Name).ToList();

            ddlCompetency.Visible = competencyNotYetAssignedList.Any();
            nbAllCompetenciesAlreadyAdded.Visible = !competencyNotYetAssignedList.Any();
            btnSave.Visible = competencyNotYetAssignedList.Any();

            competencyNotYetAssignedList.Insert(0, new Competency {
                Id = Rock.Constants.All.Id, Name = Rock.Constants.All.Text
            });

            ddlCompetency.DataSource = competencyNotYetAssignedList;
            ddlCompetency.DataBind();
        }
コード例 #3
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            ResidencyService <CompetencyPerson>        competencyPersonService        = new ResidencyService <CompetencyPerson>();
            ResidencyService <Competency>              competencyService              = new ResidencyService <Competency>();
            ResidencyService <CompetencyPersonProject> competencyPersonProjectService = new ResidencyService <CompetencyPersonProject>();

            int competencyPersonId = int.Parse(hfCompetencyPersonId.Value);
            int trackId            = ddlTrack.SelectedValueAsInt() ?? 0;
            int personId           = hfPersonId.ValueAsInt();

            if (competencyPersonId == 0)
            {
                int        selectedId = ddlCompetency.SelectedValueAsInt() ?? 0;
                List <int> competencyToAssignIdList = null;

                if (selectedId == Rock.Constants.All.Id)
                {
                    // add all the Competencies for this Track that they don't have yet
                    var competencyQry = new ResidencyService <Competency>().Queryable().Where(a => a.TrackId == trackId);

                    // list
                    List <int> assignedCompetencyIds = new ResidencyService <CompetencyPerson>().Queryable().Where(a => a.PersonId.Equals(personId)).Select(a => a.CompetencyId).ToList();

                    competencyToAssignIdList = competencyQry.Where(a => !assignedCompetencyIds.Contains(a.Id)).OrderBy(a => a.Name).Select(a => a.Id).ToList();
                }
                else
                {
                    // just add the selected Competency
                    competencyToAssignIdList = new List <int>();
                    competencyToAssignIdList.Add(selectedId);
                }

                RockTransactionScope.WrapTransaction(() =>
                {
                    foreach (var competencyId in competencyToAssignIdList)
                    {
                        CompetencyPerson competencyPerson = new CompetencyPerson();
                        competencyPersonService.Add(competencyPerson, CurrentPersonId);
                        competencyPerson.PersonId     = hfPersonId.ValueAsInt();
                        competencyPerson.CompetencyId = competencyId;
                        competencyPersonService.Save(competencyPerson, CurrentPersonId);

                        Competency competency = competencyService.Get(competencyId);
                        foreach (var project in competency.Projects)
                        {
                            // add all the projects associated with the competency
                            CompetencyPersonProject competencyPersonProject = new CompetencyPersonProject
                            {
                                CompetencyPersonId = competencyPerson.Id,
                                ProjectId          = project.Id,
                                MinAssessmentCount = null
                            };

                            competencyPersonProjectService.Add(competencyPersonProject, CurrentPersonId);
                            competencyPersonProjectService.Save(competencyPersonProject, CurrentPersonId);
                        }
                    }
                });
            }
            else
            {
                // shouldn't happen, they can only Add
            }

            var qryParams = new Dictionary <string, string>();

            qryParams["personId"] = personId.ToString();
            NavigateToParentPage(qryParams);
        }