Пример #1
0
        /// <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)
        {
            var rockContext       = new RockContext();
            var attendanceService = new AttendanceService(rockContext);
            var group             = new GroupService(rockContext).Get(ddlGroup.SelectedValue.AsInteger());
            var person            = new PersonService(rockContext).Get(ppAttendee.PersonId.Value);
            var scheduleId        = ddlSchedule.SelectedValue.AsIntegerOrNull();
            var dateTime          = dpAttendanceDate.SelectedDate.Value;
            var groupLocation     = new GroupLocationService(rockContext).Get(ddlLocation.SelectedValue.AsInteger());

            attendanceService.AddOrUpdate(person.PrimaryAliasId.Value, dateTime, group.Id, groupLocation.LocationId, scheduleId, group.CampusId);

            //
            // If the user is using the activate and save button then mark the
            // person as active too.
            //
            if (sender == btnSaveActivate)
            {
                person.RecordStatusValueId = new DefinedValueService(rockContext).Get(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE.AsGuid()).Id;
            }

            rockContext.SaveChanges();

            //
            // Flush the attendance cache.
            //
            Rock.CheckIn.KioskLocationAttendance.Remove(groupLocation.LocationId);

            nbAttended.Text = string.Format("{0} has been marked attended.", person.FullName);

            //
            // Clear the person picker and open it so it's ready to go.
            //
            ppAttendee.SetValue(null);
            btnSaveActivate.Visible  = false;
            nbInactivePerson.Visible = false;

            //
            // Autoexpand the person picker for next entry.
            //
            var personPickerStartupScript = @"(function () {
                var runOnce = true;
                Sys.Application.add_load(function () {
                    if ( runOnce ) {
                        var personPicker = $('.js-attendee');
                        var currentPerson = personPicker.find('.picker-selectedperson').html();
                        if (currentPerson != null && currentPerson.length == 0) {
                            $(personPicker).find('a.picker-label').trigger('click');
                        }
                        runOnce = false;
                    }
                })
            })();";

            ScriptManager.RegisterStartupScript(btnSave, this.GetType(), "StartupScript", personPickerStartupScript, true);

            BindAttendees();
        }
Пример #2
0
        public static void CloneAttendance(Attendance attendance, bool isSubroom, Location location, AttendanceService notUsed, Request req)
        {
            RockContext       rockContext       = new RockContext();
            AttendanceService attendanceService = new AttendanceService(rockContext);
            Attendance        newAttendance;

            if (!isSubroom)
            {
                newAttendance = attendanceService.AddOrUpdate(attendance.PersonAliasId, attendance.StartDateTime.Date, attendance.Occurrence.GroupId,
                                                              location.Id, attendance.Occurrence.ScheduleId, location.CampusId,
                                                              null, null, null, null, null, null);
            }
            else
            {
                newAttendance = attendanceService.AddOrUpdate(attendance.PersonAliasId, attendance.StartDateTime.Date, attendance.Occurrence.GroupId,
                                                              location.ParentLocationId, attendance.Occurrence.ScheduleId, location.CampusId,
                                                              null, null, null, null, null, null);
            }
            newAttendance.StartDateTime    = Rock.RockDateTime.Now;
            newAttendance.EndDateTime      = null;
            newAttendance.DidAttend        = true;
            newAttendance.AttendanceCodeId = attendance.AttendanceCodeId;
            if (isSubroom)
            {
                newAttendance.ForeignId = location.Id;
            }
            else
            {
                newAttendance.ForeignId = null;
            }
            attendanceService.Add(newAttendance);
            var stayedFifteenMinutes = (Rock.RockDateTime.Now - attendance.StartDateTime) > new TimeSpan(0, 15, 0);

            attendance.DidAttend   = stayedFifteenMinutes;
            attendance.EndDateTime = Rock.RockDateTime.Now;

            rockContext.SaveChanges();

            AttendanceCache.RemoveWithParent(attendance.PersonAlias.PersonId);
            AttendanceCache.AddOrUpdate(newAttendance);
            AttendanceCache.AddOrUpdate(attendance);
        }
