Exemple #1
0
        private void SelectArea(Guid?groupTypeGuid)
        {
            hfIsDirty.Value = "false";

            checkinArea.Visible  = false;
            checkinGroup.Visible = false;
            btnSave.Visible      = false;
            btnDelete.Visible    = false;

            if (groupTypeGuid.HasValue)
            {
                using (var rockContext = new RockContext())
                {
                    var groupTypeService = new GroupTypeService(rockContext);
                    var groupType        = groupTypeService.Get(groupTypeGuid.Value);
                    if (groupType != null)
                    {
                        _currentGroupTypeGuid = groupType.Guid;

                        checkinArea.SetGroupType(groupType, rockContext);
                        checkinArea.CheckinLabels = new List <CheckinArea.CheckinLabelAttributeInfo>();

                        groupType.LoadAttributes(rockContext);
                        List <string> labelAttributeKeys = CheckinArea.GetCheckinLabelAttributes(groupType.Attributes)
                                                           .OrderBy(a => a.Value.Order)
                                                           .Select(a => a.Key).ToList();
                        BinaryFileService binaryFileService = new BinaryFileService(rockContext);

                        foreach (string key in labelAttributeKeys)
                        {
                            var  attributeValue = groupType.GetAttributeValue(key);
                            Guid binaryFileGuid = attributeValue.AsGuid();
                            var  fileName       = binaryFileService.Queryable().Where(a => a.Guid == binaryFileGuid).Select(a => a.FileName).FirstOrDefault();
                            if (fileName != null)
                            {
                                checkinArea.CheckinLabels.Add(new CheckinArea.CheckinLabelAttributeInfo {
                                    AttributeKey = key, BinaryFileGuid = binaryFileGuid, FileName = fileName
                                });
                            }
                        }

                        checkinArea.Visible             = true;
                        btnSave.Visible                 = true;
                        btnDelete.Visible               = true;
                        btnDelete.Attributes["onclick"] = string.Format("javascript: return Rock.dialogs.confirmDelete(event, '{0}', '{1}');", "check-in area", "This action cannot be undone.");
                    }
                    else
                    {
                        _currentGroupTypeGuid = null;
                    }
                }
            }
            else
            {
                _currentGroupTypeGuid = null;
            }

            BuildRows();
        }
 /// <summary>
 /// Used to draw checkin area
 /// </summary>
 public static void CheckinArea(int y, CheckinArea checkinArea)
 {
     ConsoleEx.SetPosition(0, y);
     foreach (Counter c in checkinArea.Counters)
     {
         ConsoleEx.WriteLine($"\f{c.Id+1:X}█ \f7{c}");
     }
 }
        private void SelectArea(Guid?groupTypeGuid)
        {
            hfIsDirty.Value = "false";

            checkinArea.Visible  = false;
            checkinGroup.Visible = false;
            btnSave.Visible      = false;

            if (groupTypeGuid.HasValue)
            {
                using (var rockContext = new RockContext())
                {
                    var groupTypeService = new GroupTypeService(rockContext);
                    var groupType        = groupTypeService.Get(groupTypeGuid.Value);
                    if (groupType != null)
                    {
                        _currentGroupTypeGuid = groupType.Guid;

                        checkinArea.SetGroupType(groupType);
                        checkinArea.CheckinLabels = new List <CheckinArea.CheckinLabelAttributeInfo>();

                        groupType.LoadAttributes(rockContext);
                        List <string> labelAttributeKeys = CheckinArea.GetCheckinLabelAttributes(groupType.Attributes)
                                                           .OrderBy(a => a.Value.Order)
                                                           .Select(a => a.Key).ToList();
                        BinaryFileService binaryFileService = new BinaryFileService(rockContext);

                        foreach (string key in labelAttributeKeys)
                        {
                            var  attributeValue = groupType.GetAttributeValue(key);
                            Guid binaryFileGuid = attributeValue.AsGuid();
                            var  fileName       = binaryFileService.Queryable().Where(a => a.Guid == binaryFileGuid).Select(a => a.FileName).FirstOrDefault();
                            if (fileName != null)
                            {
                                checkinArea.CheckinLabels.Add(new CheckinArea.CheckinLabelAttributeInfo {
                                    AttributeKey = key, BinaryFileGuid = binaryFileGuid, FileName = fileName
                                });
                            }
                        }

                        checkinArea.Visible = true;
                        btnSave.Visible     = true;
                    }
                    else
                    {
                        _currentGroupTypeGuid = null;
                    }
                }
            }
            else
            {
                _currentGroupTypeGuid = null;
            }

            BuildRows();
        }
