示例#1
0
        protected void gKioskType_Delete(object sender, RowEventArgs e)
        {
            var checkinContext = new RockContext();
            KioskTypeService KioskTypeService = new KioskTypeService(checkinContext);
            KioskType        KioskType        = KioskTypeService.Get(e.RowKeyId);

            if (KioskType != null)
            {
                int kosktypeId = KioskType.Id;

                string errorMessage;
                if (!KioskTypeService.CanDelete(KioskType, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                KioskTypeService.Delete(KioskType);
                checkinContext.SaveChanges();

                KioskTypeCache.Clear();
                KioskDeviceHelpers.Clear();
            }

            BindGrid();
        }
示例#2
0
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap = context.JobDetail.JobDataMap;

            var rockContext = new RockContext();

            var definedTypeService   = new DefinedTypeService(rockContext);
            var definedValueService  = new DefinedValueService(rockContext);
            var dtDeactivated        = definedTypeService.Get(Constants.DEFINED_TYPE_DISABLED_GROUPLOCATIONSCHEDULES.AsGuid());
            var dvDeactivated        = dtDeactivated.DefinedValues.ToList();
            var scheduleService      = new ScheduleService(rockContext);
            var groupLocationService = new GroupLocationService(rockContext);
            var deactivatedGroupLocationSchedules = dvDeactivated.Select(dv => dv.Value.Split('|'))
                                                    .Select(s => new
            {
                GroupLocation = groupLocationService.Get(s[0].AsInteger()),
                Schedule      = scheduleService.Get(s[1].AsInteger()),
            }).ToList();

            //add schedules back
            foreach (var groupLocationSchedule in deactivatedGroupLocationSchedules)
            {
                if (!groupLocationSchedule.GroupLocation.Schedules.Contains(groupLocationSchedule.Schedule))
                {
                    groupLocationSchedule.GroupLocation.Schedules.Add(groupLocationSchedule.Schedule);
                }
            }
            //Remove defined values
            foreach (var value in dvDeactivated)
            {
                definedValueService.Delete(value);
                Rock.Web.Cache.DefinedValueCache.Remove(value.Id);
            }

            //clear defined type cache
            Rock.Web.Cache.DefinedTypeCache.Remove(dtDeactivated.Id);

            rockContext.SaveChanges();

            //clear caches
            KioskTypeCache.Clear();
            KioskDeviceHelpers.Clear();
            OccurrenceCache.Clear();
            AttendanceCache.Clear();

            context.Result = string.Format("Finished at {0}. Reset {1} GroupScheduleLocations.", Rock.RockDateTime.Now, deactivatedGroupLocationSchedules.Count);
        }
示例#3
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            KioskType kioskType = null;

            var rockContext      = new RockContext();
            var kioskTypeService = new KioskTypeService(rockContext);
            var attributeService = new AttributeService(rockContext);
            var locationService  = new LocationService(rockContext);
            var scheduleService  = new ScheduleService(rockContext);
            var groupTypeService = new GroupTypeService(rockContext);

            int kioskTypeId = int.Parse(hfKioskTypeId.Value);

            if (kioskTypeId != 0)
            {
                kioskType = kioskTypeService.Get(kioskTypeId);
            }

            if (kioskType == null)
            {
                kioskType = new KioskType();
                kioskTypeService.Add(kioskType);
            }

            if (kioskType != null)
            {
                kioskType.Name         = tbName.Text;
                kioskType.Description  = tbDescription.Text;
                kioskType.Message      = tbMessage.Text;
                kioskType.IsMobile     = cbIsMobile.Checked;
                kioskType.MinutesValid = tbMinutesValid.Text.AsIntegerOrNull();
                kioskType.GraceMinutes = tbGraceMinutes.Text.AsIntegerOrNull();
                kioskType.Theme        = ddlTheme.SelectedValue;

                if (!kioskType.IsValid || !Page.IsValid)
                {
                    // Controls will render the error messages
                    return;
                }

                // Remove any deleted locations
                foreach (var location in kioskType.Locations
                         .Where(l =>
                                !Locations.Keys.Contains(l.Id))
                         .ToList())
                {
                    kioskType.Locations.Remove(location);
                }

                // Remove any deleted schedules
                foreach (var schedule in kioskType.Schedules
                         .Where(s =>
                                !Schedules.Keys.Contains(s.Id))
                         .ToList())
                {
                    kioskType.Schedules.Remove(schedule);
                }

                // Add any new locations
                var existingLocationIDs = kioskType.Locations.Select(l => l.Id).ToList();
                foreach (var location in locationService.Queryable()
                         .Where(l =>
                                Locations.Keys.Contains(l.Id) &&
                                !existingLocationIDs.Contains(l.Id)))
                {
                    kioskType.Locations.Add(location);
                }

                // Add any new schedules
                var existingScheduleIDs = kioskType.Schedules.Select(s => s.Id).ToList();
                foreach (var schedule in scheduleService.Queryable()
                         .Where(s =>
                                Schedules.Keys.Contains(s.Id) &&
                                !existingScheduleIDs.Contains(s.Id)))
                {
                    kioskType.Schedules.Add(schedule);
                }

                //Save checkin template
                kioskType.CheckinTemplateId = ddlTemplates.SelectedValue.AsInteger();


                var GroupTypes = kioskType.GroupTypes;
                GroupTypes.Clear();

                foreach (ListItem item in cblPrimaryGroupTypes.Items)
                {
                    if (item.Selected)
                    {
                        GroupTypes.Add(groupTypeService.Get(item.Value.AsInteger()));
                    }
                }

                kioskType.CampusId = ddlCampus.SelectedCampusId;

                rockContext.SaveChanges();

                KioskTypeCache.Remove(kioskType.Id);
                KioskTypeCache.Get(kioskType.Id);
                KioskDeviceHelpers.Clear(kioskType.GroupTypes.Select(gt => gt.Id).ToList());

                NavigateToParentPage();
            }
        }