Пример #3
0
        public static void CloneAttendance(Attendance attendance, bool isSubroom, Location location, AttendanceService attendanceService, Request req)
        {
            Attendance newAttendance = null;

            if (!isSubroom)
            {
                newAttendance = attendanceService.AddOrUpdate(attendance.PersonAliasId, attendance.StartDateTime.Date, attendance.Occurrence.GroupId,
                                                              location.Id, attendance.Occurrence.ScheduleId, location.CampusId,
                                                              null, null, null, null, null, null);
            }
            else
            {
                newAttendance = attendanceService.AddOrUpdate(attendance.PersonAliasId, attendance.StartDateTime.Date, attendance.Occurrence.GroupId,
                                                              location.ParentLocationId, attendance.Occurrence.ScheduleId, location.CampusId,
                                                              null, null, null, null, null, null);
            }
            newAttendance.StartDateTime    = Rock.RockDateTime.Now;
            newAttendance.EndDateTime      = null;
            newAttendance.DidAttend        = true;
            newAttendance.AttendanceCodeId = attendance.AttendanceCodeId;
            if (isSubroom)
            {
                newAttendance.ForeignId = location.Id;
            }
            else
            {
                newAttendance.ForeignId = null;
            }
            attendanceService.Add(newAttendance);
            var stayedFifteenMinutes = (Rock.RockDateTime.Now - attendance.StartDateTime) > new TimeSpan(0, 15, 0);

            attendance.DidAttend   = stayedFifteenMinutes;
            attendance.EndDateTime = Rock.RockDateTime.Now;
            InMemoryPersonStatus.RemoveFromWorship(attendance.PersonAlias.PersonId);
            InMemoryPersonStatus.RemoveFromWithParent(attendance.PersonAlias.PersonId);
            CheckInCountCache.AddAttendance(newAttendance);
            CheckInCountCache.RemoveAttendance(attendance);
        }
