Exemple #1
0
        /// <summary>
        /// Handles the Click event of the btnEdit 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 btnEdit_Click(object sender, EventArgs e)
        {
            ResidencyService <CompetencyPersonProject> service = new ResidencyService <CompetencyPersonProject>();
            CompetencyPersonProject item = service.Get(hfCompetencyPersonProjectId.ValueAsInt());

            ShowEditDetails(item);
        }
Exemple #2
0
        /// <summary>
        /// Handles the Click event of the btnCancel 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 btnCancel_Click(object sender, EventArgs e)
        {
            SetEditMode(false);

            if (hfCompetencyPersonProjectId.ValueAsInt().Equals(0))
            {
                // Cancelling on Add.  Return to Grid
                // if this page was called from the CompetencyPerson Detail page, return to that
                string competencyPersonId = PageParameter("competencyPersonId");
                if (!string.IsNullOrWhiteSpace(competencyPersonId))
                {
                    Dictionary <string, string> qryString = new Dictionary <string, string>();
                    qryString["competencyPersonId"] = competencyPersonId;
                    NavigateToParentPage(qryString);
                }
                else
                {
                    NavigateToParentPage();
                }
            }
            else
            {
                // Cancelling on Edit.  Return to Details
                ResidencyService <CompetencyPersonProject> service = new ResidencyService <CompetencyPersonProject>();
                CompetencyPersonProject item = service.Get(hfCompetencyPersonProjectId.ValueAsInt());
                ShowReadonlyDetails(item);
            }
        }
Exemple #3
0
        /// <summary>
        /// Shows the readonly details.
        /// </summary>
        /// <param name="competencyPersonProject">The competency person project.</param>
        private void ShowReadonlyDetails(CompetencyPersonProject competencyPersonProject)
        {
            string residentCompetencyPageGuid = this.GetAttributeValue("ResidentCompetencyPage");

            lblMainDetails.Text = new DescriptionList()
                                  .Add("Resident", competencyPersonProject.CompetencyPerson.Person)
                                  .Add("Competency", competencyPersonProject.CompetencyPerson.Competency.Name)
                                  .Add("Project", string.Format("{0} - {1}", competencyPersonProject.Project.Name, competencyPersonProject.Project.Description))
                                  .Html;
        }
