public BlockActionResult SaveSchedule(PersonScheduleSignupDataBag schedule) { using (var rockContext = new RockContext()) { var groupId = new GroupService(rockContext).GetNoTracking(schedule.GroupGuid).Id; var locationId = new LocationService(rockContext).GetNoTracking(schedule.LocationGuid).Id; var scheduleId = new ScheduleService(rockContext).GetNoTracking(schedule.ScheduleGuid).Id; var attendanceOccurrence = new AttendanceOccurrenceService(rockContext).GetOrAdd(schedule.ScheduledDateTime.DateTime, groupId, locationId, scheduleId); var personAlias = new PersonAliasService(rockContext).Get(CurrentPersonPrimaryAliasId); var attendanceService = new AttendanceService(rockContext); var attendance = attendanceService.ScheduledPersonAddPending(CurrentPersonId, attendanceOccurrence.Id, personAlias); if (attendance == null) { return(ActionBadRequest("Failed to schedule that particular date. Please try again.")); } rockContext.SaveChanges(); attendanceService.ScheduledPersonConfirm(attendance.Id); rockContext.SaveChanges(); return(ActionOk()); } }
public BlockActionResult DeleteSchedule(PersonScheduleSignupDataBag schedule) { using (var rockContext = new RockContext()) { var attendanceService = new AttendanceService(rockContext); var locationId = new LocationService(rockContext).GetNoTracking(schedule.LocationGuid).Id; var scheduleId = new ScheduleService(rockContext).GetNoTracking(schedule.ScheduleGuid).Id; var groupId = new GroupService(rockContext).GetNoTracking(schedule.GroupGuid).Id; var attendance = attendanceService.Get(schedule.ScheduledDateTime.DateTime, locationId, scheduleId, groupId, CurrentPersonId); if (attendance == null) { return(ActionBadRequest("Failed to remove attendance.")); } attendanceService.ScheduledPersonRemove(attendance.Id); rockContext.SaveChanges(); return(ActionOk()); } }