Exemple #4
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            hfAreaGroupClicked.Value = "true";

            using (var rockContext = new RockContext())
            {
                var attributeService = new AttributeService(rockContext);

                if (checkinArea.Visible)
                {
                    var groupTypeService = new GroupTypeService(rockContext);
                    var groupType        = groupTypeService.Get(checkinArea.GroupTypeGuid);
                    if (groupType != null)
                    {
                        groupType.LoadAttributes(rockContext);
                        checkinArea.GetGroupTypeValues(groupType);

                        if (groupType.IsValid)
                        {
                            rockContext.SaveChanges();
                            groupType.SaveAttributeValues(rockContext);

                            // rebuild the CheckinLabel attributes from the UI (brute-force)
                            foreach (var labelAttribute in CheckinArea.GetCheckinLabelAttributes(groupType.Attributes))
                            {
                                var attribute = attributeService.Get(labelAttribute.Value.Guid);
                                attributeService.Delete(attribute);
                            }

                            // Make sure default role is set
                            if (!groupType.DefaultGroupRoleId.HasValue && groupType.Roles.Any())
                            {
                                groupType.DefaultGroupRoleId = groupType.Roles.First().Id;
                            }

                            rockContext.SaveChanges();

                            int labelOrder            = 0;
                            int binaryFileFieldTypeID = FieldTypeCache.Get(Rock.SystemGuid.FieldType.LABEL.AsGuid()).Id;
                            foreach (var checkinLabelAttributeInfo in checkinArea.CheckinLabels)
                            {
                                var attribute = new Rock.Model.Attribute();
                                attribute.AttributeQualifiers.Add(new AttributeQualifier {
                                    Key = "binaryFileType", Value = Rock.SystemGuid.BinaryFiletype.CHECKIN_LABEL
                                });
                                attribute.Guid         = Guid.NewGuid();
                                attribute.FieldTypeId  = binaryFileFieldTypeID;
                                attribute.EntityTypeId = EntityTypeCache.GetId(typeof(GroupType));
                                attribute.EntityTypeQualifierColumn = "Id";
                                attribute.EntityTypeQualifierValue  = groupType.Id.ToString();
                                attribute.DefaultValue = checkinLabelAttributeInfo.BinaryFileGuid.ToString();
                                attribute.Key          = checkinLabelAttributeInfo.AttributeKey;
                                attribute.Name         = checkinLabelAttributeInfo.FileName;
                                attribute.Order        = labelOrder++;

                                if (!attribute.IsValid)
                                {
                                    return;
                                }

                                attributeService.Add(attribute);
                            }

                            rockContext.SaveChanges();

                            Rock.CheckIn.KioskDevice.Clear();

                            nbSaveSuccess.Visible = true;
                            BuildRows();
                        }
                        else
                        {
                            ShowInvalidResults(groupType.ValidationResults);
                        }
                    }
                }

                if (checkinGroup.Visible)
                {
                    var groupService         = new GroupService(rockContext);
                    var groupLocationService = new GroupLocationService(rockContext);

                    var group = groupService.Get(checkinGroup.GroupGuid);
                    if (group != null)
                    {
                        group.LoadAttributes(rockContext);
                        checkinGroup.GetGroupValues(group);

                        // populate groupLocations with whatever is currently in the grid, with just enough info to repopulate it and save it later
                        var newLocationIds = checkinGroup.Locations.Select(l => l.LocationId).ToList();
                        foreach (var groupLocation in group.GroupLocations.Where(l => !newLocationIds.Contains(l.LocationId)).ToList())
                        {
                            groupLocation.GroupLocationScheduleConfigs.Clear();

                            groupLocationService.Delete(groupLocation);
                            group.GroupLocations.Remove(groupLocation);
                        }

                        var existingLocationIds = group.GroupLocations.Select(g => g.LocationId).ToList();
                        foreach (var item in checkinGroup.Locations.Where(l => !existingLocationIds.Contains(l.LocationId)).ToList())
                        {
                            var groupLocation = new GroupLocation();
                            groupLocation.LocationId = item.LocationId;
                            group.GroupLocations.Add(groupLocation);
                        }

                        // Set the new order
                        foreach (var item in checkinGroup.Locations.OrderBy(l => l.Order).ToList())
                        {
                            var groupLocation = group.GroupLocations.FirstOrDefault(gl => gl.LocationId == item.LocationId);
                            groupLocation.Order = item.Order ?? 0;
                        }

                        if (group.IsValid)
                        {
                            rockContext.SaveChanges();
                            group.SaveAttributeValues(rockContext);

                            Rock.CheckIn.KioskDevice.Clear();
                            nbSaveSuccess.Visible = true;
                            BuildRows();
                        }
                        else
                        {
                            ShowInvalidResults(group.ValidationResults);
                        }
                    }
                }
            }

            hfIsDirty.Value = "false";
        }