Exemple #4
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="itemKey">The item key.</param>
        /// <param name="itemKeyValue">The item key value.</param>
        /// <param name="competencyPersonId">The competency person id.</param>
        public void ShowDetail(string itemKey, int itemKeyValue, int?competencyPersonId)
        {
            // return if unexpected itemKey
            if (itemKey != "competencyPersonProjectId")
            {
                return;
            }

            pnlDetails.Visible = true;

            // Load depending on Add(0) or Edit
            CompetencyPersonProject competencyPersonProject = null;

            if (!itemKeyValue.Equals(0))
            {
                competencyPersonProject = new ResidencyService <CompetencyPersonProject>().Get(itemKeyValue);
            }
            else
            {
                competencyPersonProject = new CompetencyPersonProject {
                    Id = 0
                };
                competencyPersonProject.CompetencyPersonId = competencyPersonId ?? 0;
                competencyPersonProject.CompetencyPerson   = new ResidencyService <CompetencyPerson>().Get(competencyPersonProject.CompetencyPersonId);
            }

            hfCompetencyPersonProjectId.Value = competencyPersonProject.Id.ToString();
            hfCompetencyPersonId.Value        = competencyPersonProject.CompetencyPersonId.ToString();

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if (!IsUserAuthorized("Edit"))
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(CompetencyPersonProject.FriendlyTypeName);
            }

            if (readOnly)
            {
                ShowReadonlyDetails(competencyPersonProject);
            }
            else
            {
                if (competencyPersonProject.Id > 0)
                {
                    ShowReadonlyDetails(competencyPersonProject);
                }
                else
                {
                    ShowEditDetails(competencyPersonProject);
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Shows the readonly details.
        /// </summary>
        /// <param name="competencyPersonProject">The competency person project.</param>
        private void ShowReadonlyDetails(CompetencyPersonProject competencyPersonProject)
        {
            SetEditMode(false);

            lblMainDetails.Text = new DescriptionList()
                                  .Add("Resident", competencyPersonProject.CompetencyPerson.Person)
                                  .Add("Competency", competencyPersonProject.CompetencyPerson.Competency.Name)
                                  .Add("Project", string.Format("{0} - {1}", competencyPersonProject.Project.Name, competencyPersonProject.Project.Description))
                                  .Add("Assessments Required", competencyPersonProject.MinAssessmentCount ?? competencyPersonProject.Project.MinAssessmentCountDefault)
                                  .Html;
        }
Exemple #6
0
        /// <summary>
        /// Determines whether this instance can delete the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="errorMessage">The error message.</param>
        /// <returns>
        ///   <c>true</c> if this instance can delete the specified item; otherwise, <c>false</c>.
        /// </returns>
        public bool CanDelete(CompetencyPersonProject item, out string errorMessage)
        {
            errorMessage = string.Empty;

            if (new ResidencyService <CompetencyPersonProjectAssessment>().Queryable().Any(a => a.CompetencyPersonProjectId == item.Id))
            {
                errorMessage = string.Format("This {0} is assigned to a {1}.", CompetencyPersonProject.FriendlyTypeName, CompetencyPersonProjectAssessment.FriendlyTypeName);
                return(false);
            }

            return(true);
        }
Exemple #7
0
        /// <summary>
        /// Shows the edit details.
        /// </summary>
        /// <param name="competencyPersonProject">The competency person project.</param>
        private void ShowEditDetails(CompetencyPersonProject competencyPersonProject)
        {
            if (competencyPersonProject.Id > 0)
            {
                lActionTitle.Text = ActionTitle.Edit(CompetencyPersonProject.FriendlyTypeName);
            }
            else
            {
                lActionTitle.Text = ActionTitle.Add(CompetencyPersonProject.FriendlyTypeName);
            }

            LoadDropDowns();

            SetEditMode(true);

            lblPersonName.Text = competencyPersonProject.CompetencyPerson.Person.FullName;
            lblCompetency.Text = competencyPersonProject.CompetencyPerson.Competency.Name;

            if (competencyPersonProject.MinAssessmentCount != null)
            {
                tbMinAssessmentCountOverride.Text = competencyPersonProject.MinAssessmentCount.ToString();
            }
            else
            {
                tbMinAssessmentCountOverride.Text = string.Empty;
            }

            /* Only allow changing the Project when in Add mode (If this record has already be saved, the child tables (especially assessments) are assuming this project doesn't change) */

            if (competencyPersonProject.Project != null)
            {
                lblProject.Text = string.Format("{0} - {1}", competencyPersonProject.Project.Name, competencyPersonProject.Project.Description);
                lblMinAssessmentCountDefault.Text = competencyPersonProject.Project.MinAssessmentCountDefault.ToString();
            }
            else
            {
                // they haven't picked a Project yet, so set the lblMinAssessmentCountDefault.text based on whatever project the ddl defaults to
                ddlProject_SelectedIndexChanged(null, null);

                // shouldn't happen in Edit, but just in case
                lblProject.Text = Rock.Constants.None.Text;
            }

            bool addMode = competencyPersonProject.Id == 0;

            ddlProject.Visible = addMode;
            lblProject.Visible = !addMode;

            lblPersonName.Visible = true;
            lblCompetency.Visible = true;
        }
Exemple #8
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var competencyPersonProjectService = new ResidencyService <CompetencyPersonProject>();
            int competencyPersonProjectId      = hfCompetencyPersonProjectId.ValueAsInt();
            CompetencyPersonProject competencyPersonProject = competencyPersonProjectService.Get(competencyPersonProjectId);

            if (competencyPersonProject.CompetencyPerson.PersonId != CurrentPersonId)
            {
                // somebody besides the Resident is logged in
                Dictionary <string, string> qryString = new Dictionary <string, string>();
                qryString["competencyPersonId"] = competencyPersonProject.CompetencyPersonId.ToString();
                NavigateToParentPage(qryString);
                return;
            }

            var rawList = competencyPersonProject.Project.ProjectPointOfAssessments
                          .OrderBy(s => s.AssessmentOrder).ToList();

            foreach (var item in rawList)
            {
                if (item.PointOfAssessmentTypeValue != null)
                {
                    item.PointOfAssessmentTypeValue.LoadAttributes();
                }
            }

            var selectList = rawList.Select(a =>
                                            new
            {
                a.Id,
                ProjectPointOfAssessmentColor = a.PointOfAssessmentTypeValue != null ? a.PointOfAssessmentTypeValue.GetAttributeValue("Color") : string.Empty,
                a.PointOfAssessmentTypeValue,
                a.AssessmentOrder,
                a.AssessmentText
            }).ToList();

            if (competencyPersonProject != null)
            {
                gList.DataSource = selectList;
                gList.DataBind();
            }
            else
            {
                NavigateToParentPage();
                return;
            }
        }
Exemple #9
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)
        {
            CompetencyPersonProject competencyPersonProject;
            ResidencyService <CompetencyPersonProject> competencyPersonProjectService = new ResidencyService <CompetencyPersonProject>();

            int competencyPersonProjectId = int.Parse(hfCompetencyPersonProjectId.Value);

            if (competencyPersonProjectId == 0)
            {
                competencyPersonProject = new CompetencyPersonProject();
                competencyPersonProjectService.Add(competencyPersonProject, CurrentPersonId);

                // these inputs are only editable on Add
                competencyPersonProject.ProjectId          = ddlProject.SelectedValueAsInt() ?? 0;
                competencyPersonProject.CompetencyPersonId = hfCompetencyPersonId.ValueAsInt();
            }
            else
            {
                competencyPersonProject = competencyPersonProjectService.Get(competencyPersonProjectId);
            }

            if (!string.IsNullOrWhiteSpace(tbMinAssessmentCountOverride.Text))
            {
                competencyPersonProject.MinAssessmentCount = tbMinAssessmentCountOverride.Text.AsInteger();
            }
            else
            {
                competencyPersonProject.MinAssessmentCount = null;
            }

            if (!competencyPersonProject.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            RockTransactionScope.WrapTransaction(() =>
            {
                competencyPersonProjectService.Save(competencyPersonProject, CurrentPersonId);
            });

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

            qryParams["competencyPersonProjectId"] = competencyPersonProject.Id.ToString();
            NavigateToPage(this.CurrentPage.Guid, qryParams);
        }
Exemple #10
0
        /// <summary>
        /// Handles the Delete event of the gList control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        protected void gList_Delete(object sender, RowEventArgs e)
        {
            RockTransactionScope.WrapTransaction(() =>
            {
                var competencyPersonProjectService = new ResidencyService <CompetencyPersonProject>();
                CompetencyPersonProject competencyPersonProject = competencyPersonProjectService.Get((int)e.RowKeyValue);

                if (competencyPersonProject != null)
                {
                    string errorMessage;
                    if (!competencyPersonProjectService.CanDelete(competencyPersonProject, out errorMessage))
                    {
                        mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                        return;
                    }

                    competencyPersonProjectService.Delete(competencyPersonProject, CurrentPersonId);
                    competencyPersonProjectService.Save(competencyPersonProject, CurrentPersonId);
                }
            });

            BindGrid();
        }
Exemple #11
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)
        {
            CompetencyPersonProject competencyPersonProject;
            ResidencyService <CompetencyPersonProject> competencyPersonProjectService = new ResidencyService <CompetencyPersonProject>();

            CompetencyPersonProjectAssessment competencyPersonProjectAssessment;
            ResidencyService <CompetencyPersonProjectAssessment> competencyPersonProjectAssessmentService = new ResidencyService <CompetencyPersonProjectAssessment>();

            ResidencyService <CompetencyPersonProjectAssessmentPointOfAssessment> competencyPersonProjectAssessmentPointOfAssessmentService = new ResidencyService <CompetencyPersonProjectAssessmentPointOfAssessment>();

            int competencyPersonProjectId = hfCompetencyPersonProjectId.ValueAsInt();

            if (competencyPersonProjectId == 0)
            {
                competencyPersonProject = new CompetencyPersonProject();
                competencyPersonProjectService.Add(competencyPersonProject, CurrentPersonId);
            }
            else
            {
                competencyPersonProject = competencyPersonProjectService.Get(competencyPersonProjectId);
            }

            int competencyPersonProjectAssessmentId = hfCompetencyPersonProjectAssessmentId.ValueAsInt();

            if (competencyPersonProjectAssessmentId == 0)
            {
                competencyPersonProjectAssessment = new CompetencyPersonProjectAssessment();
                competencyPersonProjectAssessmentService.Add(competencyPersonProjectAssessment, CurrentPersonId);
            }
            else
            {
                competencyPersonProjectAssessment = competencyPersonProjectAssessmentService.Get(competencyPersonProjectAssessmentId);
                competencyPersonProjectAssessment.CompetencyPersonProjectAssessmentPointOfAssessments = new List <CompetencyPersonProjectAssessmentPointOfAssessment>();
            }

            // set competencyPersonProjectAssessment.CompetencyPersonProjectId after saving competencyPersonProject in case it is new
            competencyPersonProjectAssessment.AssessmentDateTime = DateTime.Now;
            competencyPersonProjectAssessment.RatingNotes        = tbRatingNotesOverall.Text;
            competencyPersonProjectAssessment.AssessorPersonId   = hfAssessorPersonId.ValueAsInt();

            if (!competencyPersonProjectAssessment.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            List <CompetencyPersonProjectAssessmentPointOfAssessment> competencyPersonProjectAssessmentPointOfAssessmentList = new List <CompetencyPersonProjectAssessmentPointOfAssessment>();

            foreach (RepeaterItem item in rptPointOfAssessment.Items.OfType <RepeaterItem>())
            {
                HiddenField hfProjectPointOfAssessmentId = item.FindControl("hfProjectPointOfAssessmentId") as HiddenField;
                int         projectPointOfAssessmentId   = hfProjectPointOfAssessmentId.ValueAsInt();

                CompetencyPersonProjectAssessmentPointOfAssessment competencyPersonProjectAssessmentPointOfAssessment = competencyPersonProjectAssessmentPointOfAssessmentService.Queryable()
                                                                                                                        .Where(a => a.ProjectPointOfAssessmentId == projectPointOfAssessmentId)
                                                                                                                        .Where(a => a.CompetencyPersonProjectAssessmentId == competencyPersonProjectAssessmentId).FirstOrDefault();

                if (competencyPersonProjectAssessmentPointOfAssessment == null)
                {
                    competencyPersonProjectAssessmentPointOfAssessment = new CompetencyPersonProjectAssessmentPointOfAssessment();
                    //// set competencyPersonProjectAssessmentPointOfAssessment.CompetencyPersonProjectAssessmentId = competencyPersonProjectAssessment.Id in save in case it's new
                    competencyPersonProjectAssessmentPointOfAssessment.ProjectPointOfAssessmentId = projectPointOfAssessmentId;
                }

                LabeledDropDownList ddlPointOfAssessmentRating = item.FindControl("ddlPointOfAssessmentRating") as LabeledDropDownList;
                TextBox             tbRatingNotesPOA           = item.FindControl("tbRatingNotesPOA") as TextBox;

                competencyPersonProjectAssessmentPointOfAssessment.Rating      = ddlPointOfAssessmentRating.SelectedValueAsInt();
                competencyPersonProjectAssessmentPointOfAssessment.RatingNotes = tbRatingNotesPOA.Text;

                competencyPersonProjectAssessmentPointOfAssessmentList.Add(competencyPersonProjectAssessmentPointOfAssessment);
            }

            RockTransactionScope.WrapTransaction(() =>
            {
                competencyPersonProjectService.Save(competencyPersonProject, CurrentPersonId);
                competencyPersonProjectAssessment.CompetencyPersonProjectId = competencyPersonProject.Id;

                // set Overall Rating based on average of POA ratings
                competencyPersonProjectAssessment.OverallRating = (decimal?)competencyPersonProjectAssessmentPointOfAssessmentList.Average(a => a.Rating);
                competencyPersonProjectAssessmentService.Save(competencyPersonProjectAssessment, CurrentPersonId);

                foreach (var competencyPersonProjectAssessmentPointOfAssessment in competencyPersonProjectAssessmentPointOfAssessmentList)
                {
                    competencyPersonProjectAssessmentPointOfAssessment.CompetencyPersonProjectAssessmentId = competencyPersonProjectAssessment.Id;

                    if (competencyPersonProjectAssessmentPointOfAssessment.Id == 0)
                    {
                        competencyPersonProjectAssessmentPointOfAssessmentService.Add(competencyPersonProjectAssessmentPointOfAssessment, CurrentPersonId);
                    }

                    competencyPersonProjectAssessmentPointOfAssessmentService.Save(competencyPersonProjectAssessmentPointOfAssessment, CurrentPersonId);
                }
            });

            Rock.Model.Page page = null;
            string          personProjectDetailPageGuid = this.GetAttributeValue("PersonProjectDetailPage");

            if (!string.IsNullOrWhiteSpace(personProjectDetailPageGuid))
            {
                page = new PageService().Get(new Guid(personProjectDetailPageGuid));
            }

            if (page != null)
            {
                Dictionary <string, string> qryString = new Dictionary <string, string>();
                qryString["competencyPersonProjectId"] = hfCompetencyPersonProjectId.Value;
                NavigateToPage(page.Guid, qryString);
            }
            else
            {
                throw new Exception("PersonProjectDetailPage not configured correctly");
            }
        }
Exemple #12
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);
        }