Пример #4
0
        protected void Save(object sender, EventArgs e)
        {
            if (hfIsDirty.Value.AsBoolean())
            {
                gList.Enabled = false;
                var attendanceService = new AttendanceService(_rockContext);
                foreach (var attendance in _attendanceToAdd)
                {
                    attendanceService.AddOrUpdate(attendance.PersonAliasId.Value, attendance.StartDateTime, _groupId, _locationId, _scheduleId, _campusId);
                }

                foreach (int id in _attendanceToChange)
                {
                    var attendance = attendanceService.Get(id);
                    if (attendance == null)
                    {
                        continue;
                    }
                    attendance.DidAttend = true;
                }

                foreach (int id in _attendanceToRemove)
                {
                    var attendance = attendanceService.Get(id);
                    attendanceService.Delete(attendance);
                }

                _rockContext.SaveChanges();
                _attendance.Clear();
                _attendanceToAdd.Clear();
                _attendanceToRemove.Clear();
                _attendanceToChange.Clear();
                gList.Enabled = true;
                DisplayBox("Attendance Saved", NotificationBoxType.Info);
                hfIsDirty.Value = "false";
                GetAttended();
                BindGrid();
            }
        }
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The workflow action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public override bool Execute(RockContext rockContext, Model.WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            var checkInState = GetCheckInState(entity, out errorMessages);

            if (checkInState != null)
            {
                Guid checkinGroupAttributeGuid = GetAttributeValue(action, "CheckinGroupAttribute").AsGuid();
                if (checkinGroupAttributeGuid == Guid.Empty)
                {
                    throw new Exception("CheckInGroupAttribute not set. Set attribute to continue.");
                }
                string checkinGroupAttributeKey = AttributeCache.Get(checkinGroupAttributeGuid).Key;

                string sessionAttributeKey = GetAttributeValue(action, "SessionAttributeKey");

                AttendanceCode attendanceCode = null;
                DateTime       startDateTime  = RockDateTime.Now;

                bool reuseCodeForFamily = checkInState.CheckInType != null && checkInState.CheckInType.ReuseSameCode;
                int  securityCodeLength = checkInState.CheckInType != null ? checkInState.CheckInType.SecurityCodeAlphaNumericLength : 3;

                AttendanceCodeService attendanceCodeService = new AttendanceCodeService(rockContext);
                AttendanceService     attendanceService     = new AttendanceService(rockContext);
                GroupMemberService    groupMemberService    = new GroupMemberService(rockContext);
                PersonAliasService    personAliasService    = new PersonAliasService(rockContext);
                GroupService          groupService          = new GroupService(rockContext);

                var family = checkInState.CheckIn.CurrentFamily;
                if (family != null)
                {
                    foreach (var person in family.GetPeople(true))
                    {
                        if (reuseCodeForFamily && attendanceCode != null)
                        {
                            person.SecurityCode = attendanceCode.Code;
                        }
                        else
                        {
                            attendanceCode      = AttendanceCodeService.GetNew(securityCodeLength);
                            person.SecurityCode = attendanceCode.Code;
                        }

                        foreach (var groupType in person.GetGroupTypes(true))
                        {
                            foreach (var group in groupType.GetGroups(true))
                            {
                                var referenceGroupGuid = group.Group.GetAttributeValue(checkinGroupAttributeKey).AsGuid();
                                var referenceGroup     = groupService.Get(referenceGroupGuid);
                                if (referenceGroup == null)
                                {
                                    group.Selected = false;
                                    continue;
                                }
                                GroupMember groupMember = groupMemberService.GetByGroupIdAndPersonId(referenceGroup.Id, person.Person.Id).FirstOrDefault();
                                if (groupMember == null)
                                {
                                    group.Selected = false;
                                    continue;
                                }
                                groupMember.LoadAttributes();
                                int sessions = groupMember.GetAttributeValue(sessionAttributeKey).AsInteger();

                                foreach (var location in group.GetLocations(true))
                                {
                                    foreach (var schedule in location.GetSchedules(true))
                                    {
                                        if (sessions == 0)
                                        {
                                            continue;
                                        }

                                        // Only create one attendance record per day for each person/schedule/group/location
                                        var attendance = attendanceService.Get(startDateTime, location.Location.Id, schedule.Schedule.Id, group.Group.Id, person.Person.Id);
                                        if (attendance == null)
                                        {
                                            var primaryAlias = personAliasService.GetPrimaryAlias(person.Person.Id);
                                            if (primaryAlias != null)
                                            {
                                                attendance = attendanceService.AddOrUpdate(primaryAlias.Id, startDateTime.Date, group.Group.Id,
                                                                                           location.Location.Id, schedule.Schedule.Id, location.CampusId,
                                                                                           checkInState.Kiosk.Device.Id, checkInState.CheckIn.SearchType.Id,
                                                                                           checkInState.CheckIn.SearchValue, family.Group.Id, attendanceCode.Id);

                                                attendanceService.Add(attendance);
                                            }

                                            //decrement sessions and save
                                            sessions--;
                                            groupMember.SetAttributeValue(sessionAttributeKey, sessions);
                                            groupMember.SaveAttributeValues();
                                        }
                                        else
                                        {
                                            foreach (var cPerson in checkInState.CheckIn.Families.SelectMany(f => f.People))
                                            {
                                                cPerson.Selected = false;
                                                cPerson.GroupTypes.ForEach(gt => gt.Selected = false);
                                            }
                                            return(true);
                                        }

                                        attendance.AttendanceCodeId = attendanceCode.Id;
                                        attendance.StartDateTime    = startDateTime;
                                        attendance.EndDateTime      = null;
                                        attendance.DidAttend        = true;

                                        KioskLocationAttendance.AddAttendance(attendance);
                                    }
                                }
                            }
                        }
                    }
                }

                rockContext.SaveChanges();
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Handles the Click event of the lbSave 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 lbSave_Click(object sender, EventArgs e)
        {
            if (CurrentGroup != null)
            {
                if (ddlOccurence.SelectedValue.AsInteger() != 0)
                {
                    //The drop down stores the time in unix time
                    var occurenceDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Local)
                                        .AddSeconds(ddlOccurence.SelectedValue.AsInteger());

                    var attendanceData = new AttendanceService(_rockContext)
                                         .Queryable("PersonAlias")
                                         .Where(a => a.Occurrence.GroupId == CurrentGroup.Id && a.StartDateTime == occurenceDate);


                    var attendanceOccurenceService = new AttendanceOccurrenceService(_rockContext);
                    if (cbDidNotMeet.Checked == true)
                    {
                        var occurrence = attendanceOccurenceService.Get(occurenceDate.Date, CurrentGroup.Id, null, CurrentGroup.ScheduleId);
                        if (occurrence == null)
                        {
                            occurrence = new AttendanceOccurrence();
                            occurrence.OccurrenceDate = occurenceDate;
                            occurrence.GroupId        = CurrentGroup.Id;
                            occurrence.ScheduleId     = CurrentGroup.ScheduleId;
                            attendanceOccurenceService.Add(occurrence);
                        }
                        occurrence.DidNotOccur = true;
                        foreach (var attendee in occurrence.Attendees)
                        {
                            attendee.DidAttend = false;
                        }
                    }
                    else
                    {
                        var attendanceService  = new AttendanceService(_rockContext);
                        var personAliasService = new PersonAliasService(_rockContext);

                        foreach (var item in lvMembers.Items)
                        {
                            var hfMember       = item.FindControl("hfMember") as HiddenField;
                            var cbMember       = item.FindControl("cbMember") as HtmlInputCheckBox;
                            var personId       = hfMember.Value.AsInteger();
                            var attendanceItem = attendanceData.Where(a => a.PersonAlias.PersonId == personId)
                                                 .FirstOrDefault();
                            if (attendanceItem == null)
                            {
                                var attendancePerson = new PersonService(_rockContext).Get(personId);
                                if (attendancePerson != null && attendancePerson.PrimaryAliasId.HasValue)
                                {
                                    attendanceItem = attendanceService.AddOrUpdate(attendancePerson.PrimaryAliasId.Value, occurenceDate, CurrentGroup.Id, null, CurrentGroup.ScheduleId, CurrentGroup.CampusId);
                                }
                            }

                            if (attendanceItem != null)
                            {
                                attendanceItem.DidAttend = cbMember.Checked;
                            }
                        }
                    }
                }


                _rockContext.SaveChanges();
                nbNotice.Text = "Attendance Saved";
                nbNotice.NotificationBoxType = NotificationBoxType.Success;
                nbNotice.Visible             = true;
                nbNotice.Dismissable         = true;
            }
        }
Пример #7
0
        private void SaveAttendance(Group group, Location location, Schedule schedule)
        {
            PersonAliasService personAliasService = new PersonAliasService(rockContext);
            var personAlias = personAliasService.Get(personAliasGuid.AsGuid());

            if (personAlias == null)
            {
                errorMessages.Add("No Person Found");
                return;
            }
            ;

            var memberOptions = keywordSearchType = GetAttributeValue(action, "MemberOptions", true);

            if (memberOptions != "0")   //Not just add attendance
            {
                GroupMemberService groupMemberService = new GroupMemberService(rockContext);
                // get group member
                var groupMember = groupMemberService.Queryable()
                                  .Where(m => m.GroupId == group.Id &&
                                         m.PersonId == personAlias.PersonId)
                                  .FirstOrDefault();
                if (groupMember == null)
                {
                    if (memberOptions == "1")   //Create new member
                    {
                        if (group != null)
                        {
                            groupMember                   = new GroupMember();
                            groupMember.GroupId           = group.Id;
                            groupMember.PersonId          = personAlias.PersonId;
                            groupMember.GroupMemberStatus = GroupMemberStatus.Active;
                            groupMember.GroupRole         = group.GroupType.DefaultGroupRole;
                            groupMemberService.Add(groupMember);
                            rockContext.SaveChanges();
                        }
                    }
                    else //Must be in group
                    {
                        action.AddLogEntry(string.Format("{0} was not a member of the group {1} and the action was not configured to add them.", personAlias.Person.FullName, group.Name));
                        return;
                    }
                }
            }


            //Save attendance
            AttendanceService attendanceService = new AttendanceService(rockContext);

            attendanceService.AddOrUpdate(personAlias.Id, Rock.RockDateTime.Now, group.Id, location?.Id, schedule?.Id, location?.CampusId);

            //Set Attributes for Group Location and Schedule
            var groupAttribute = AttributeCache.Get(GetAttributeValue(action, "GroupOutput").AsGuid(), rockContext);

            if (groupAttribute != null)
            {
                SetWorkflowAttributeValue(action, groupAttribute.Guid, group.Guid.ToString());
            }

            var locationAttribute = AttributeCache.Get(GetAttributeValue(action, "LocationOutput").AsGuid(), rockContext);

            if (locationAttribute != null && location != null)
            {
                SetWorkflowAttributeValue(action, locationAttribute.Guid, location.Guid.ToString());
            }

            var scheduleAttribute = AttributeCache.Get(GetAttributeValue(action, "ScheduleOutput").AsGuid(), rockContext);

            if (scheduleAttribute != null && schedule != null)
            {
                SetWorkflowAttributeValue(action, scheduleAttribute.Guid, schedule.Guid.ToString());
            }
        }
Пример #8
0
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The workflow action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public override bool Execute(RockContext rockContext, Model.WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            var checkInState = GetCheckInState(entity, out errorMessages);

            if (checkInState != null)
            {
                AttendanceCode attendanceCode = null;

                bool reuseCodeForFamily             = checkInState.CheckInType != null && checkInState.CheckInType.ReuseSameCode;
                int  securityCodeAlphaNumericLength = checkInState.CheckInType != null ? checkInState.CheckInType.SecurityCodeAlphaNumericLength : 3;
                int  securityCodeAlphaLength        = checkInState.CheckInType != null ? checkInState.CheckInType.SecurityCodeAlphaLength : 0;
                int  securityCodeNumericLength      = checkInState.CheckInType != null ? checkInState.CheckInType.SecurityCodeNumericLength : 0;
                bool securityCodeNumericRandom      = checkInState.CheckInType != null ? checkInState.CheckInType.SecurityCodeNumericRandom : true;


                var attendanceCodeService = new AttendanceCodeService(rockContext);
                var attendanceService     = new AttendanceService(rockContext);
                var groupMemberService    = new GroupMemberService(rockContext);
                var personAliasService    = new PersonAliasService(rockContext);
                var attendanceRecords     = new List <Attendance>();

                checkInState.Messages.Clear();

                var family = checkInState.CheckIn.CurrentFamily;
                if (family != null)
                {
                    var currentOccurences = new List <OccurenceRecord>();
                    foreach (var person in family.GetPeople(true))
                    {
                        if (reuseCodeForFamily && attendanceCode != null)
                        {
                            person.SecurityCode = attendanceCode.Code;
                        }
                        else
                        {
                            attendanceCode      = AttendanceCodeService.GetNew(securityCodeAlphaNumericLength, securityCodeAlphaLength, securityCodeNumericLength, securityCodeNumericRandom);
                            person.SecurityCode = attendanceCode.Code;
                        }

                        foreach (var groupType in person.GetGroupTypes(true))
                        {
                            foreach (var group in groupType.GetGroups(true))
                            {
                                if (groupType.GroupType.AttendanceRule == AttendanceRule.AddOnCheckIn &&
                                    groupType.GroupType.DefaultGroupRoleId.HasValue &&
                                    !groupMemberService.GetByGroupIdAndPersonId(group.Group.Id, person.Person.Id, true).Any())
                                {
                                    var groupMember = new GroupMember();
                                    groupMember.GroupId     = group.Group.Id;
                                    groupMember.PersonId    = person.Person.Id;
                                    groupMember.GroupRoleId = groupType.GroupType.DefaultGroupRoleId.Value;
                                    groupMemberService.Add(groupMember);
                                }

                                foreach (var location in group.GetLocations(true))
                                {
                                    bool isCheckedIntoLocation = false;
                                    foreach (var schedule in location.GetSchedules(true))
                                    {
                                        var startDateTime = schedule.CampusCurrentDateTime;

                                        // If we're enforcing strict location thresholds, then before we create an attendance record
                                        // we need to check the location-schedule's current count.
                                        if (GetAttributeValue(action, "EnforceStrictLocationThreshold").AsBoolean() && location.Location.SoftRoomThreshold.HasValue)
                                        {
                                            var thresHold = location.Location.SoftRoomThreshold.Value;
                                            if (checkInState.ManagerLoggedIn && location.Location.FirmRoomThreshold.HasValue && location.Location.FirmRoomThreshold.Value > location.Location.SoftRoomThreshold.Value)
                                            {
                                                thresHold = location.Location.FirmRoomThreshold.Value;
                                            }

                                            var currentOccurence = GetCurrentOccurence(currentOccurences, location, schedule, startDateTime.Date);

                                            // The totalAttended is the number of people still checked in (not people who have been checked-out)
                                            // not counting the current person who may already be checked in,
                                            // + the number of people we have checked in so far (but haven't been saved yet).
                                            var attendanceQry = attendanceService.GetByDateOnLocationAndSchedule(startDateTime.Date, location.Location.Id, schedule.Schedule.Id)
                                                                .AsNoTracking()
                                                                .Where(a => a.EndDateTime == null);

                                            // Only process if the current person is NOT already checked-in to this location and schedule
                                            if (!attendanceQry.Where(a => a.PersonAlias.PersonId == person.Person.Id).Any())
                                            {
                                                var totalAttended = attendanceQry.Count() + (currentOccurence == null ? 0 : currentOccurence.Count);

                                                // If over capacity, remove the schedule and add a warning message.
                                                if (totalAttended >= thresHold)
                                                {
                                                    // Remove the schedule since the location was full for this schedule.
                                                    location.Schedules.Remove(schedule);

                                                    var message = new CheckInMessage()
                                                    {
                                                        MessageType = MessageType.Warning
                                                    };

                                                    var mergeFields = Lava.LavaHelper.GetCommonMergeFields(null);
                                                    mergeFields.Add("Person", person.Person);
                                                    mergeFields.Add("Group", group.Group);
                                                    mergeFields.Add("Location", location.Location);
                                                    mergeFields.Add("Schedule", schedule.Schedule);
                                                    message.MessageText = GetAttributeValue(action, "NotChecked-InMessageFormat").ResolveMergeFields(mergeFields);

                                                    // Now add it to the check-in state message list for others to see.
                                                    checkInState.Messages.Add(message);
                                                    continue;
                                                }
                                                else
                                                {
                                                    // Keep track of anyone who was checked in so far.
                                                    if (currentOccurence == null)
                                                    {
                                                        currentOccurence = new OccurenceRecord()
                                                        {
                                                            Date       = startDateTime.Date,
                                                            LocationId = location.Location.Id,
                                                            ScheduleId = schedule.Schedule.Id
                                                        };
                                                        currentOccurences.Add(currentOccurence);
                                                    }

                                                    currentOccurence.Count += 1;
                                                }
                                            }
                                        }

                                        // Only create one attendance record per day for each person/schedule/group/location
                                        var attendance = attendanceService.Get(startDateTime, location.Location.Id, schedule.Schedule.Id, group.Group.Id, person.Person.Id);
                                        if (attendance == null)
                                        {
                                            var primaryAlias = personAliasService.GetPrimaryAlias(person.Person.Id);
                                            if (primaryAlias != null)
                                            {
                                                attendance = attendanceService.AddOrUpdate(primaryAlias.Id, startDateTime.Date, group.Group.Id,
                                                                                           location.Location.Id, schedule.Schedule.Id, location.CampusId,
                                                                                           checkInState.Kiosk.Device.Id, checkInState.CheckIn.SearchType.Id,
                                                                                           checkInState.CheckIn.SearchValue, family.Group.Id, attendanceCode.Id);

                                                attendance.PersonAlias = primaryAlias;
                                            }
                                        }

                                        attendance.DeviceId                 = checkInState.Kiosk.Device.Id;
                                        attendance.SearchTypeValueId        = checkInState.CheckIn.SearchType.Id;
                                        attendance.SearchValue              = checkInState.CheckIn.SearchValue;
                                        attendance.CheckedInByPersonAliasId = checkInState.CheckIn.CheckedInByPersonAliasId;
                                        attendance.SearchResultGroupId      = family.Group.Id;
                                        attendance.AttendanceCodeId         = attendanceCode.Id;
                                        attendance.StartDateTime            = startDateTime;
                                        attendance.EndDateTime              = null;
                                        attendance.DidAttend                = true;
                                        attendance.Note = group.Notes;

                                        KioskLocationAttendance.AddAttendance(attendance);
                                        isCheckedIntoLocation = true;

                                        // Keep track of attendance (Ids) for use by other actions later in the workflow pipeline
                                        attendanceRecords.Add(attendance);
                                    }

                                    // If the person was NOT checked into the location for any schedule then remove the location
                                    if (!isCheckedIntoLocation)
                                    {
                                        group.Locations.Remove(location);
                                    }
                                }
                            }
                        }
                    }
                }

                rockContext.SaveChanges();

                // Now that the records are persisted, take the Ids and save them to the temp CheckInFamliy object
                family.AttendanceIds = attendanceRecords.Select(a => a.Id).ToList();
                attendanceRecords    = null;

                return(true);
            }

            return(false);
        }
Пример #9
0
        private MobileBlockResponse SaveAttendance(Dictionary <string, string> body)
        {
            GetGroupMembers(body["groupId"]);

            if (group != null)
            {
                if (body["schedule"].AsInteger() != 0)
                {
                    //The drop down stores the time in unix time
                    var occurenceDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Local)
                                        .AddSeconds(body["schedule"].AsInteger());

                    var attendanceService = new AttendanceService(rockContext);
                    var attendanceData    = attendanceService
                                            .Queryable("PersonAlias")
                                            .Where(a => a.Occurrence.GroupId == group.Id && a.StartDateTime == occurenceDate);

                    var personAliasService = new PersonAliasService(rockContext);

                    foreach (var item in groupMembers)
                    {
                        var personId       = item.PersonId;
                        var attendanceItem = attendanceData.Where(a => a.PersonAlias.PersonId == personId)
                                             .FirstOrDefault();
                        if (attendanceItem == null)
                        {
                            var attendancePerson = new PersonService(rockContext).Get(personId);
                            if (attendancePerson != null)
                            {
                                attendanceService.AddOrUpdate(attendancePerson.PrimaryAliasId ?? 0, occurenceDate, group.Id, null, group.ScheduleId, group.CampusId);
                            }
                        }

                        if (body["didNotMeet"].AsBoolean())
                        {
                            attendanceItem.DidAttend = false;
                            attendanceItem.Occurrence.DidNotOccur = true;
                        }
                        else
                        {
                            List <string> groupMemberAttendedIds = groupMemberAttendedIds = body["groupMembers"].SplitDelimitedValues(false).ToList();
                            attendanceItem.Occurrence.DidNotOccur = false;
                            attendanceItem.DidAttend = groupMemberAttendedIds.Contains(personId.ToString());
                        }
                    }
                }

                rockContext.SaveChanges();

                var response = new FormResponse
                {
                    Success          = true,
                    Message          = "Attendance Saved",
                    FormElementItems = GetForm(body["schedule"])
                };

                return(new MobileBlockResponse()
                {
                    Request = "save",
                    Response = JsonConvert.SerializeObject(response),
                    TTL = 0
                });
            }

            var errorResponse = new FormResponse
            {
                Success = false,
                Message = "There was an errror saving your attendance."
            };

            return(new MobileBlockResponse()
            {
                Request = "save",
                Response = JsonConvert.SerializeObject(errorResponse),
                TTL = 0
            });
        }