/// <summary> /// Handles the ItemDataBound event of the rptPointOfAssessment control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterItemEventArgs"/> instance containing the event data.</param> protected void rptPointOfAssessment_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e) { CompetencyPersonProjectAssessmentPointOfAssessment competencyPersonProjectAssessmentPointOfAssessment = e.Item.DataItem as CompetencyPersonProjectAssessmentPointOfAssessment; if (competencyPersonProjectAssessmentPointOfAssessment != null) { LabeledDropDownList ddlPointOfAssessmentRating = e.Item.FindControl("ddlPointOfAssessmentRating") as LabeledDropDownList; ddlPointOfAssessmentRating.Items.Clear(); ddlPointOfAssessmentRating.Items.Add(new ListItem("-", Rock.Constants.None.IdValue)); for (int ratingOption = 1; ratingOption <= 5; ratingOption++) { ddlPointOfAssessmentRating.Items.Add(new ListItem(ratingOption.ToString(), ratingOption.ToString())); } ddlPointOfAssessmentRating.SetValue(competencyPersonProjectAssessmentPointOfAssessment.Rating.ToString()); HiddenField hfProjectPointOfAssessmentId = e.Item.FindControl("hfProjectPointOfAssessmentId") as HiddenField; hfProjectPointOfAssessmentId.Value = competencyPersonProjectAssessmentPointOfAssessment.ProjectPointOfAssessmentId.ToString(); Literal lblAssessmentText = e.Item.FindControl("lblAssessmentText") as Literal; lblAssessmentText.Text = string.Format( "{0}. {1}", competencyPersonProjectAssessmentPointOfAssessment.ProjectPointOfAssessment.AssessmentOrder, competencyPersonProjectAssessmentPointOfAssessment.ProjectPointOfAssessment.AssessmentText); TextBox tbRatingNotesPOA = e.Item.FindControl("tbRatingNotesPOA") as TextBox; tbRatingNotesPOA.Text = competencyPersonProjectAssessmentPointOfAssessment.RatingNotes; } }
/// <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"); } }