/// <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 ) { Schedule schedule; ScheduleService scheduleService = new ScheduleService(); int scheduleId = int.Parse( hfScheduleId.Value ); if ( scheduleId == 0 ) { schedule = new Schedule(); scheduleService.Add( schedule, CurrentPersonId ); } else { schedule = scheduleService.Get( scheduleId ); } schedule.Name = tbScheduleName.Text; schedule.Description = tbScheduleDescription.Text; schedule.iCalendarContent = sbSchedule.iCalendarContent; schedule.CategoryId = cpCategory.SelectedValueAsInt(); int offsetMins = int.MinValue; if ( int.TryParse( nbStartOffset.Text, out offsetMins ) ) { schedule.CheckInStartOffsetMinutes = offsetMins; } else { schedule.CheckInStartOffsetMinutes = null; } offsetMins = int.MinValue; if ( int.TryParse( nbEndOffset.Text, out offsetMins ) ) { schedule.CheckInEndOffsetMinutes = offsetMins; } else { schedule.CheckInEndOffsetMinutes = null; } if ( !schedule.IsValid ) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction( () => { scheduleService.Save( schedule, CurrentPersonId ); } ); var qryParams = new Dictionary<string, string>(); qryParams["ScheduleId"] = schedule.Id.ToString(); NavigateToPage( RockPage.Guid, qryParams ); }
/// <summary> /// Handles the Delete event of the gSchedules 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 gSchedules_Delete( object sender, RowEventArgs e ) { RockTransactionScope.WrapTransaction( () => { ScheduleService scheduleService = new ScheduleService(); Schedule schedule = scheduleService.Get( (int)e.RowKeyValue ); if ( schedule != null ) { string errorMessage; if ( !scheduleService.CanDelete( schedule, out errorMessage ) ) { mdGridWarning.Show( errorMessage, ModalAlertType.Information ); return; } scheduleService.Delete( schedule, CurrentPersonId ); scheduleService.Save( schedule, CurrentPersonId ); } } ); BindGrid(); }
/// <summary> /// Handles the Click event of the btnDelete 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 btnDelete_Click( object sender, EventArgs e ) { int? categoryId = null; var service = new ScheduleService(); var item = service.Get( int.Parse( hfScheduleId.Value ) ); if ( item != null ) { string errorMessage; if ( !service.CanDelete( item, out errorMessage ) ) { ShowReadonlyDetails( item ); mdDeleteWarning.Show( errorMessage, ModalAlertType.Information ); } else { categoryId = item.CategoryId; service.Delete( item, CurrentPersonId ); service.Save( item, CurrentPersonId ); // reload page, selecting the deleted data view's parent var qryParams = new Dictionary<string, string>(); if ( categoryId != null ) { qryParams["CategoryId"] = categoryId.ToString(); } NavigateToPage( RockPage.Guid, qryParams ); } } }