Ejemplo n.º 1
0
        protected void gKiosk_Delete(object sender, RowEventArgs e)
        {
            var          rockContext  = new RockContext();
            KioskService kioskService = new KioskService(rockContext);
            Kiosk        kiosk        = kioskService.Get(e.RowKeyId);

            if (kiosk != null)
            {
                int kioskId = kiosk.Id;

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

                kioskService.Delete(kiosk);
                rockContext.SaveChanges();

                DeviceService deviceService = new DeviceService(rockContext);
                var           devices       = deviceService.Queryable().Where(d => d.Name == kiosk.Name).ToList();
                foreach (var device in devices)
                {
                    KioskDeviceHelpers.FlushItem(device.Id);
                }
            }

            BindGrid();
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Kiosk kiosk = null;

            var rockContext      = new RockContext();
            var kioskService     = new KioskService(rockContext);
            var attributeService = new AttributeService(rockContext);

            int kioskId = int.Parse(hfKioskId.Value);

            if (kioskId != 0)
            {
                kiosk = kioskService.Get(kioskId);
            }

            if (kiosk == null)
            {
                // Check for existing
                var existingDevice = kioskService.Queryable()
                                     .Where(k => k.Name == tbName.Text)
                                     .FirstOrDefault();
                if (existingDevice != null)
                {
                    nbDuplicateKiosk.Text    = string.Format("A kiosk already exists with the name '{0}'. Please use a different device name.", existingDevice.Name);
                    nbDuplicateKiosk.Visible = true;
                }
                else
                {
                    kiosk = new Kiosk();
                    kioskService.Add(kiosk);
                }
            }


            if (kiosk != null)
            {
                kiosk.Name        = tbName.Text;
                kiosk.Description = tbDescription.Text;
                kiosk.IPAddress   = tbIPAddress.Text;

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

                kiosk.CategoryId = pCategory.SelectedValueAsId();

                //Save kiosk's checkin type
                kiosk.KioskTypeId = ddlKioskType.SelectedValue.AsInteger();

                kiosk.PrintToOverride = ( PrintTo )System.Enum.Parse(typeof(PrintTo), ddlPrintTo.SelectedValue);
                kiosk.PrinterDeviceId = ddlPrinter.SelectedValueAsInt();
                kiosk.PrintFrom       = ( PrintFrom )System.Enum.Parse(typeof(PrintFrom), ddlPrintFrom.SelectedValue);


                rockContext.SaveChanges();

                DeviceService deviceService = new DeviceService(rockContext);
                var           devices       = deviceService.Queryable().Where(d => d.Name == kiosk.Name).ToList();
                foreach (var device in devices)
                {
                    KioskDeviceHelpers.FlushItem(device.Id);
                }

                NavigateToParentPage();
            }
        }
Ejemplo n.º 5
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();
            }
        }