예제 #1
0
        /// <summary>
        /// Gets the attendee data (for use in the grid and chart).
        /// </summary>
        /// <param name="rockContext">The RockContext</param>
        /// <returns>A list of <see cref="RSVPAttendee"/> objects representing the attendees of an occurrence.</returns>
        private List <RSVPAttendee> GetAttendees(RockContext rockContext)
        {
            List <RSVPAttendee> attendees = new List <RSVPAttendee>();
            List <int>          existingAttendanceRecords = new List <int>();

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

            if ((occurrenceId != null) && (occurrenceId != 0))
            {
                // Add RSVP responses for anyone who has an attendance record, already.
                var occurrenceService = new AttendanceOccurrenceService(rockContext);
                var occurrence        = occurrenceService.Get(occurrenceId.Value);
                var sortedAttendees   = occurrence.Attendees.OrderBy(a => a.PersonAlias.Person.LastName).ThenBy(a => a.PersonAlias.Person.FirstName);
                foreach (var attendee in sortedAttendees)
                {
                    RSVPAttendee rsvp = new RSVPAttendee();
                    rsvp.PersonId      = attendee.PersonAlias.PersonId;
                    rsvp.NickName      = attendee.PersonAlias.Person.NickName;
                    rsvp.LastName      = attendee.PersonAlias.Person.LastName;
                    rsvp.Accept        = (attendee.RSVP == Rock.Model.RSVP.Yes);
                    rsvp.Decline       = (attendee.RSVP == Rock.Model.RSVP.No);
                    rsvp.DeclineReason = attendee.DeclineReasonValueId;
                    rsvp.DeclineNote   = attendee.Note;
                    attendees.Add(rsvp);
                    existingAttendanceRecords.Add(attendee.PersonAlias.PersonId);
                }
            }

            return(attendees);
        }
예제 #2
0
        /// <summary>
        /// Gets the attendee data (for use in the grid and chart).
        /// </summary>
        /// <param name="rockContext">The RockContext</param>
        /// <returns>A list of <see cref="RSVPAttendee"/> objects representing the attendees of an occurrence.</returns>
        private List <RSVPAttendee> GetAttendees(RockContext rockContext)
        {
            List <RSVPAttendee> result = new List <RSVPAttendee>();
            List <int>          existingAttendanceRecords = new List <int>();

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

            if ((occurrenceId != null) && (occurrenceId != 0))
            {
                // Add RSVP responses for anyone who has an attendance record, already.
                var occurrenceService = new AttendanceOccurrenceService(rockContext);
                var occurrence        = occurrenceService.Get(occurrenceId.Value);
                var attendees         = occurrence.Attendees.AsEnumerable();

                var rsvpStatus = new List <Rock.Model.RSVP>();

                foreach (string selectedStatuses in cblStatus.SelectedValues)
                {
                    var status = selectedStatuses.ConvertToEnum <Statuses>();

                    switch (status)
                    {
                    case Statuses.Accept:
                        rsvpStatus.Add(Rock.Model.RSVP.Yes);
                        break;

                    case Statuses.Decline:
                        rsvpStatus.Add(Rock.Model.RSVP.No);
                        break;

                    case Statuses.NoResponse:
                        rsvpStatus.Add(Rock.Model.RSVP.Unknown);
                        break;
                    }
                }

                if (rsvpStatus.Any())
                {
                    attendees = attendees.Where(a => rsvpStatus.Contains(a.RSVP));
                }

                var declineReasonValueIds = cblDeclineReason.SelectedValuesAsInt;
                if (declineReasonValueIds.Any())
                {
                    attendees = attendees.Where(a => a.DeclineReasonValueId.HasValue && declineReasonValueIds.Contains(a.DeclineReasonValueId.Value));
                }

                var sortedAttendees = attendees.OrderBy(a => a.PersonAlias.Person.LastName).ThenBy(a => a.PersonAlias.Person.FirstName);
                foreach (var attendee in sortedAttendees)
                {
                    RSVPAttendee rsvp = new RSVPAttendee();
                    rsvp.PersonId      = attendee.PersonAlias.PersonId;
                    rsvp.NickName      = attendee.PersonAlias.Person.NickName;
                    rsvp.LastName      = attendee.PersonAlias.Person.LastName;
                    rsvp.Accept        = (attendee.RSVP == Rock.Model.RSVP.Yes);
                    rsvp.Decline       = (attendee.RSVP == Rock.Model.RSVP.No);
                    rsvp.DeclineReason = attendee.DeclineReasonValueId;
                    rsvp.DeclineNote   = attendee.Note;
                    rsvp.RSVPDateTime  = attendee.RSVPDateTime;
                    result.Add(rsvp);
                    existingAttendanceRecords.Add(attendee.PersonAlias.PersonId);
                }
            }

            return(result);
        }
예제 #3
0
        public async Task <ActionResult> Rsvp(RsvpViewModel model)
        {
            if (!string.IsNullOrWhiteSpace(model.Website) || model.CaptchaPass == null || model.CaptchaPass != "KALASHIAN_NOT_ROBOT")
            {
                return(Json(new { status = 0, error = "Only humans can submit this form." }));
            }

            using (NickBeckyWedding db = new NickBeckyWedding())
                using (DbContextTransaction dbTrans = db.Database.BeginTransaction())
                {
                    RSVP rsvp = new RSVP
                    {
                        ArrivalDate  = model.ArrivalDate,
                        PrimaryEmail = model.EmailAddress,
                        Attending    = model.Attending
                    };

                    db.RSVPs.Add(rsvp);

                    try
                    {
                        await db.SaveChangesAsync();
                    }
                    catch (Exception ex)
                    {
                        dbTrans.Rollback();

                        return(Json(new { status = 0, error = ex.Message }));
                    }

                    RSVPAttendee primeAttendee = new RSVPAttendee
                    {
                        EmailAddress = model.EmailAddress,
                        Name         = model.Name,
                        RSVP_ID      = rsvp.ID
                    };

                    db.RSVPAttendees.Add(primeAttendee);

                    foreach (RSVPAttendee dbAttendee in model.Attendees.Where(attendee => attendee.EmailAddress != null).Select(attendee => new RSVPAttendee
                    {
                        EmailAddress = attendee.EmailAddress,
                        Name = attendee.Name,
                        RSVP_ID = rsvp.ID
                    }))
                    {
                        db.RSVPAttendees.Add(dbAttendee);
                    }

                    try
                    {
                        await db.SaveChangesAsync();

                        dbTrans.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbTrans.Rollback();

                        return(Json(new { status = 0, error = ex.Message }));
                    }

                    await SendRsvpEmailAsync(model);
                }

            return(Json(new { status = 1 }));
        }