/// <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) { Campus campus; CampusService campusService = new CampusService(); int campusId = int.Parse(hfCampusId.Value); if (campusId == 0) { campus = new Campus(); campusService.Add(campus, CurrentPersonId); } else { campus = campusService.Get(campusId); } campus.Name = tbCampusName.Text; campus.ShortCode = tbCampusCode.Text; if (!campus.IsValid) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction(() => { campusService.Save(campus, CurrentPersonId); }); NavigateToParentPage(); }
/// <summary> /// Handles the Delete event of the gCampuses 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 gCampuses_Delete(object sender, RowEventArgs e) { CampusService campusService = new CampusService(); Campus campus = campusService.Get((int)gCampuses.DataKeys[e.RowIndex]["id"]); if (CurrentBlock != null) { campusService.Delete(campus, CurrentPersonId); campusService.Save(campus, CurrentPersonId); } BindGrid(); }
/// <summary> /// Handles the Delete event of the gCampuses 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 gCampuses_Delete(object sender, RowEventArgs e) { RockTransactionScope.WrapTransaction(() => { CampusService campusService = new CampusService(); Campus campus = campusService.Get((int)e.RowKeyValue); if (campus != null) { string errorMessage; if (!campusService.CanDelete(campus, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } campusService.Delete(campus, CurrentPersonId); campusService.Save(campus, 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) { Campus campus; CampusService campusService = new CampusService(); int campusId = int.Parse(hfCampusId.Value);; if (campusId == 0) { campus = new Campus(); campusService.Add(campus, CurrentPersonId); } else { campus = campusService.Get(campusId); } campus.Name = tbCampusName.Text; // check for duplicates if (campusService.Queryable().Count(a => a.Name.Equals(campus.Name, StringComparison.OrdinalIgnoreCase) && !a.Id.Equals(campus.Id)) > 0) { nbMessage.Text = WarningMessage.DuplicateFoundMessage("name", Campus.FriendlyTypeName); nbMessage.Visible = true; return; } if (!campus.IsValid) { // Controls will render the error messages return; } campusService.Save(campus, CurrentPersonId); BindGrid(); pnlDetails.Visible = false; pnlList.Visible = true; }