Esempio n. 1
0
        public static void SyncAttendee(string apiUrl)
        {
            var eb          = new EBApi(Settings.GetAccessToken(), Settings.GetOrganizationId().ToLong(0));
            var attendee    = eb.GetAttendee(apiUrl, "event,order");
            var order       = attendee.Order;
            var rockContext = new RockContext();
            var group       = GetGroupByEBEventId(attendee.Event_Id, rockContext);
            var ebEvent     = attendee.Event;

            if (group != null && ebEvent != null)
            {
                var gmPersonAttributeKey = GetPersonAttributeKey(rockContext, group);

                var groupMemberService = new GroupMemberService(rockContext);
                var personAliasService = new PersonAliasService(rockContext);

                AttendanceOccurrence occ = GetOrAddOccurrence(rockContext, group, ebEvent);

                SyncAttendee(rockContext, attendee, order, group, groupMemberService, personAliasService, occ, attendee.Event_Id, ebEvent.IsRSVPEvent(eb), gmPersonAttributeKey, false);
                rockContext.SaveChanges();
            }
            else
            {
                HttpContext httpContext  = HttpContext.Current;
                var         logException = new Exception(string.Format("Eventbrite SyncAttendee, Group not found for Event: {0}", attendee.Event_Id), new Exception(string.Format("Sync api request: {0}", apiUrl)));
                ExceptionLogService.LogException(logException, httpContext);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Calculates the display title for an <see cref="AttendanceOccurrence"/>.
        /// </summary>
        /// <param name="occurrence">The <see cref="AttendanceOccurrence"/>.</param>
        private string GetOccurrenceTitle(AttendanceOccurrence occurrence)
        {
            bool hasTitle    = (!string.IsNullOrWhiteSpace(occurrence.Name));
            bool hasSchedule = (occurrence.Schedule != null);

            if (hasSchedule)
            {
                // This block is unnecessary if the event has a name (because the name will take priority over the schedule, anyway), but it
                // has been intentionally left in place to prevent anyone from creating an unintentional bug in the future, as it affects
                // the logic below.
                var calendarEvent = occurrence.Schedule.GetICalEvent();
                if (calendarEvent == null)
                {
                    hasSchedule = false;
                }
            }

            if (hasTitle)
            {
                return(occurrence.Name);
            }
            else if (hasSchedule)
            {
                return(string.Format(
                           "{0} - {1}",
                           occurrence.Group.Name,
                           occurrence.Schedule.GetICalEvent().DtStart.Value.TimeOfDay.ToTimeString()));
            }
            else
            {
                return(occurrence.Group.Name);
            }
        }
Esempio n. 3
0
        public AttendanceListOccurrence(AttendanceOccurrence occurrence)
        {
            Id             = occurrence.Id;
            OccurrenceDate = occurrence.OccurrenceDate;
            LocationId     = occurrence.LocationId;

            if (occurrence.Location != null)
            {
                LocationName = occurrence.Location.ToString(true);
            }

            LocationName     = occurrence.Location != null ? occurrence.Location.Name : string.Empty;
            ParentLocationId = occurrence.Location != null ? occurrence.Location.ParentLocationId : ( int? )null;
            ScheduleId       = occurrence.ScheduleId;

            if (occurrence.Schedule != null)
            {
                if (occurrence.Schedule.Name.IsNotNullOrWhiteSpace())
                {
                    ScheduleName = occurrence.Schedule.Name.EncodeHtml();
                }
                else
                {
                    ScheduleName = occurrence.Schedule.ToString();
                }
            }

            StartTime             = occurrence.Schedule != null ? occurrence.Schedule.StartTimeOfDay : new TimeSpan();
            AttendanceEntered     = occurrence.AttendanceEntered;
            DidNotOccur           = occurrence.DidNotOccur ?? false;
            DidAttendCount        = occurrence.DidAttendCount;
            AttendanceRate        = occurrence.AttendanceRate;
            Notes                 = occurrence.Notes;
            AttendanceTypeValueId = occurrence.AttendanceTypeValueId;
        }
        /// <summary>
        /// Gets the occurrence items.
        /// </summary>
        private AttendanceOccurrence GetOccurrence(RockContext rockContext, Group group, DateTime date, bool allowAdd)
        {
            var occurrenceService = new AttendanceOccurrenceService(rockContext);

            var occurrence = occurrenceService.Get(date.Date, group.Id, null, group.ScheduleId);

            // If an occurrence date was included, but no occurrence was found with that date, and new
            // occurrences can be added, create a new one
            if (occurrence == null && allowAdd)
            {
                // Create a new occurrence record and return it
                occurrence = new AttendanceOccurrence
                {
                    Group          = group,
                    GroupId        = group.Id,
                    OccurrenceDate = date.Date,
                    LocationId     = null,
                    ScheduleId     = group.ScheduleId,
                };

                occurrenceService.Add(occurrence);

                return(occurrence);
            }

            return(occurrence);
        }
        /// <summary>
        /// Gets the attendees.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="occurrence">The occurrence.</param>
        /// <param name="group">The group.</param>
        /// <returns></returns>
        private List <Attendee> GetAttendees(RockContext rockContext, AttendanceOccurrence occurrence, Group group)
        {
            var attendedIds = new List <int>();

            if (occurrence != null)
            {
                // Get the list of people who attended
                attendedIds = new AttendanceService(rockContext)
                              .Queryable().AsNoTracking()
                              .Where(a =>
                                     a.OccurrenceId == occurrence.Id &&
                                     a.DidAttend.HasValue &&
                                     a.DidAttend.Value &&
                                     a.PersonAlias != null)
                              .Select(a => a.PersonAlias.PersonId)
                              .Distinct()
                              .ToList();
            }

            return(group.Members
                   .Select(a => new Attendee
            {
                PersonGuid = a.Person.Guid,
                Attended = attendedIds.Contains(a.PersonId),
                Name = a.Person.FullName
            })
                   .ToList());
        }
Esempio n. 6
0
        public RSVPListOccurrence(AttendanceOccurrence occurrence)
        {
            this.Id             = occurrence.Id;
            this.OccurrenceDate = occurrence.OccurrenceDate;
            this.LocationId     = occurrence.LocationId;
            this.GroupId        = occurrence.GroupId;

            if (occurrence.Location != null)
            {
                if (occurrence.Location.Name.IsNotNullOrWhiteSpace())
                {
                    LocationName = occurrence.Location.Name;
                }
                else
                {
                    LocationName = occurrence.Location.ToString();
                }
            }

            LocationName     = occurrence.Location != null ? occurrence.Location.Name : string.Empty;
            ParentLocationId = occurrence.Location != null ? occurrence.Location.ParentLocationId : ( int? )null;
            ScheduleId       = occurrence.ScheduleId;

            if (occurrence.Schedule != null)
            {
                if (occurrence.Schedule.Name.IsNotNullOrWhiteSpace())
                {
                    ScheduleName = occurrence.Schedule.Name;
                }
                else
                {
                    ScheduleName = occurrence.Schedule.ToString();
                }
            }

            StartTime = occurrence.Schedule != null ? occurrence.Schedule.StartTimeOfDay : new TimeSpan();

            foreach (var attendee in occurrence.Attendees)
            {
                this.InvitedCount++;

                if (attendee.RSVP == Rock.Model.RSVP.Yes)
                {
                    this.AcceptedCount++;
                }
                else if (attendee.RSVP == Rock.Model.RSVP.No)
                {
                    this.DeclinedCount++;
                }
                else
                {
                    this.NoResponseCount++;
                }
            }
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!_canManageMembers)
            {
                nbNotice.Heading             = "Sorry";
                nbNotice.Text                = "<p>You're not authorized to update the attendance for the selected group.</p>";
                nbNotice.NotificationBoxType = NotificationBoxType.Danger;
                nbNotice.Visible             = true;
                pnlDetails.Visible           = false;
            }
            else
            {
                _occurrence = GetOccurrence();
                if (!Page.IsPostBack)
                {
                    if (_allowCampusFilter)
                    {
                        var campus = CampusCache.Get(GetBlockUserPreference("Campus").AsInteger());
                        if (campus != null)
                        {
                            bddlCampus.Title = campus.Name;
                            bddlCampus.SetValue(campus.Id);
                        }
                    }

                    BindLocations();
                    ShowDetails();
                }
                else
                {
                    if (_attendees != null)
                    {
                        foreach (var item in lvMembers.Items)
                        {
                            var hfMember = item.FindControl("hfMember") as HiddenField;
                            var cbMember = item.FindControl("cbMember") as CheckBox;

                            if (hfMember != null && cbMember != null)
                            {
                                int personId = hfMember.ValueAsInt();

                                var attendance = _attendees.Where(a => a.PersonId == personId).FirstOrDefault();
                                if (attendance != null)
                                {
                                    attendance.Attended = cbMember.Checked;
                                }
                            }
                        }
                    }
                }
            }
        }
        private AttendanceOccurrence BuildAttendanceOccurrence(RockContext rockContext, DateTime occurrenceDate)
        {
            var AttendanceOccurrence = new AttendanceOccurrence();

            AttendanceOccurrence attendanceOccurrence = new AttendanceOccurrence();

            attendanceOccurrence.ForeignKey     = attendanceOccurrenceForeignKey;
            attendanceOccurrence.OccurrenceDate = occurrenceDate;

            return(attendanceOccurrence);
        }
        public void AttendanceOccurrenceDateKeyGetsSetCorrectly()
        {
            var testList = TestDataHelper.GetAnalyticsSourceDateTestData();

            foreach (var keyValue in testList)
            {
                AttendanceOccurrence attendanceOccurrence = new AttendanceOccurrence();
                attendanceOccurrence.OccurrenceDate = keyValue.Value;
                Assert.AreEqual(keyValue.Key, attendanceOccurrence.OccurrenceDateKey);
            }
        }
        /// <summary>
        /// Gets the attendance value.
        /// </summary>
        /// <param name="attendanceOccurrence">The attendance occurrence.</param>
        /// <returns>The attendance value.</returns>
        private string GetAttendanceValue(AttendanceOccurrence attendanceOccurrence)
        {
            if (attendanceOccurrence.DidNotOccur == true)
            {
                return("Did not meet");
            }

            if (!attendanceOccurrence.AttendanceEntered)
            {
                return("No attendance");
            }

            return($"{attendanceOccurrence.DidAttendCount}/{attendanceOccurrence.Attendees.Count}");
        }
Esempio n. 11
0
        public void TestFirstDateOfWeekMonday()
        {
            var sundayDate20190825 = new DateTime(2019, 8, 25);
            var sundayDate20190901 = new DateTime(2019, 9, 1);
            var sundayDate20190908 = new DateTime(2019, 9, 8);
            var sundayDate20190915 = new DateTime(2019, 9, 15);
            var sundayDate20190922 = new DateTime(2019, 9, 22);

            Rock.Web.SystemSettings.SetValue(Rock.SystemKey.SystemSetting.START_DAY_OF_WEEK, DayOfWeek.Monday.ConvertToInt().ToString());
            RockDateTimeHelper.UpdateSundayDateData();

            Assert.That.IsTrue(new DateTime(2019, 8, 23).SundayDate() == sundayDate20190825, "Incorrect Sunday Date");
            Assert.That.IsTrue(new DateTime(2019, 8, 24).SundayDate() == sundayDate20190825, "Incorrect Sunday Date");
            Assert.That.IsTrue(new DateTime(2019, 8, 25).SundayDate() == sundayDate20190825, "Incorrect Sunday Date");
            Assert.That.IsTrue(new DateTime(2019, 8, 26).SundayDate() == sundayDate20190901, "Incorrect Sunday Date");
            Assert.That.IsTrue(new DateTime(2019, 8, 27).SundayDate() == sundayDate20190901, "Incorrect Sunday Date");
            Assert.That.IsTrue(new DateTime(2019, 8, 28).SundayDate() == sundayDate20190901, "Incorrect Sunday Date");
            Assert.That.IsTrue(new DateTime(2019, 8, 29).SundayDate() == sundayDate20190901, "Incorrect Sunday Date");
            Assert.That.IsTrue(new DateTime(2019, 8, 30).SundayDate() == sundayDate20190901, "Incorrect Sunday Date");
            Assert.That.IsTrue(new DateTime(2019, 9, 5).SundayDate() == sundayDate20190908, "Incorrect Sunday Date");
            Assert.That.IsTrue(new DateTime(2019, 9, 9).SundayDate() == sundayDate20190915, "Incorrect Sunday Date");
            Assert.That.IsTrue(new DateTime(2019, 9, 17).SundayDate() == sundayDate20190922, "Incorrect Sunday Date");

            var attendanceOccurrence = new AttendanceOccurrence()
            {
                OccurrenceDate = new DateTime(2019, 9, 17)
            };

            Assert.That.IsTrue(attendanceOccurrence.SundayDate == new DateTime(2019, 9, 17).SundayDate());
            attendanceOccurrence = new AttendanceOccurrence()
            {
                OccurrenceDate = new DateTime(2019, 9, 19)
            };
            Assert.That.IsTrue(attendanceOccurrence.SundayDate == new DateTime(2019, 9, 19).SundayDate());

            var rockContext = new RockContext();

            Assert.That.IsTrue(rockContext.Database.SqlQuery <DateTime>($@"SELECT dbo.ufnUtility_GetSundayDate('{new DateTime( 2019, 8, 23 )}')").FirstOrDefault() == sundayDate20190825, "Incorrect Sunday Date (SQL)");
            Assert.That.IsTrue(rockContext.Database.SqlQuery <DateTime>($@"SELECT dbo.ufnUtility_GetSundayDate('{new DateTime( 2019, 8, 24 )}')").FirstOrDefault() == sundayDate20190825, "Incorrect Sunday Date (SQL)");
            Assert.That.IsTrue(rockContext.Database.SqlQuery <DateTime>($@"SELECT dbo.ufnUtility_GetSundayDate('{new DateTime( 2019, 8, 25 )}')").FirstOrDefault() == sundayDate20190825, "Incorrect Sunday Date (SQL)");
            Assert.That.IsTrue(rockContext.Database.SqlQuery <DateTime>($@"SELECT dbo.ufnUtility_GetSundayDate('{new DateTime( 2019, 8, 26 )}')").FirstOrDefault() == sundayDate20190901, "Incorrect Sunday Date (SQL)");
            Assert.That.IsTrue(rockContext.Database.SqlQuery <DateTime>($@"SELECT dbo.ufnUtility_GetSundayDate('{new DateTime( 2019, 8, 27 )}')").FirstOrDefault() == sundayDate20190901, "Incorrect Sunday Date (SQL)");
            Assert.That.IsTrue(rockContext.Database.SqlQuery <DateTime>($@"SELECT dbo.ufnUtility_GetSundayDate('{new DateTime( 2019, 8, 28 )}')").FirstOrDefault() == sundayDate20190901, "Incorrect Sunday Date (SQL)");
            Assert.That.IsTrue(rockContext.Database.SqlQuery <DateTime>($@"SELECT dbo.ufnUtility_GetSundayDate('{new DateTime( 2019, 8, 29 )}')").FirstOrDefault() == sundayDate20190901, "Incorrect Sunday Date (SQL)");
            Assert.That.IsTrue(rockContext.Database.SqlQuery <DateTime>($@"SELECT dbo.ufnUtility_GetSundayDate('{new DateTime( 2019, 8, 30 )}')").FirstOrDefault() == sundayDate20190901, "Incorrect Sunday Date (SQL)");
            Assert.That.IsTrue(rockContext.Database.SqlQuery <DateTime>($@"SELECT dbo.ufnUtility_GetSundayDate('{new DateTime( 2019, 9, 5 )}')").FirstOrDefault() == sundayDate20190908, "Incorrect Sunday Date (SQL)");
            Assert.That.IsTrue(rockContext.Database.SqlQuery <DateTime>($@"SELECT dbo.ufnUtility_GetSundayDate('{new DateTime( 2019, 9, 9 )}')").FirstOrDefault() == sundayDate20190915, "Incorrect Sunday Date (SQL)");
            Assert.That.IsTrue(rockContext.Database.SqlQuery <DateTime>($@"SELECT dbo.ufnUtility_GetSundayDate('{new DateTime( 2019, 9, 17 )}')").FirstOrDefault() == sundayDate20190922, "Incorrect Sunday Date (SQL)");
        }
Esempio n. 12
0
 public AttendanceListOccurrence(AttendanceOccurrence occurrence)
 {
     Id                = occurrence.Id;
     OccurrenceDate    = occurrence.OccurrenceDate;
     LocationId        = occurrence.LocationId;
     LocationName      = occurrence.Location != null ? occurrence.Location.Name : string.Empty;
     ParentLocationId  = occurrence.Location != null ? occurrence.Location.ParentLocationId : (int?)null;
     ScheduleId        = occurrence.ScheduleId;
     ScheduleName      = occurrence.Schedule != null ? occurrence.Schedule.Name : string.Empty;
     StartTime         = occurrence.Schedule != null ? occurrence.Schedule.StartTimeOfDay : new TimeSpan();
     AttendanceEntered = occurrence.AttendanceEntered;
     DidNotOccur       = occurrence.DidNotOccur ?? false;
     DidAttendCount    = occurrence.DidAttendCount;
     AttendanceRate    = occurrence.AttendanceRate;
     Notes             = occurrence.Notes;
 }
Esempio n. 13
0
        private static AttendanceOccurrence GetOrAddOccurrence(RockContext rockContext, Group group, Event ebEvent)
        {
            var occurrenceService = new AttendanceOccurrenceService(rockContext);

            // Get all the occurrences for this group for the selected dates, location and schedule
            var occurrences = occurrenceService.GetGroupOccurrences(group, ebEvent.Start.Local.Date, null, new List <int>(), new List <int>()).ToList();

            var occ = occurrences.FirstOrDefault(o => o.OccurrenceDate.Date.Equals(ebEvent.Start.Local.Date));

            if (occ == null)
            {
                occ = new AttendanceOccurrence
                {
                    GroupId        = group.Id,
                    OccurrenceDate = ebEvent.Start.Local.Date
                };
                occurrenceService.Add(occ);
            }

            return(occ);
        }
Esempio n. 14
0
        /// <summary>
        /// Sends an RSVP reminder <see cref="SystemCommunication"/> to an individual attendee.
        /// </summary>
        /// <param name="group">The <see cref="Group"/>.</param>
        /// <param name="occurrence">The <see cref="AttendanceOccurrence"/>.</param>
        /// <param name="person">The <see cref="Person"/>.</param>
        /// <param name="reminder">The <see cref="SystemCommunication"/> to be sent as a reminder.</param>
        private int SendReminder(Group group, AttendanceOccurrence occurrence, Person person, SystemCommunication reminder)
        {
            // Build Lava merge fields.
            Dictionary <string, object> lavaMergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(null, person);

            lavaMergeFields.Add("Person", person);
            lavaMergeFields.Add("Group", group);
            lavaMergeFields.Add("Occurrence", occurrence);
            lavaMergeFields.Add("OccurrenceTitle", GetOccurrenceTitle(occurrence));

            var smsNumber = person.PhoneNumbers.GetFirstSmsNumber();

            if (person.CommunicationPreference == CommunicationType.SMS &&
                !string.IsNullOrWhiteSpace(reminder.SMSMessage) &&
                reminder.SMSFromDefinedValueId.HasValue &&
                !string.IsNullOrWhiteSpace(smsNumber))
            {
                return(SendReminderSMS(person, reminder, lavaMergeFields, smsNumber));
            }

            return(SendReminderEmail(person, reminder, lavaMergeFields));
        }
Esempio n. 15
0
        /// <summary>
        /// Creates an AttendanceOccurrence if one doesn't already exist and returns the ID.
        /// </summary>
        /// <param name="e">The RowEventArgs of the selected grid row.</param>
        /// <returns>The ID of an AttendanceOccurrence</returns>
        private int GetOccurrenceId(RowEventArgs e)
        {
            int occurrenceId = e.RowKeyId;

            if (occurrenceId == 0)
            {
                // Find or create occurrence.
                using (var rockContext = new RockContext())
                {
                    HiddenField hfOccurrenceDate = e.Row.FindControl("hfOccurrenceDate") as HiddenField;
                    HiddenField hfGroupId        = e.Row.FindControl("hfGroupId") as HiddenField;
                    HiddenField hfScheduleId     = e.Row.FindControl("hfScheduleId") as HiddenField;
                    HiddenField hfLocationId     = e.Row.FindControl("hfLocationId") as HiddenField;

                    DateTime occurrenceDate = DateTime.Parse(hfOccurrenceDate.Value);

                    int?groupId    = hfGroupId.Value.AsIntegerOrNull();
                    int?scheduleId = hfScheduleId.Value.AsIntegerOrNull();
                    int?locationId = hfLocationId.Value.AsIntegerOrNull();

                    var group = new GroupService(rockContext).Get(groupId.Value);
                    var attendanceOccurrenceService = new AttendanceOccurrenceService(rockContext);

                    //If this occurrence has already been created, just return the existing one.
                    var existingOccurrenceQry = attendanceOccurrenceService.Queryable().Where(o => o.OccurrenceDate == occurrenceDate);
                    if (groupId != null)
                    {
                        existingOccurrenceQry = existingOccurrenceQry.Where(o => o.GroupId == groupId);
                    }
                    if (scheduleId != null)
                    {
                        existingOccurrenceQry = existingOccurrenceQry.Where(o => o.ScheduleId == scheduleId);
                    }
                    if (locationId != null)
                    {
                        existingOccurrenceQry = existingOccurrenceQry.Where(o => o.LocationId == locationId);
                    }

                    var existingOccurrences = existingOccurrenceQry.ToList();
                    if (existingOccurrences.Any())
                    {
                        occurrenceId = existingOccurrences.FirstOrDefault().Id;
                    }
                    else
                    {
                        //Create new occurrence.
                        var attendanceOccurrence = new AttendanceOccurrence();

                        if (groupId != null)
                        {
                            attendanceOccurrence.GroupId = groupId;
                        }
                        if (scheduleId != null)
                        {
                            attendanceOccurrence.ScheduleId = scheduleId;
                        }
                        if (locationId != null)
                        {
                            attendanceOccurrence.LocationId = locationId;
                        }
                        attendanceOccurrence.OccurrenceDate = occurrenceDate;
                        attendanceOccurrenceService.Add(attendanceOccurrence);
                        rockContext.SaveChanges();
                        occurrenceId = attendanceOccurrence.Id;
                    }
                }
                return(occurrenceId);
            }

            return(occurrenceId);
        }
        /// <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;
            }
        }
        /// <summary>
        /// Gets the occurrence items.
        /// </summary>
        private AttendanceOccurrence GetOccurrence()
        {
            AttendanceOccurrence occurrence = null;

            var occurrenceService = new AttendanceOccurrenceService(_rockContext);

            // Check to see if a occurrence id was specified on the query string, and if so, query for it
            int?occurrenceId = PageParameter("OccurrenceId").AsIntegerOrNull();

            if (occurrenceId.HasValue && occurrenceId.Value > 0)
            {
                occurrence = occurrenceService.Get(occurrenceId.Value);

                // If we have a valid occurrence return it now (the date,location,schedule cannot be changed for an existing occurrence)
                if (occurrence != null)
                {
                    return(occurrence);
                }
            }

            // Set occurrence values from query string
            var occurrenceDate = PageParameter("Date").AsDateTime() ?? PageParameter("Occurrence").AsDateTime();
            var locationId     = PageParameter("LocationId").AsIntegerOrNull();
            var scheduleId     = PageParameter("ScheduleId").AsIntegerOrNull();

            if (scheduleId == null)
            {
                // if no specific schedule was specified in the URL, use the group's scheduleId
                scheduleId = _group.ScheduleId;
            }

            // If this is a postback, check to see if date/location/schedule were updated
            if (Page.IsPostBack && _allowAdd)
            {
                if (dpOccurrenceDate.Visible && dpOccurrenceDate.SelectedDate.HasValue)
                {
                    occurrenceDate = dpOccurrenceDate.SelectedDate.Value;
                }

                if (ddlLocation.Visible && ddlLocation.SelectedValueAsInt().HasValue)
                {
                    locationId = ddlLocation.SelectedValueAsInt().Value;
                }

                if (ddlSchedule.Visible && ddlSchedule.SelectedValueAsInt().HasValue)
                {
                    scheduleId = ddlSchedule.SelectedValueAsInt().Value;
                }
            }

            if (occurrence == null && occurrenceDate.HasValue)
            {
                // if no specific occurrenceId was specified, try to find a matching occurrence from Date, GroupId, Location, ScheduleId
                occurrence = occurrenceService.Get(occurrenceDate.Value.Date, _group.Id, locationId, scheduleId);
            }

            // If an occurrence date was included, but no occurrence was found with that date, and new
            // occurrences can be added, create a new one
            if (occurrence == null && _allowAdd)
            {
                // Create a new occurrence record and return it
                return(new AttendanceOccurrence
                {
                    Group = _group,
                    GroupId = _group.Id,
                    OccurrenceDate = occurrenceDate ?? RockDateTime.Today.Date,
                    LocationId = locationId,
                    ScheduleId = scheduleId,
                });
            }

            return(occurrence);
        }
        /// <summary>
        /// Method to save attendance for use in two separate areas.
        /// </summary>
        protected bool SaveAttendance()
        {
            using (var rockContext = new RockContext())
            {
                var occurrenceService  = new AttendanceOccurrenceService(rockContext);
                var attendanceService  = new AttendanceService(rockContext);
                var personAliasService = new PersonAliasService(rockContext);
                var locationService    = new LocationService(rockContext);

                AttendanceOccurrence occurrence = null;

                if (_occurrence.Id != 0)
                {
                    occurrence = occurrenceService.Get(_occurrence.Id);
                }

                if (occurrence == null)
                {
                    var existingOccurrence = occurrenceService.Get(_occurrence.OccurrenceDate, _group.Id, _occurrence.LocationId, _occurrence.ScheduleId);
                    if (existingOccurrence != null)
                    {
                        nbNotice.Heading             = "Occurrence Already Exists";
                        nbNotice.Text                = "<p>An occurrence already exists for this group for the selected date, location, and schedule that you've selected. Please return to the list and select that occurrence to update it's attendance.</p>";
                        nbNotice.NotificationBoxType = NotificationBoxType.Danger;
                        nbNotice.Visible             = true;

                        return(false);
                    }
                    else
                    {
                        occurrence                = new AttendanceOccurrence();
                        occurrence.GroupId        = _occurrence.GroupId;
                        occurrence.LocationId     = _occurrence.LocationId;
                        occurrence.ScheduleId     = _occurrence.ScheduleId;
                        occurrence.OccurrenceDate = _occurrence.OccurrenceDate;
                        occurrenceService.Add(occurrence);
                    }
                }

                occurrence.Notes       = GetAttributeValue("ShowNotes").AsBoolean() ? dtNotes.Text : string.Empty;
                occurrence.DidNotOccur = cbDidNotMeet.Checked;

                var existingAttendees = occurrence.Attendees.ToList();

                // If did not meet was selected and this was a manually entered occurrence (not based on a schedule/location)
                // then just delete all the attendance records instead of tracking a 'did not meet' value
                if (cbDidNotMeet.Checked && !_occurrence.ScheduleId.HasValue)
                {
                    foreach (var attendance in existingAttendees)
                    {
                        attendanceService.Delete(attendance);
                    }
                }
                else
                {
                    int?campusId = locationService.GetCampusIdForLocation(_occurrence.LocationId) ?? _group.CampusId;
                    if (!campusId.HasValue && _allowCampusFilter)
                    {
                        var campus = CampusCache.Get(bddlCampus.SelectedValueAsInt() ?? 0);
                        if (campus != null)
                        {
                            campusId = campus.Id;
                        }
                    }

                    if (cbDidNotMeet.Checked)
                    {
                        // If the occurrence is based on a schedule, set the did not meet flags
                        foreach (var attendance in existingAttendees)
                        {
                            attendance.DidAttend = null;
                        }
                    }
                    else
                    {
                        foreach (var attendee in _attendees)
                        {
                            var attendance = existingAttendees
                                             .Where(a => a.PersonAlias.PersonId == attendee.PersonId)
                                             .FirstOrDefault();

                            if (attendance == null)
                            {
                                int?personAliasId = personAliasService.GetPrimaryAliasId(attendee.PersonId);
                                if (personAliasId.HasValue)
                                {
                                    attendance = new Attendance();
                                    attendance.PersonAliasId = personAliasId;
                                    attendance.CampusId      = campusId;
                                    attendance.StartDateTime = _occurrence.OccurrenceDate;

                                    // check that the attendance record is valid
                                    cvAttendance.IsValid = attendance.IsValid;
                                    if (!cvAttendance.IsValid)
                                    {
                                        cvAttendance.ErrorMessage = attendance.ValidationResults.Select(a => a.ErrorMessage).ToList().AsDelimited("<br />");
                                        return(false);
                                    }

                                    occurrence.Attendees.Add(attendance);
                                }
                            }

                            if (attendance != null)
                            {
                                attendance.DidAttend = attendee.Attended;
                            }
                        }
                    }
                }

                rockContext.SaveChanges();

                if (occurrence.LocationId.HasValue)
                {
                    Rock.CheckIn.KioskLocationAttendance.Remove(occurrence.LocationId.Value);
                }


                Guid?workflowTypeGuid = GetAttributeValue("Workflow").AsGuidOrNull();
                if (workflowTypeGuid.HasValue)
                {
                    var workflowType = WorkflowTypeCache.Get(workflowTypeGuid.Value);
                    if (workflowType != null && (workflowType.IsActive ?? true))
                    {
                        try
                        {
                            var workflow = Workflow.Activate(workflowType, _group.Name);

                            workflow.SetAttributeValue("StartDateTime", _occurrence.OccurrenceDate.ToString("o"));
                            workflow.SetAttributeValue("Schedule", _group.Schedule.Guid.ToString());

                            List <string> workflowErrors;
                            new WorkflowService(rockContext).Process(workflow, _group, out workflowErrors);
                        }
                        catch (Exception ex)
                        {
                            ExceptionLogService.LogException(ex, this.Context);
                        }
                    }
                }
            }

            return(true);
        }
