/// <summary> /// Shows the edit details. /// </summary> /// <param name="competencyPerson">The competency person.</param> private void ShowEditDetails(CompetencyPerson competencyPerson) { if (competencyPerson.Id > 0) { lActionTitle.Text = ActionTitle.Edit("Competency for Resident"); } else { lActionTitle.Text = ActionTitle.Add("Competency to Resident"); } SetEditMode(true); LoadDropDowns(); lblPersonName.Text = competencyPerson.Person.FullName; ddlCompetency.SetValue(competencyPerson.CompetencyId); if (competencyPerson.Competency != null) { lblPeriod.Text = competencyPerson.Competency.Track.Period.Name; lblTrack.Text = competencyPerson.Competency.Track.Name; lblCompetency.Text = competencyPerson.Competency.Name; } else { // shouldn't happen, but just in case lblCompetency.Text = Rock.Constants.None.Text; } // only allow a Competency to be assigned when in Add mode pnlCompetencyLabels.Visible = competencyPerson.Id != 0; pnlCompetencyDropDownLists.Visible = competencyPerson.Id == 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 <CompetencyPerson> service = new ResidencyService <CompetencyPerson>(); CompetencyPerson item = service.Get(hfCompetencyPersonId.ValueAsInt()); ShowEditDetails(item); }
/// <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 (hfCompetencyPersonId.ValueAsInt().Equals(0)) { // Cancelling on Add. Return to Grid // if this page was called from the ResidencyPerson Detail page, return to that string personId = PageParameter("personId"); if (!string.IsNullOrWhiteSpace(personId)) { Dictionary <string, string> qryString = new Dictionary <string, string>(); qryString["personId"] = personId; NavigateToParentPage(qryString); } else { NavigateToParentPage(); } } else { // Cancelling on Edit. Return to Details ResidencyService <CompetencyPerson> service = new ResidencyService <CompetencyPerson>(); CompetencyPerson item = service.Get(hfCompetencyPersonId.ValueAsInt()); ShowReadonlyDetails(item); } }
/// <summary> /// Shows the detail. /// </summary> /// <param name="itemKey">The item key.</param> /// <param name="itemKeyValue">The item key value.</param> /// <param name="personId">The person id.</param> public void ShowDetail(string itemKey, int itemKeyValue, int?personId) { // return if unexpected itemKey if (itemKey != "competencyPersonId") { return; } pnlDetails.Visible = true; // Load depending on Add(0) or Edit CompetencyPerson competencyPerson = null; if (!itemKeyValue.Equals(0)) { competencyPerson = new ResidencyService <CompetencyPerson>().Get(itemKeyValue); } else { competencyPerson = new CompetencyPerson { Id = 0 }; competencyPerson.PersonId = personId ?? 0; competencyPerson.Person = new ResidencyService <Person>().Get(competencyPerson.PersonId); } hfCompetencyPersonId.Value = competencyPerson.Id.ToString(); hfPersonId.Value = competencyPerson.PersonId.ToString(); // render UI based on Authorized and IsSystem bool readOnly = false; nbEditModeMessage.Text = string.Empty; if (!IsUserAuthorized("Edit")) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(CompetencyPerson.FriendlyTypeName); } if (readOnly) { btnEdit.Visible = false; ShowReadonlyDetails(competencyPerson); } else { // don't allow edit once a Competency has been assign btnEdit.Visible = false; if (competencyPerson.Id > 0) { ShowReadonlyDetails(competencyPerson); } else { ShowEditDetails(competencyPerson); } } }
/// <summary> /// Shows the readonly details. /// </summary> /// <param name="competencyPerson">The competency person.</param> private void ShowReadonlyDetails(CompetencyPerson competencyPerson) { SetEditMode(false); lblMainDetails.Text = new DescriptionList() .Add("Resident", competencyPerson.Person) .Add("Competency", competencyPerson.Competency.Name) .Html; }
/// <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(CompetencyPerson item, out string errorMessage) { errorMessage = string.Empty; if (new ResidencyService <CompetencyPersonProject>().Queryable().Any(a => a.CompetencyPersonId == item.Id)) { errorMessage = string.Format("This {0} is assigned to a {1}.", CompetencyPerson.FriendlyTypeName, CompetencyPersonProject.FriendlyTypeName); return(false); } return(true); }
/// <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 competencyPersonService = new ResidencyService <CompetencyPerson>(); CompetencyPerson competencyPerson = competencyPersonService.Get((int)e.RowKeyValue); if (competencyPerson != null) { string errorMessage; if (!competencyPersonService.CanDelete(competencyPerson, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } competencyPersonService.Delete(competencyPerson, CurrentPersonId); competencyPersonService.Save(competencyPerson, CurrentPersonId); } }); BindGrid(); }
/// <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); }