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(); 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); Rock.CheckIn.KioskDevice.Clear(); NavigateToParentPage(); } }
private void ActivateKiosk(Kiosk kiosk, bool logout) { RockContext rockContext = new RockContext(); DeviceService deviceService = new DeviceService(rockContext); KioskService kioskService = new KioskService(rockContext); //The kiosk can come in a variety of states. //Get a fresh version with our context to avoid context errors. kiosk = kioskService.Get(kiosk.Id); //Load matching device and update or create information var device = deviceService.Queryable().Where(d => d.Name == kiosk.Name).FirstOrDefault(); //create new device to match our kiosk if (device == null) { device = new Device(); device.DeviceTypeValueId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.DEVICE_TYPE_CHECKIN_KIOSK).Id; device.Name = kiosk.Name; deviceService.Add(device); } device.LoadAttributes(); device.IPAddress = kiosk.IPAddress; device.Locations.Clear(); foreach (var loc in kiosk.KioskType.Locations.ToList()) { device.Locations.Add(loc); } device.PrintFrom = kiosk.PrintFrom; device.PrintToOverride = kiosk.PrintToOverride; device.PrinterDeviceId = kiosk.PrinterDeviceId; rockContext.SaveChanges(); if (PageParameter("DateTime").AsDateTime().HasValue) { device.SetAttributeValue("core_device_DebugDateTime", PageParameter("datetime")); } else { device.SetAttributeValue("core_device_DebugDateTime", ""); } device.SaveAttributeValues(rockContext); LocalDeviceConfig.CurrentKioskId = device.Id; LocalDeviceConfig.CurrentGroupTypeIds = kiosk.KioskType.GroupTypes.Select(gt => gt.Id).ToList(); LocalDeviceConfig.CurrentCheckinTypeId = kiosk.KioskType.CheckinTemplateId; CurrentCheckInState = null; CurrentWorkflow = null; var kioskTypeCookie = this.Page.Request.Cookies["KioskTypeId"]; if (kioskTypeCookie == null) { kioskTypeCookie = new System.Web.HttpCookie("KioskTypeId"); } kioskTypeCookie.Expires = RockDateTime.Now.AddYears(1); kioskTypeCookie.Value = kiosk.KioskType.Id.ToString(); this.Page.Response.Cookies.Set(kioskTypeCookie); Session["KioskTypeId"] = kiosk.KioskType.Id; Session["KioskMessage"] = kiosk.KioskType.Message; //Clean things up so we have the freshest possible version. KioskTypeCache.Remove(kiosk.KioskTypeId ?? 0); KioskDevice.Remove(device.Id); Dictionary <string, string> pageParameters = new Dictionary <string, string>(); if (kiosk.KioskType.Theme.IsNotNullOrWhiteSpace() && !GetAttributeValue("Manual").AsBoolean()) { LocalDeviceConfig.CurrentTheme = kiosk.KioskType.Theme; pageParameters.Add("theme", LocalDeviceConfig.CurrentTheme); } if (logout) { pageParameters.Add("logout", "true"); } SaveState(); NavigateToNextPage(pageParameters); }
/// <summary> /// Attempts to match a known kiosk based on the IP address of the client. /// </summary> private void GetKioskType(Kiosk kiosk, RockContext rockContext) { if (kiosk.KioskType != null) { DeviceService deviceService = new DeviceService(rockContext); //Load matching device and update or create information var device = deviceService.Queryable().Where(d => d.Name == kiosk.Name).FirstOrDefault(); //create new device to match our kiosk if (device == null) { device = new Device(); device.DeviceTypeValueId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.DEVICE_TYPE_CHECKIN_KIOSK).Id; device.Name = kiosk.Name; deviceService.Add(device); } device.LoadAttributes(); device.IPAddress = kiosk.IPAddress; device.Locations.Clear(); foreach (var loc in kiosk.KioskType.Locations.ToList()) { device.Locations.Add(loc); } device.PrintFrom = kiosk.PrintFrom; device.PrintToOverride = kiosk.PrintToOverride; device.PrinterDeviceId = kiosk.PrinterDeviceId; rockContext.SaveChanges(); if (PageParameter("DateTime").AsDateTime().HasValue) { device.SetAttributeValue("core_device_DebugDateTime", PageParameter("datetime")); } else { device.SetAttributeValue("core_device_DebugDateTime", ""); } device.SaveAttributeValues(rockContext); LocalDeviceConfig.CurrentKioskId = device.Id; LocalDeviceConfig.CurrentGroupTypeIds = kiosk.KioskType.GroupTypes.Select(gt => gt.Id).ToList(); LocalDeviceConfig.CurrentCheckinTypeId = kiosk.KioskType.CheckinTemplateId; CurrentCheckInState = null; CurrentWorkflow = null; var kioskTypeCookie = this.Page.Request.Cookies["KioskTypeId"]; if (kioskTypeCookie == null) { kioskTypeCookie = new System.Web.HttpCookie("KioskTypeId"); } kioskTypeCookie.Expires = RockDateTime.Now.AddYears(1); kioskTypeCookie.Value = kiosk.KioskType.Id.ToString(); this.Page.Response.Cookies.Set(kioskTypeCookie); Session["KioskTypeId"] = kiosk.KioskType.Id; Session["KioskMessage"] = kiosk.KioskType.Message; //Clean things up so we have the freshest possible version. KioskTypeCache.Remove(kiosk.KioskTypeId ?? 0); KioskDevice.Remove(device.Id); SaveState(); NavigateToNextPage(); } else { ltDNS.Text = kiosk.Name; pnlMain.Visible = true; } }