Пример #1
0
        public LocationScheduleCount GetLocationScheduleCount(int LocationId, int ScheduleId)
        {
            var locationScheduleCount = new LocationScheduleCount();
            var lglsc = CheckInCountCache.GetByLocation(LocationId).Where(glsc => glsc.ScheduleId == ScheduleId).ToList();

            locationScheduleCount.ChildCount = lglsc.Where(glsc => ChildGroupIds.Contains(glsc.GroupId))
                                               .Select(glsc => glsc.PersonIds.Count).Sum();

            locationScheduleCount.VolunteerCount = lglsc.Where(glsc => VolunteerGroupIds.Contains(glsc.GroupId))
                                                   .Select(glsc => glsc.PersonIds.Count).Sum();

            locationScheduleCount.ReservedCount = 0;

            locationScheduleCount.TotalCount = lglsc.Select(glsc => glsc.PersonIds.Count).Sum();

            return(locationScheduleCount);
        }
Пример #2
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, WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            var checkInState = GetCheckInState(entity, out errorMessages);

            if (checkInState != null)
            {
                List <string> labelCodes = new List <string>();

                var volAttributeGuid = GetAttributeValue(action, "VolunteerGroupAttribute").AsGuid();
                var volAttribute     = AttributeCache.Read(volAttributeGuid);

                List <int> ChildGroupIds;

                if (volAttribute != null)
                {
                    AttributeValueService attributeValueService = new AttributeValueService(rockContext);
                    ChildGroupIds = attributeValueService.Queryable().Where(av => av.AttributeId == volAttribute.Id && av.Value == "False").Select(av => av.EntityId.Value).ToList();
                }
                else
                {
                    ChildGroupIds = new List <int>();
                }


                var globalAttributes  = Rock.Web.Cache.GlobalAttributesCache.Read(rockContext);
                var globalMergeValues = Rock.Lava.LavaHelper.GetCommonMergeFields(null);

                var groupMemberService = new GroupMemberService(rockContext);

                AttendanceService attendanceService = new AttendanceService(rockContext);

                foreach (var family in checkInState.CheckIn.Families.Where(f => f.Selected))
                {
                    foreach (var person in family.People)
                    {
                        var attendances = attendanceService.Queryable("AttendanceCode")
                                          .Where(a => a.CreatedDateTime >= Rock.RockDateTime.Today &&
                                                 person.Person.Id == a.PersonAlias.PersonId &&
                                                 ChildGroupIds.Contains(a.GroupId ?? 0) &&
                                                 a.AttendanceCode != null)
                                          .DistinctBy(a => a.AttendanceCodeId).ToList();
                        foreach (var attendance in attendances)
                        {
                            if (attendance != null && attendance.AttendanceCode != null)
                            {
                                labelCodes.Add(attendance.AttendanceCode.Code + "-" + LabelAge(person.Person));
                            }
                        }
                    }

                    //Add in custom labels for parents
                    //This is the aggregate part
                    List <CheckInLabel> customLabels = new List <CheckInLabel>();

                    List <string> mergeCodes = (( string )GetAttributeValue(action, "MergeText")).Split(',').ToList();
                    while (labelCodes.Count > 0)
                    {
                        var mergeDict = new Dictionary <string, string>();

                        foreach (var mergeCode in mergeCodes)
                        {
                            if (labelCodes.Count > 0)
                            {
                                mergeDict.Add(mergeCode, labelCodes[0]);
                                labelCodes.RemoveAt(0);
                            }
                            else
                            {
                                mergeDict.Add(mergeCode, "");
                            }
                        }

                        var labelCache = KioskLabel.Read(new Guid(GetAttributeValue(action, "AggregatedLabel")));
                        if (labelCache != null)
                        {
                            var checkInLabel = new CheckInLabel(labelCache, new Dictionary <string, object>());
                            checkInLabel.FileGuid = new Guid(GetAttributeValue(action, "AggregatedLabel"));

                            foreach (var keyValue in mergeDict)
                            {
                                if (checkInLabel.MergeFields.ContainsKey(keyValue.Key))
                                {
                                    checkInLabel.MergeFields[keyValue.Key] = keyValue.Value;
                                }
                                else
                                {
                                    checkInLabel.MergeFields.Add(keyValue.Key, keyValue.Value);
                                }
                            }

                            checkInLabel.MergeFields.Add("Date", Rock.RockDateTime.Today.DayOfWeek.ToString().Substring(0, 3) + " " + Rock.RockDateTime.Today.ToMonthDayString());

                            checkInLabel.PrintFrom = checkInState.Kiosk.Device.PrintFrom;
                            checkInLabel.PrintTo   = checkInState.Kiosk.Device.PrintToOverride;

                            if (checkInLabel.PrintTo == PrintTo.Kiosk)
                            {
                                var device = checkInState.Kiosk.Device;
                                if (device != null)
                                {
                                    checkInLabel.PrinterDeviceId = device.PrinterDeviceId;
                                }
                            }

                            if (checkInLabel.PrinterDeviceId.HasValue)
                            {
                                var printerDevice = new DeviceService(rockContext).Get(checkInLabel.PrinterDeviceId.Value);
                                checkInLabel.PrinterAddress = printerDevice.IPAddress;
                            }
                            var firstPerson = family.People.Where(p => p.GroupTypes.Any()).FirstOrDefault();
                            if (firstPerson != null)
                            {
                                //we have to set as selected or it wil not print
                                firstPerson.Selected = true;
                                var firstGroupType = firstPerson.GroupTypes.FirstOrDefault();
                                firstGroupType.Selected = true;
                                if (firstGroupType.Labels == null)
                                {
                                    firstGroupType.Labels = new List <CheckInLabel>()
                                    {
                                        checkInLabel
                                    };
                                }
                                else
                                {
                                    firstGroupType.Labels.Add(checkInLabel);
                                }
                            }
                        }
                    }
                }

                return(true);
            }

            return(false);
        }