private void SetCampus() { RockContext rockContext = new RockContext(); Campus campus = null; // get device string deviceIp = GetIPAddress(); DeviceService deviceService = new DeviceService(rockContext); var deviceQry = deviceService.Queryable( "Location" ) .Where( d => d.IPAddress == deviceIp ); // add device type filter if (!string.IsNullOrWhiteSpace(GetAttributeValue("DeviceType"))) { Guid givingKioskGuid = new Guid( GetAttributeValue("DeviceType")); deviceQry = deviceQry.Where( d => d.DeviceType.Guid == givingKioskGuid); } var device = deviceQry.FirstOrDefault(); if ( device != null ) { if ( device.Locations.Count > 0 ) { campus = new CampusService( new RockContext() ).Get( device.Locations.First().CampusId.Value ); // set the context if ( campus != null ) { var campusEntityType = EntityTypeCache.Read( "Rock.Model.Campus" ); var currentCampus = RockPage.GetCurrentContext( campusEntityType ) as Campus; if ( currentCampus == null || currentCampus.Id != campus.Id ) { bool pageScope = GetAttributeValue( "ContextScope" ) == "Page"; RockPage.SetContextCookie( campus, pageScope, true ); } } } } // set display output var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields( this.RockPage, this.CurrentPerson ); mergeFields.Add( "ClientIp", deviceIp ); mergeFields.Add( "Device", device ); mergeFields.Add( "Campus", campus ); lOutput.Text = GetAttributeValue( "DisplayLava" ).ResolveMergeFields( mergeFields ); // show debug info if ( GetAttributeValue( "EnableDebug" ).AsBoolean() && IsUserAuthorized( Authorization.EDIT ) ) { lDebug.Visible = true; lDebug.Text = mergeFields.lavaDebugInfo(); } }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click( object sender, EventArgs e ) { Device Device = null; var rockContext = new RockContext(); var deviceService = new DeviceService( rockContext ); var attributeService = new AttributeService( rockContext ); var locationService = new LocationService( rockContext ); int DeviceId = int.Parse( hfDeviceId.Value ); if ( DeviceId != 0 ) { Device = deviceService.Get( DeviceId ); } if ( Device == null ) { // Check for existing var existingDevice = deviceService.Queryable() .Where( d => d.Name == tbName.Text ) .FirstOrDefault(); if ( existingDevice != null ) { nbDuplicateDevice.Text = string.Format( "A device already exists with the name '{0}'. Please use a different device name.", existingDevice.Name ); nbDuplicateDevice.Visible = true; } else { Device = new Device(); deviceService.Add( Device ); } } if ( Device != null ) { Device.Name = tbName.Text; Device.Description = tbDescription.Text; Device.IPAddress = tbIpAddress.Text; Device.DeviceTypeValueId = ddlDeviceType.SelectedValueAsInt().Value; Device.PrintToOverride = (PrintTo)System.Enum.Parse( typeof( PrintTo ), ddlPrintTo.SelectedValue ); Device.PrinterDeviceId = ddlPrinter.SelectedValueAsInt(); Device.PrintFrom = (PrintFrom)System.Enum.Parse( typeof( PrintFrom ), ddlPrintFrom.SelectedValue ); if ( Device.Location == null ) { Device.Location = new Location(); } Device.Location.GeoPoint = geopPoint.SelectedValue; Device.Location.GeoFence = geopFence.SelectedValue; if ( !Device.IsValid || !Page.IsValid ) { // Controls will render the error messages return; } // Remove any deleted locations foreach ( var location in Device.Locations .Where( l => !Locations.Keys.Contains( l.Id ) ) .ToList() ) { Device.Locations.Remove( location ); } // Add any new locations var existingLocationIDs = Device.Locations.Select( l => l.Id ).ToList(); foreach ( var location in locationService.Queryable() .Where( l => Locations.Keys.Contains( l.Id ) && !existingLocationIDs.Contains( l.Id ) ) ) { Device.Locations.Add( location ); } rockContext.SaveChanges(); Rock.CheckIn.KioskDevice.Flush( Device.Id ); NavigateToParentPage(); } }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { var deviceService = new DeviceService( new RockContext() ); var sortProperty = gDevice.SortProperty; gDevice.EntityTypeId = EntityTypeCache.Read<Device>().Id; var queryable = deviceService.Queryable().Select( a => new { a.Id, a.Name, DeviceTypeName = a.DeviceType.Value, a.IPAddress, a.PrintToOverride, a.PrintFrom, PrinterDeviceName = a.PrinterDevice.Name, a.PrinterDeviceId, a.DeviceTypeValueId } ); string name = fDevice.GetUserPreference( "Name" ); if ( !string.IsNullOrWhiteSpace( name ) ) { queryable = queryable.Where( d => d.Name.Contains( name ) ); } int? deviceTypeId = fDevice.GetUserPreference( "Device Type" ).AsIntegerOrNull(); if ( deviceTypeId.HasValue ) { queryable = queryable.Where( d => d.DeviceTypeValueId == deviceTypeId.Value ); } string ipAddress = fDevice.GetUserPreference( "IP Address" ); if ( !string.IsNullOrWhiteSpace( ipAddress ) ) { queryable = queryable.Where( d => d.IPAddress.Contains( ipAddress ) ); } if ( !string.IsNullOrWhiteSpace( fDevice.GetUserPreference( "Print To" ) ) ) { PrintTo printTo = (PrintTo)System.Enum.Parse( typeof( PrintTo ), fDevice.GetUserPreference( "Print To" ) ); ; queryable = queryable.Where( d => d.PrintToOverride == printTo ); } int? printerId = fDevice.GetUserPreference( "Printer" ).AsIntegerOrNull(); if ( printerId.HasValue ) { queryable = queryable.Where( d => d.PrinterDeviceId == printerId ); } if ( !string.IsNullOrWhiteSpace( fDevice.GetUserPreference( "Print From" ) ) ) { PrintFrom printFrom = (PrintFrom)System.Enum.Parse( typeof( PrintFrom ), fDevice.GetUserPreference( "Print From" ) ); ; queryable = queryable.Where( d => d.PrintFrom == printFrom ); } if ( sortProperty != null ) { gDevice.DataSource = queryable.Sort( sortProperty ).ToList(); } else { gDevice.DataSource = queryable.OrderBy( d => d.Name ).ToList(); } gDevice.EntityTypeId = EntityTypeCache.Read<Rock.Model.Device>().Id; gDevice.DataBind(); }