Esempio n. 19
0
        /// <summary>
        /// Creates a new AttendanceOccurrence record.
        /// </summary>
        private bool CreateNewOccurrence()
        {
            using (var rockContext = new RockContext())
            {
                int?groupId = PageParameter(PageParameterKey.GroupId).AsIntegerOrNull();
                var group   = new GroupService(rockContext).Get(groupId.Value);

                //Create new occurrence.
                var occurrence = new AttendanceOccurrence();
                occurrence.Name    = tbOccurrenceName.Text;
                occurrence.GroupId = groupId;

                if (locpLocation.Location != null)
                {
                    occurrence.Location   = new LocationService(rockContext).Get(locpLocation.Location.Id);
                    occurrence.LocationId = occurrence.Location.Id;
                }
                else
                {
                    occurrence.Location   = null;
                    occurrence.LocationId = null;
                }

                // The schedule is OK to be null
                occurrence.ScheduleId = spSchedule.SelectedValueAsId();

                if (dpOccurrenceDate.SelectedDate.HasValue)
                {
                    occurrence.OccurrenceDate = dpOccurrenceDate.SelectedDate.Value;
                }

                var occurrenceService = new AttendanceOccurrenceService(rockContext);

                // If this occurrence has already been created, just use the existing one.
                var existingOccurrences = occurrenceService.Queryable()
                                          .Where(o => o.GroupId == occurrence.GroupId)
                                          .Where(o => o.OccurrenceDate == occurrence.OccurrenceDate)
                                          .Where(o => o.ScheduleId == occurrence.ScheduleId)
                                          .Where(o => o.LocationId == occurrence.LocationId)
                                          .ToList();

                if (existingOccurrences.Any())
                {
                    occurrence = existingOccurrences.FirstOrDefault();
                }
                else
                {
                    occurrenceService.Add(occurrence);
                }

                occurrence.DeclineConfirmationMessage = heDeclineMessage.Text;
                occurrence.AcceptConfirmationMessage  = heAcceptMessage.Text;
                occurrence.ShowDeclineReasons         = rcbShowDeclineReasons.Checked;

                var selectedDeclineReasons = new List <string>();
                foreach (ListItem listItem in rcblAvailableDeclineReasons.Items)
                {
                    if (listItem.Selected)
                    {
                        selectedDeclineReasons.Add(listItem.Value);
                    }
                }
                occurrence.DeclineReasonValueIds = selectedDeclineReasons.AsDelimited(",");

                rockContext.SaveChanges();

                occurrence = occurrenceService.Get(occurrence.Id);

                hfNewOccurrenceId.Value = occurrence.Id.ToString();
                ShowDetails(rockContext, occurrence.Id, group);
                return(true);
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Save RSVP response data from grid (to Attendance records).
        /// </summary>
        protected bool SaveRSVPData()
        {
            var attendees = new List <RSVPAttendee>();

            foreach (GridViewRow row in gAttendees.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    RockCheckBox     rcbAccept         = row.FindControl("rcbAccept") as RockCheckBox;
                    RockCheckBox     rcbDecline        = row.FindControl("rcbDecline") as RockCheckBox;
                    DataDropDownList rddlDeclineReason = row.FindControl("rddlDeclineReason") as DataDropDownList;
                    RockTextBox      tbDeclineNote     = row.FindControl("tbDeclineNote") as RockTextBox;
                    int    declineReason = int.Parse(rddlDeclineReason.SelectedValue);
                    string declineNote   = tbDeclineNote.Text;

                    attendees.Add(
                        new RSVPAttendee()
                    {
                        Accept        = rcbAccept.Checked,
                        Decline       = rcbDecline.Checked,
                        DeclineNote   = declineNote,
                        DeclineReason = declineReason,
                        PersonId      = ( int )gAttendees.DataKeys[row.RowIndex].Value
                    }
                        );
                }
            }
            using (var rockContext = new RockContext())
            {
                var occurrenceService  = new AttendanceOccurrenceService(rockContext);
                var attendanceService  = new AttendanceService(rockContext);
                var personAliasService = new PersonAliasService(rockContext);

                AttendanceOccurrence occurrence = null;

                int?groupId      = PageParameter(PageParameterKey.GroupId).AsIntegerOrNull();
                int?occurrenceId = PageParameter(PageParameterKey.OccurrenceId).AsIntegerOrNull();

                if ((occurrenceId == null) || (occurrenceId == 0))
                {
                    occurrenceId = hfNewOccurrenceId.Value.AsIntegerOrNull();
                    if ((occurrenceId == null) || (occurrenceId == 0))
                    {
                        throw new Exception("The AttendanceOccurrence does not exist.");
                    }
                }

                occurrence = occurrenceService.Get(occurrenceId.Value);

                var existingAttendees = occurrence.Attendees.ToList();

                foreach (var attendee in attendees)
                {
                    var attendance = existingAttendees
                                     .Where(a => a.PersonAlias.PersonId == attendee.PersonId)
                                     .FirstOrDefault();

                    if (attendance == null)
                    {
                        int?personAliasId = personAliasService.GetPrimaryAliasId(attendee.PersonId);
                        if (personAliasId.HasValue)
                        {
                            attendance = new Attendance();
                            attendance.PersonAliasId = personAliasId;
                            attendance.StartDateTime = occurrence.Schedule != null && occurrence.Schedule.HasSchedule() ? occurrence.OccurrenceDate.Date.Add(occurrence.Schedule.StartTimeOfDay) : occurrence.OccurrenceDate;
                            occurrence.Attendees.Add(attendance);
                        }
                    }

                    if (attendance != null)
                    {
                        if (attendee.Accept)
                        {
                            var groupMember = occurrence.Group.Members.Where(gm => gm.PersonId == attendee.PersonId).FirstOrDefault();
                            if (groupMember == null)
                            {
                                groupMember             = new GroupMember();
                                groupMember.PersonId    = attendee.PersonId;
                                groupMember.GroupId     = occurrence.Group.Id;
                                groupMember.GroupRoleId = occurrence.Group.GroupType.DefaultGroupRoleId ?? 0;

                                new GroupMemberService(rockContext).Add(groupMember);
                                rockContext.SaveChanges();
                            }

                            // only set the RSVP and Date if the value is changing
                            if (attendance.RSVP != Rock.Model.RSVP.Yes)
                            {
                                attendance.RSVPDateTime = DateTime.Now;
                                attendance.RSVP         = Rock.Model.RSVP.Yes;
                            }
                            attendance.Note = string.Empty;
                            attendance.DeclineReasonValueId = null;
                        }
                        else if (attendee.Decline)
                        {
                            // only set the RSVP and Date if the value is changing
                            if (attendance.RSVP != Rock.Model.RSVP.No)
                            {
                                attendance.RSVPDateTime = DateTime.Now;
                                attendance.RSVP         = Rock.Model.RSVP.No;
                            }

                            attendance.Note = attendee.DeclineNote;
                            if (attendee.DeclineReason != 0)
                            {
                                attendance.DeclineReasonValueId = attendee.DeclineReason;
                            }
                        }
                        else
                        {
                            attendance.RSVPDateTime         = null;
                            attendance.RSVP                 = Rock.Model.RSVP.Unknown;
                            attendance.Note                 = string.Empty;
                            attendance.DeclineReasonValueId = null;
                        }
                    }
                }

                rockContext.SaveChanges();

                if (occurrence.LocationId.HasValue)
                {
                    Rock.CheckIn.KioskLocationAttendance.Remove(occurrence.LocationId.Value);
                }
            }

            return(true);
        }
Esempio n. 21
0
        public static void SyncEvent(
            int groupid,
            bool updatePrimaryEmail = false,
            string userid           = "Eventbrite",
            int recordStatusId      = 5,
            int connectionStatusId  = 66,
            bool EnableLogging      = false,
            bool ThrottleSync       = false)
        {
            //Setup
            var rockContext = new RockContext();

            if (EnableLogging)
            {
                LogEvent(rockContext, "SyncEvent", string.Format("GroupId:{0}", groupid), "Started");
            }

            var group = new GroupService(rockContext).Get(groupid);
            var eb    = new EBApi(Settings.GetAccessToken(), Settings.GetOrganizationId().ToLong(0));
            var groupEBEventIDAttr    = GetGroupEBEventId(group);
            var groupEBEventAttrSplit = groupEBEventIDAttr.Value.SplitDelimitedValues("^");
            var evntid = long.Parse(groupEBEventIDAttr != null ? groupEBEventAttrSplit[0] : "0");

            if (ThrottleSync && groupEBEventAttrSplit.Length > 1 && groupEBEventAttrSplit[1].AsDateTime() > RockDateTime.Now.Date.AddMinutes(-30))
            {
                return;
            }

            if (EnableLogging)
            {
                LogEvent(rockContext, "SyncEvent", string.Format("Group: {0}", group), "Got Group and EBEventId from Group.");
            }

            var ebOrders             = new List <Order>();
            var ebEvent              = eb.GetEventById(evntid);
            var IsRSVPEvent          = ebEvent.IsRSVPEvent(eb);
            var gmPersonAttributeKey = GetPersonAttributeKey(rockContext, group);

            if (EnableLogging)
            {
                LogEvent(rockContext, "SyncEvent", string.Format("eb.GetEventById({0})", evntid), "eb.GetEventById and get Person Attribute Key");
            }

            //Get Eventbrite Attendees
            var ebOrderGet = eb.GetExpandedOrdersById(evntid);

            ebOrders.AddRange(ebOrderGet.Orders);
            if (ebOrderGet.Pagination.PageCount > 1)
            {
                var looper = new EventOrders();
                for (int i = 2; i <= ebOrderGet.Pagination.PageCount; i++)
                {
                    looper = eb.GetExpandedOrdersById(evntid, i);
                    ebOrders.AddRange(looper.Orders);
                }
            }

            if (EnableLogging)
            {
                LogEvent(rockContext, "SyncEvent", string.Format("GetExpandedOrdersById:{0}", evntid), string.Format("Result count: {0}", ebOrders.Count));
            }

            var groupMemberService = new GroupMemberService(rockContext);
            var personAliasService = new PersonAliasService(rockContext);

            AttendanceOccurrence occ = GetOrAddOccurrence(rockContext, group, ebEvent);

            if (EnableLogging)
            {
                LogEvent(rockContext, "SyncEvent", string.Format("GroupId: {0} Evntid: {1}", groupid, evntid), "Begin For each order in ebOrders");
            }
            foreach (var order in ebOrders)
            {
                foreach (var attendee in order.Attendees)
                {
                    HttpContext.Current.Server.ScriptTimeout = HttpContext.Current.Server.ScriptTimeout + 2;
                    SyncAttendee(rockContext, attendee, order, group, groupMemberService, personAliasService, occ, evntid, IsRSVPEvent, gmPersonAttributeKey, updatePrimaryEmail, recordStatusId, connectionStatusId, EnableLogging);
                }
            }

            if (EnableLogging)
            {
                LogEvent(rockContext, "SyncEvent", string.Format("End Sync for Group: {0}", groupid), "End Sync and Write SyncTime to Group");
            }
            rockContext.SaveChanges();

            // Write the Sync Time
            group.SetAttributeValue(groupEBEventIDAttr.AttributeKey, string.Format("{0}^{1}", groupEBEventIDAttr.Value.SplitDelimitedValues("^")[0], RockDateTime.Now.ToString("g", CultureInfo.CreateSpecificCulture("en-us"))));
            group.SaveAttributeValue(groupEBEventIDAttr.AttributeKey, rockContext);
        }
Esempio n. 22
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="occurrence"></param>
 public GroupOccurrenceResponse(AttendanceOccurrence occurrence)
 {
     Occurrence = occurrence;
     GetOccurrenceTitle();
 }
Esempio n. 23
0
        private static void SyncAttendee(RockContext rockContext, Attendee attendee, Order order, Group group, GroupMemberService groupMemberService, PersonAliasService personAliasService, AttendanceOccurrence occ, long evntid, bool IsRSVPEvent, string gmPersonAttributeKey, bool updatePrimaryEmail, int recordStatusId = 5, int connectionStatusId = 66, bool EnableLogging = false)
        {
            if (string.IsNullOrWhiteSpace(attendee.Profile.Email))
            {
                attendee.Profile.Email = order.Email;
            }

            if (!string.IsNullOrWhiteSpace(attendee.Profile.First_Name) && !string.IsNullOrWhiteSpace(attendee.Profile.Last_Name) && !string.IsNullOrWhiteSpace(attendee.Profile.Email))
            {
                var person             = MatchOrAddPerson(rockContext, attendee.Profile, connectionStatusId, updatePrimaryEmail, EnableLogging);
                var matchedGroupMember = MatchGroupMember(group.Members, order, person.Id, gmPersonAttributeKey, rockContext, EnableLogging);
                if (matchedGroupMember == null && (order.Status != "deleted" || order.Status != "abandoned"))
                {
                    var member = new GroupMember
                    {
                        GroupId           = group.Id,
                        Person            = person,
                        GuestCount        = (order.Attendees != null) ? order.Attendees.Count : 1,
                        GroupRoleId       = group.GroupType.DefaultGroupRoleId.Value,
                        GroupMemberStatus = GroupMemberStatus.Active
                    };

                    groupMemberService.Add(member);

                    SetPersonData(rockContext, person, attendee, group, IsRSVPEvent && order.Attendees != null ? order.Attendees.Count : attendee.Quantity, EnableLogging);
                }
                else if (matchedGroupMember != null && order.Status == "deleted")
                {
                    matchedGroupMember.GroupMemberStatus = GroupMemberStatus.Inactive;
                    matchedGroupMember.Note = "Eventbrite order deleted!";

                    groupMemberService.Delete(matchedGroupMember);
                }
                else if (matchedGroupMember != null && order.Status == "refunded")
                {
                    matchedGroupMember.GroupMemberStatus = GroupMemberStatus.Inactive;
                    matchedGroupMember.Note = "Eventbrite order canceled/refunded!";
                }
                else if (matchedGroupMember != null)
                {
                    if (matchedGroupMember.Attributes == null)
                    {
                        matchedGroupMember.LoadAttributes(rockContext);
                    }
                    var attributeVal = matchedGroupMember.GetAttributeValue(gmPersonAttributeKey);
                    if (attributeVal.IsNotNullOrWhiteSpace())
                    {
                        // Attribute Values in our special eventBritePerson field type are stored as a delimited string Eventbrite Id^Ticket Class(es)^Eventbrite Order Id^RSVP/Ticket Count(s)
                        var splitVal      = attributeVal.SplitDelimitedValues("^");
                        var ticketClasses = splitVal[1].SplitDelimitedValues("||");
                        var ticketQtys    = splitVal[3].SplitDelimitedValues("||");
                        if (!ticketClasses.Contains(attendee.Ticket_Class_Name))
                        {
                            splitVal[1] += "||" + attendee.Ticket_Class_Name;
                            splitVal[3] += "||" + order.Attendees?.Count(a => a.Profile.First_Name == attendee.Profile.First_Name && a.Profile.Last_Name == attendee.Profile.Last_Name && a.Profile.Email == attendee.Profile.Email && a.Ticket_Class_Id == attendee.Ticket_Class_Id).ToString();
                        }
                        else
                        {
                            ticketQtys[Array.IndexOf(ticketClasses, attendee.Ticket_Class_Name)] = order.Attendees?.Count(a => a.Profile.First_Name == attendee.Profile.First_Name && a.Profile.Last_Name == attendee.Profile.Last_Name && a.Profile.Email == attendee.Profile.Email && a.Ticket_Class_Id == attendee.Ticket_Class_Id).ToString();
                            splitVal[3] = ticketQtys.JoinStrings("||");
                        }
                        matchedGroupMember.SetAttributeValue(gmPersonAttributeKey, splitVal.JoinStrings("^"));
                        matchedGroupMember.SaveAttributeValue(gmPersonAttributeKey);
                    }
                }

                //Record Attendance
                if (attendee.Checked_In)
                {
                    if (EnableLogging)
                    {
                        LogEvent(rockContext, "SyncAttendee", string.Format("Attendee.Checked_in", evntid), "True");
                    }

                    var attendance = occ.Attendees
                                     .Where(a => a.PersonAlias != null && a.PersonAlias.PersonId == person.Id)
                                     .FirstOrDefault();

                    if (attendance == null)
                    {
                        int?personAliasId = personAliasService.GetPrimaryAliasId(person.Id);
                        if (personAliasId.HasValue)
                        {
                            attendance = new Attendance
                            {
                                PersonAliasId = personAliasId,
                                StartDateTime = occ.Schedule != null && occ.Schedule.HasSchedule() ? occ.OccurrenceDate.Date.Add(occ.Schedule.StartTimeOfDay) : occ.OccurrenceDate,
                                DidAttend     = true
                            };

                            occ.Attendees.Add(attendance);
                        }
                    }
                    else
                    {
                        // Otherwise, only record that they attended -- don't change their attendance startDateTime
                        attendance.DidAttend = true;
                    }
                    rockContext.SaveChanges();
                }
            }
        }