/// <summary> /// Handles the ItemCommand event of the rLocations control. /// </summary> /// <param name="source">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterCommandEventArgs"/> instance containing the event data.</param> protected void rLocations_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e) { int?locationId = (e.CommandArgument as string).AsIntegerOrNull(); if (locationId.HasValue) { var rockContext = new RockContext(); var location = new LocationService(rockContext).Get(locationId.Value); if (location != null) { if (e.CommandName == "Open" && !location.IsActive) { location.IsActive = true; rockContext.SaveChanges(); KioskDevice.Clear(); } else if (e.CommandName == "Close" && location.IsActive) { location.IsActive = false; rockContext.SaveChanges(); KioskDevice.Clear(); } } BindManagerLocationsGrid(); } }
/// <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) { using (var rockContext = new RockContext()) { GroupLocationService groupLocationService = new GroupLocationService(rockContext); ScheduleService scheduleService = new ScheduleService(rockContext); bool schedulesChanged = false; var gridViewRows = gGroupLocationSchedule.Rows; foreach (GridViewRow row in gridViewRows.OfType <GridViewRow>()) { int groupLocationId = int.Parse(gGroupLocationSchedule.DataKeys[row.RowIndex].Value as string); GroupLocation groupLocation = groupLocationService.Get(groupLocationId); if (groupLocation != null) { foreach (var fieldCell in row.Cells.OfType <DataControlFieldCell>()) { var checkBoxTemplateField = fieldCell.ContainingField as CheckBoxEditableField; if (checkBoxTemplateField != null) { CheckBox checkBox = fieldCell.Controls[0] as CheckBox; string dataField = (fieldCell.ContainingField as CheckBoxEditableField).DataField; int scheduleId = int.Parse(dataField.Replace("scheduleField_", string.Empty)); // update GroupLocationSchedule depending on if the Schedule is Checked or not if (checkBox.Checked) { // This schedule is selected, so if GroupLocationSchedule doesn't already have this schedule, add it if (!groupLocation.Schedules.Any(a => a.Id == scheduleId)) { var schedule = scheduleService.Get(scheduleId); groupLocation.Schedules.Add(schedule); schedulesChanged = true; } } else { // This schedule is not selected, so if GroupLocationSchedule has this schedule, delete it if (groupLocation.Schedules.Any(a => a.Id == scheduleId)) { groupLocation.Schedules.Remove(groupLocation.Schedules.FirstOrDefault(a => a.Id == scheduleId)); schedulesChanged = true; } } } } } } if (schedulesChanged) { rockContext.SaveChanges(); KioskDevice.Clear(); } } NavigateToHomePage(); }