public Rock.Groups.DTO.GroupType ApiGet(string id, string apiKey) { using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault(); if (user != null) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.Groups.GroupTypeService GroupTypeService = new Rock.Groups.GroupTypeService(); Rock.Groups.GroupType GroupType = GroupTypeService.Get(int.Parse(id)); if (GroupType.Authorized("View", user)) { return(GroupType.DataTransferObject); } else { throw new WebFaultException <string>("Not Authorized to View this GroupType", System.Net.HttpStatusCode.Forbidden); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public void UpdateGroupType(string id, Rock.Groups.DTO.GroupType GroupType) { var currentUser = Rock.CMS.UserService.GetCurrentUser(); if (currentUser == null) { throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden); } using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.Groups.GroupTypeService GroupTypeService = new Rock.Groups.GroupTypeService(); Rock.Groups.GroupType existingGroupType = GroupTypeService.Get(int.Parse(id)); if (existingGroupType.Authorized("Edit", currentUser)) { uow.objectContext.Entry(existingGroupType).CurrentValues.SetValues(GroupType); if (existingGroupType.IsValid) { GroupTypeService.Save(existingGroupType, currentUser.PersonId); } else { throw new WebFaultException <string>(existingGroupType.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest); } } else { throw new WebFaultException <string>("Not Authorized to Edit this GroupType", System.Net.HttpStatusCode.Forbidden); } } }
public void ApiCreateGroupType(string apiKey, Rock.Groups.DTO.GroupType GroupType) { using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault(); if (user != null) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.Groups.GroupTypeService GroupTypeService = new Rock.Groups.GroupTypeService(); Rock.Groups.GroupType existingGroupType = new Rock.Groups.GroupType(); GroupTypeService.Add(existingGroupType, user.PersonId); uow.objectContext.Entry(existingGroupType).CurrentValues.SetValues(GroupType); if (existingGroupType.IsValid) { GroupTypeService.Save(existingGroupType, user.PersonId); } else { throw new WebFaultException <string>(existingGroupType.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public void DeleteGroupType(string id) { var currentUser = Rock.CMS.UserService.GetCurrentUser(); if (currentUser == null) { throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden); } using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.Groups.GroupTypeService GroupTypeService = new Rock.Groups.GroupTypeService(); Rock.Groups.GroupType GroupType = GroupTypeService.Get(int.Parse(id)); if (GroupType.Authorized("Edit", currentUser)) { GroupTypeService.Delete(GroupType, currentUser.PersonId); GroupTypeService.Save(GroupType, currentUser.PersonId); } else { throw new WebFaultException <string>("Not Authorized to Edit this GroupType", System.Net.HttpStatusCode.Forbidden); } } }
public void CreateBlockInstance(Rock.CMS.DTO.BlockInstance BlockInstance) { var currentUser = Rock.CMS.UserService.GetCurrentUser(); if (currentUser == null) { throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden); } using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CMS.BlockInstanceService BlockInstanceService = new Rock.CMS.BlockInstanceService(); Rock.CMS.BlockInstance existingBlockInstance = new Rock.CMS.BlockInstance(); BlockInstanceService.Add(existingBlockInstance, currentUser.PersonId); uow.objectContext.Entry(existingBlockInstance).CurrentValues.SetValues(BlockInstance); if (existingBlockInstance.IsValid) { BlockInstanceService.Save(existingBlockInstance, currentUser.PersonId); } else { throw new WebFaultException <string>(existingBlockInstance.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest); } } }
public void ApiDeleteBlockInstance(string id, string apiKey) { using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault(); if (user != null) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CMS.BlockInstanceService BlockInstanceService = new Rock.CMS.BlockInstanceService(); Rock.CMS.BlockInstance BlockInstance = BlockInstanceService.Get(int.Parse(id)); if (BlockInstance.Authorized("Edit", user)) { BlockInstanceService.Delete(BlockInstance, user.PersonId); BlockInstanceService.Save(BlockInstance, user.PersonId); } else { throw new WebFaultException <string>("Not Authorized to Edit this BlockInstance", System.Net.HttpStatusCode.Forbidden); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public void Move( string id, Rock.CMS.DTO.BlockInstance BlockInstance ) { var currentUser = Rock.CMS.UserService.GetCurrentUser(); if ( currentUser == null ) throw new WebFaultException<string>( "Must be logged in", System.Net.HttpStatusCode.Forbidden ); using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() ) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CMS.BlockInstanceService BlockInstanceService = new Rock.CMS.BlockInstanceService(); Rock.CMS.BlockInstance existingBlockInstance = BlockInstanceService.Get( int.Parse( id ) ); if ( existingBlockInstance.Authorized( "Edit", currentUser ) ) { // If the block was moved from or to the layout section, then all the pages // that use that layout need to be flushed from cache if ( existingBlockInstance.Layout != BlockInstance.Layout ) { if ( existingBlockInstance.Layout != null ) Rock.Web.Cache.Page.FlushLayout( existingBlockInstance.Layout ); if ( BlockInstance.Layout != null ) Rock.Web.Cache.Page.FlushLayout( BlockInstance.Layout ); } uow.objectContext.Entry( existingBlockInstance ).CurrentValues.SetValues( BlockInstance ); BlockInstanceService.Move( existingBlockInstance ); BlockInstanceService.Save( existingBlockInstance, currentUser.PersonId ); } else throw new WebFaultException<string>( "Not Authorized to Edit this BlockInstance", System.Net.HttpStatusCode.Forbidden ); } }
public bool Available( string username ) { using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CMS.UserService UserService = new Rock.CMS.UserService(); User User = UserService.GetByUserName( username ); return ( User == null ); } }
public bool Available(string username) { using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CMS.UserService UserService = new Rock.CMS.UserService(); User User = UserService.GetByUserName(username); return(User == null); } }
public void ApiFlushGlobal( string apiKey ) { using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() ) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault(); if ( user != null ) FlushGlobal(); else throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden ); } }
public void ApiFlushGlobal(string apiKey) { using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault(); if (user != null) { FlushGlobal(); } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public void ApiMove(string id, string apiKey, Rock.CMS.DTO.BlockInstance BlockInstance) { using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault(); if (user != null) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CMS.BlockInstanceService BlockInstanceService = new Rock.CMS.BlockInstanceService(); Rock.CMS.BlockInstance existingBlockInstance = BlockInstanceService.Get(int.Parse(id)); if (existingBlockInstance.Authorized("Edit", user)) { // If the block was moved from or to the layout section, then all the pages // that use that layout need to be flushed from cache if (existingBlockInstance.Layout != BlockInstance.Layout) { if (existingBlockInstance.Layout != null) { Rock.Web.Cache.Page.FlushLayout(existingBlockInstance.Layout); } if (BlockInstance.Layout != null) { Rock.Web.Cache.Page.FlushLayout(BlockInstance.Layout); } } uow.objectContext.Entry(existingBlockInstance).CurrentValues.SetValues(BlockInstance); BlockInstanceService.Move(existingBlockInstance); BlockInstanceService.Save(existingBlockInstance, user.PersonId); } else { throw new WebFaultException <string>("Not Authorized to Edit this BlockInstance", System.Net.HttpStatusCode.Forbidden); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public void Move(string id, Rock.CMS.DTO.BlockInstance BlockInstance) { var currentUser = Rock.CMS.UserService.GetCurrentUser(); if (currentUser == null) { throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden); } using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CMS.BlockInstanceService BlockInstanceService = new Rock.CMS.BlockInstanceService(); Rock.CMS.BlockInstance existingBlockInstance = BlockInstanceService.Get(int.Parse(id)); if (existingBlockInstance.Authorized("Edit", currentUser)) { // If the block was moved from or to the layout section, then all the pages // that use that layout need to be flushed from cache if (existingBlockInstance.Layout != BlockInstance.Layout) { if (existingBlockInstance.Layout != null) { Rock.Web.Cache.Page.FlushLayout(existingBlockInstance.Layout); } if (BlockInstance.Layout != null) { Rock.Web.Cache.Page.FlushLayout(BlockInstance.Layout); } } uow.objectContext.Entry(existingBlockInstance).CurrentValues.SetValues(BlockInstance); BlockInstanceService.Move(existingBlockInstance); BlockInstanceService.Save(existingBlockInstance, currentUser.PersonId); } else { throw new WebFaultException <string>("Not Authorized to Edit this BlockInstance", System.Net.HttpStatusCode.Forbidden); } } }
private void BindGrid() { string type = PageParameter("SearchType"); string term = PageParameter("SearchTerm"); var groups = new List <Group>(); if (!String.IsNullOrWhiteSpace(type) && !String.IsNullOrWhiteSpace(term)) { using (var uow = new Rock.Data.UnitOfWorkScope()) { var groupService = new GroupService(); switch (type.ToLower()) { case ("name"): groups = groupService.Queryable(). Where(g => (g.Name).StartsWith(term)). OrderBy(g => g.Name). ToList(); break; } } } if (groups.Count == 1) { Response.Redirect(string.Format("~/Group/{0}", groups[0].Id), false); Context.ApplicationInstance.CompleteRequest(); } else { gGroups.DataSource = groups; gGroups.DataBind(); } }
public void ApiDeletePage( string id, string apiKey ) { using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() ) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault(); if (user != null) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CMS.PageService PageService = new Rock.CMS.PageService(); Rock.CMS.Page Page = PageService.Get( int.Parse( id ) ); if ( Page.Authorized( "Edit", user ) ) { PageService.Delete( Page, user.PersonId ); PageService.Save( Page, user.PersonId ); } else throw new WebFaultException<string>( "Not Authorized to Edit this Page", System.Net.HttpStatusCode.Forbidden ); } else throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden ); } }
public void ApiCreatePage( string apiKey, Rock.CMS.DTO.Page Page ) { using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() ) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault(); if (user != null) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CMS.PageService PageService = new Rock.CMS.PageService(); Rock.CMS.Page existingPage = new Rock.CMS.Page(); PageService.Add( existingPage, user.PersonId ); uow.objectContext.Entry(existingPage).CurrentValues.SetValues(Page); if (existingPage.IsValid) PageService.Save( existingPage, user.PersonId ); else throw new WebFaultException<string>( existingPage.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest ); } else throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden ); } }
public void ApiUpdateFieldType(string id, string apiKey, Rock.Core.DTO.FieldType FieldType) { using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault(); if (user != null) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.Core.FieldTypeService FieldTypeService = new Rock.Core.FieldTypeService(); Rock.Core.FieldType existingFieldType = FieldTypeService.Get(int.Parse(id)); if (existingFieldType.Authorized("Edit", user)) { uow.objectContext.Entry(existingFieldType).CurrentValues.SetValues(FieldType); if (existingFieldType.IsValid) { FieldTypeService.Save(existingFieldType, user.PersonId); } else { throw new WebFaultException <string>(existingFieldType.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest); } } else { throw new WebFaultException <string>("Not Authorized to Edit this FieldType", System.Net.HttpStatusCode.Forbidden); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public Rock.Core.DTO.FieldType Get(string id) { var currentUser = Rock.CMS.UserService.GetCurrentUser(); if (currentUser == null) { throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden); } using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.Core.FieldTypeService FieldTypeService = new Rock.Core.FieldTypeService(); Rock.Core.FieldType FieldType = FieldTypeService.Get(int.Parse(id)); if (FieldType.Authorized("View", currentUser)) { return(FieldType.DataTransferObject); } else { throw new WebFaultException <string>("Not Authorized to View this FieldType", System.Net.HttpStatusCode.Forbidden); } } }
public void ApiMove( string id, string apiKey, Rock.CMS.DTO.BlockInstance BlockInstance ) { using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() ) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault(); if ( user != null ) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CMS.BlockInstanceService BlockInstanceService = new Rock.CMS.BlockInstanceService(); Rock.CMS.BlockInstance existingBlockInstance = BlockInstanceService.Get( int.Parse( id ) ); if ( existingBlockInstance.Authorized( "Edit", user ) ) { // If the block was moved from or to the layout section, then all the pages // that use that layout need to be flushed from cache if ( existingBlockInstance.Layout != BlockInstance.Layout ) { if ( existingBlockInstance.Layout != null ) Rock.Web.Cache.Page.FlushLayout( existingBlockInstance.Layout ); if ( BlockInstance.Layout != null ) Rock.Web.Cache.Page.FlushLayout( BlockInstance.Layout ); } uow.objectContext.Entry( existingBlockInstance ).CurrentValues.SetValues( BlockInstance ); BlockInstanceService.Move( existingBlockInstance ); BlockInstanceService.Save( existingBlockInstance, user.PersonId ); } else throw new WebFaultException<string>( "Not Authorized to Edit this BlockInstance", System.Net.HttpStatusCode.Forbidden ); } else throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden ); } }
private void BindGrid() { string type = PageParameter("SearchType"); string term = PageParameter("SearchTerm"); var people = new List <Person>(); if (!String.IsNullOrWhiteSpace(type) && !String.IsNullOrWhiteSpace(term)) { using (var uow = new Rock.Data.UnitOfWorkScope()) { var personService = new PersonService(); switch (type.ToLower()) { case ("name"): string fName = string.Empty; string lName = string.Empty; var names = term.SplitDelimitedValues(); bool lastFirst = term.Contains(","); if (lastFirst) { // last, first lName = names.Length >= 1 ? names[0] : string.Empty; fName = names.Length >= 2 ? names[1] : string.Empty; } else { // first last fName = names.Length >= 1 ? names[0] : string.Empty; lName = names.Length >= 2 ? names[1] : string.Empty; } people = personService.Queryable(). Where(p => ((p.NickName ?? p.GivenName).StartsWith(fName) && p.LastName.StartsWith(lName))). OrderBy(p => p.LastName).ThenBy(p => p.NickName ?? p.GivenName). ToList(); break; case ("phone"): var phoneService = new PhoneNumberService(); var personIds = phoneService.Queryable(). Where(n => n.Number.Contains(term)). Select(n => n.PersonId).Distinct(); people = personService.Queryable(). Where(p => personIds.Contains(p.Id)). OrderBy(p => p.LastName).ThenBy(p => (p.NickName ?? p.GivenName)). ToList(); break; case ("address"): break; case ("email"): people = personService.Queryable(). Where(p => p.Email.Contains(term)). OrderBy(p => p.LastName).ThenBy(p => (p.NickName ?? p.GivenName)). ToList(); break; } } } if (people.Count == 1) { Response.Redirect(string.Format("~/Person/{0}", people[0].Id), false); Context.ApplicationInstance.CompleteRequest(); } else { gPeople.DataSource = people; gPeople.DataBind(); } }
public void UpdatePage( string id, Rock.CMS.DTO.Page Page ) { var currentUser = Rock.CMS.UserService.GetCurrentUser(); if ( currentUser == null ) throw new WebFaultException<string>("Must be logged in", System.Net.HttpStatusCode.Forbidden ); using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() ) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CMS.PageService PageService = new Rock.CMS.PageService(); Rock.CMS.Page existingPage = PageService.Get( int.Parse( id ) ); if ( existingPage.Authorized( "Edit", currentUser ) ) { uow.objectContext.Entry(existingPage).CurrentValues.SetValues(Page); if (existingPage.IsValid) PageService.Save( existingPage, currentUser.PersonId ); else throw new WebFaultException<string>( existingPage.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest ); } else throw new WebFaultException<string>( "Not Authorized to Edit this Page", System.Net.HttpStatusCode.Forbidden ); } }
public Rock.CMS.DTO.Page Get( string id ) { var currentUser = Rock.CMS.UserService.GetCurrentUser(); if ( currentUser == null ) throw new WebFaultException<string>("Must be logged in", System.Net.HttpStatusCode.Forbidden ); using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CMS.PageService PageService = new Rock.CMS.PageService(); Rock.CMS.Page Page = PageService.Get( int.Parse( id ) ); if ( Page.Authorized( "View", currentUser ) ) return Page.DataTransferObject; else throw new WebFaultException<string>( "Not Authorized to View this Page", System.Net.HttpStatusCode.Forbidden ); } }
public void DeletePage( string id ) { var currentUser = Rock.CMS.UserService.GetCurrentUser(); if ( currentUser == null ) throw new WebFaultException<string>("Must be logged in", System.Net.HttpStatusCode.Forbidden ); using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() ) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CMS.PageService PageService = new Rock.CMS.PageService(); Rock.CMS.Page Page = PageService.Get( int.Parse( id ) ); if ( Page.Authorized( "Edit", currentUser ) ) { PageService.Delete( Page, currentUser.PersonId ); PageService.Save( Page, currentUser.PersonId ); } else throw new WebFaultException<string>( "Not Authorized to Edit this Page", System.Net.HttpStatusCode.Forbidden ); } }
public void CreateEntityChange( Rock.Core.DTO.EntityChange EntityChange ) { var currentUser = Rock.CMS.UserService.GetCurrentUser(); if ( currentUser == null ) throw new WebFaultException<string>("Must be logged in", System.Net.HttpStatusCode.Forbidden ); using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() ) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.Core.EntityChangeService EntityChangeService = new Rock.Core.EntityChangeService(); Rock.Core.EntityChange existingEntityChange = new Rock.Core.EntityChange(); EntityChangeService.Add( existingEntityChange, currentUser.PersonId ); uow.objectContext.Entry(existingEntityChange).CurrentValues.SetValues(EntityChange); if (existingEntityChange.IsValid) EntityChangeService.Save( existingEntityChange, currentUser.PersonId ); else throw new WebFaultException<string>( existingEntityChange.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest ); } }
public void ApiUpdateEntityChange( string id, string apiKey, Rock.Core.DTO.EntityChange EntityChange ) { using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() ) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault(); if (user != null) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.Core.EntityChangeService EntityChangeService = new Rock.Core.EntityChangeService(); Rock.Core.EntityChange existingEntityChange = EntityChangeService.Get( int.Parse( id ) ); if ( existingEntityChange.Authorized( "Edit", user ) ) { uow.objectContext.Entry(existingEntityChange).CurrentValues.SetValues(EntityChange); if (existingEntityChange.IsValid) EntityChangeService.Save( existingEntityChange, user.PersonId ); else throw new WebFaultException<string>( existingEntityChange.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest ); } else throw new WebFaultException<string>( "Not Authorized to Edit this EntityChange", System.Net.HttpStatusCode.Forbidden ); } else throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden ); } }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="action">The workflow action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override bool Execute( Model.WorkflowAction action, Object entity, out List<string> errorMessages ) { var checkInState = GetCheckInState( entity, out errorMessages ); if ( checkInState != null ) { DateTime startDateTime = DateTime.Now; int securityCodeLength = 3; if ( !int.TryParse( GetAttributeValue( action, "SecurityCodeLength" ), out securityCodeLength ) ) { securityCodeLength = 3; } using ( var uow = new Rock.Data.UnitOfWorkScope() ) { var attendanceCodeService = new AttendanceCodeService(); var attendanceService = new AttendanceService(); var groupMemberService = new GroupMemberService(); foreach ( var family in checkInState.CheckIn.Families.Where( f => f.Selected ) ) { foreach ( var person in family.People.Where( p => p.Selected ) ) { var attendanceCode = attendanceCodeService.GetNew( securityCodeLength ); person.SecurityCode = attendanceCode.Code; foreach ( var groupType in person.GroupTypes.Where( g => g.Selected ) ) { foreach ( var group in groupType.Groups.Where( g => g.Selected ) ) { foreach ( var location in group.Locations.Where( l => l.Selected ) ) { if ( groupType.GroupType.AttendanceRule == AttendanceRule.AddOnCheckIn && groupType.GroupType.DefaultGroupRoleId.HasValue && !groupMemberService.GetByGroupIdAndPersonId( group.Group.Id, person.Person.Id, true ).Any() ) { var groupMember = new GroupMember(); groupMember.GroupId = group.Group.Id; groupMember.PersonId = person.Person.Id; groupMember.GroupRoleId = groupType.GroupType.DefaultGroupRoleId.Value; groupMemberService.Add( groupMember, null ); groupMemberService.Save( groupMember, null ); } foreach ( var schedule in location.Schedules.Where( s => s.Selected ) ) { // Only create one attendance record per day for each person/schedule/group/location var attendance = attendanceService.Get( startDateTime, location.Location.Id, schedule.Schedule.Id, group.Group.Id, person.Person.Id ); if ( attendance == null ) { attendance = ((Rock.Data.RockContext)uow.DbContext).Attendances.Create(); attendance.LocationId = location.Location.Id; attendance.ScheduleId = schedule.Schedule.Id; attendance.GroupId = group.Group.Id; attendance.PersonId = person.Person.Id; attendance.DeviceId = checkInState.Kiosk.Device.Id; attendance.SearchTypeValueId = checkInState.CheckIn.SearchType.Id; attendanceService.Add( attendance, null ); } attendance.AttendanceCodeId = attendanceCode.Id; attendance.StartDateTime = startDateTime; attendance.EndDateTime = null; attendance.DidAttend = true; attendanceService.Save( attendance, null ); KioskLocationAttendance.AddAttendance( attendance ); } } } } } } } return true; } return false; }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="action">The workflow action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override bool Execute(Model.WorkflowAction action, Object entity, out List <string> errorMessages) { var checkInState = GetCheckInState(entity, out errorMessages); if (checkInState != null) { DateTime startDateTime = DateTime.Now; int securityCodeLength = 3; if (!int.TryParse(GetAttributeValue(action, "SecurityCodeLength"), out securityCodeLength)) { securityCodeLength = 3; } using (var uow = new Rock.Data.UnitOfWorkScope()) { var attendanceCodeService = new AttendanceCodeService(); var attendanceService = new AttendanceService(); var groupMemberService = new GroupMemberService(); foreach (var family in checkInState.CheckIn.Families.Where(f => f.Selected)) { foreach (var person in family.People.Where(p => p.Selected)) { var attendanceCode = attendanceCodeService.GetNew(securityCodeLength); person.SecurityCode = attendanceCode.Code; foreach (var groupType in person.GroupTypes.Where(g => g.Selected)) { foreach (var group in groupType.Groups.Where(g => g.Selected)) { foreach (var location in group.Locations.Where(l => l.Selected)) { if (groupType.GroupType.AttendanceRule == AttendanceRule.AddOnCheckIn && groupType.GroupType.DefaultGroupRoleId.HasValue && !groupMemberService.GetByGroupIdAndPersonId(group.Group.Id, person.Person.Id, true).Any()) { var groupMember = new GroupMember(); groupMember.GroupId = group.Group.Id; groupMember.PersonId = person.Person.Id; groupMember.GroupRoleId = groupType.GroupType.DefaultGroupRoleId.Value; groupMemberService.Add(groupMember, null); groupMemberService.Save(groupMember, null); } foreach (var schedule in location.Schedules.Where(s => s.Selected)) { // Only create one attendance record per day for each person/schedule/group/location var attendance = attendanceService.Get(startDateTime, location.Location.Id, schedule.Schedule.Id, group.Group.Id, person.Person.Id); if (attendance == null) { attendance = ((Rock.Data.RockContext)uow.DbContext).Attendances.Create(); attendance.LocationId = location.Location.Id; attendance.ScheduleId = schedule.Schedule.Id; attendance.GroupId = group.Group.Id; attendance.PersonId = person.Person.Id; attendance.DeviceId = checkInState.Kiosk.Device.Id; attendance.SearchTypeValueId = checkInState.CheckIn.SearchType.Id; attendanceService.Add(attendance, null); } attendance.AttendanceCodeId = attendanceCode.Id; attendance.StartDateTime = startDateTime; attendance.EndDateTime = null; attendance.DidAttend = true; attendanceService.Save(attendance, null); KioskLocationAttendance.AddAttendance(attendance); } } } } } } } return(true); } return(false); }
private void BindGrid() { string type = PageParameter("SearchType"); string term = PageParameter("SearchTerm"); List <Person> personList = null; if (!String.IsNullOrWhiteSpace(type) && !String.IsNullOrWhiteSpace(term)) { using (var uow = new Rock.Data.UnitOfWorkScope()) { IQueryable <Person> people = null; var personService = new PersonService(); switch (type.ToLower()) { case ("name"): people = personService.GetByFullName(term, true); break; case ("phone"): var phoneService = new PhoneNumberService(); var personIds = phoneService.GetPersonIdsByNumber(term); people = personService.Queryable().Where(p => personIds.Contains(p.Id)); break; case ("address"): var groupMemberService = new GroupMemberService(); var personIds2 = groupMemberService.GetPersonIdsByHomeAddress(term); people = personService.Queryable().Where(p => personIds2.Contains(p.Id)); break; case ("email"): people = personService.Queryable().Where(p => p.Email.Contains(term)); break; } SortProperty sortProperty = gPeople.SortProperty; if (sortProperty != null) { people = people.Sort(sortProperty); } else { people = people.OrderBy(p => p.LastName).ThenBy(p => p.FirstName); } personList = people.ToList(); } } if (personList != null) { if (personList.Count == 1) { Response.Redirect(string.Format("~/Person/{0}", personList[0].Id), false); Context.ApplicationInstance.CompleteRequest(); } else { gPeople.DataSource = personList; gPeople.DataBind(); } } }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="action">The workflow action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override bool Execute( Model.WorkflowAction action, Object entity, out List<string> errorMessages ) { var checkInState = GetCheckInState( entity, out errorMessages ); var labels = new List<CheckInLabel>(); if ( checkInState != null ) { int labelFileTypeId = new BinaryFileTypeService() .Queryable() .Where( f => f.Guid == new Guid(SystemGuid.BinaryFiletype.CHECKIN_LABEL)) .Select( f => f.Id) .FirstOrDefault(); if (labelFileTypeId != 0) { using ( var uow = new Rock.Data.UnitOfWorkScope() ) { foreach ( var family in checkInState.CheckIn.Families.Where( f => f.Selected ) ) { foreach ( var person in family.People.Where( p => p.Selected ) ) { foreach ( var groupType in person.GroupTypes.Where( g => g.Selected ) ) { var mergeObjects = new Dictionary<string, object>(); mergeObjects.Add( "person", person ); mergeObjects.Add( "groupType", groupType ); groupType.Labels = new List<CheckInLabel>(); GetGroupTypeLabels( groupType.GroupType, groupType.Labels, labelFileTypeId, mergeObjects ); var PrinterIPs = new Dictionary<int, string>(); foreach ( var label in groupType.Labels ) { label.PrintFrom = checkInState.Kiosk.Device.PrintFrom; label.PrintTo = checkInState.Kiosk.Device.PrintToOverride; if ( label.PrintTo == PrintTo.Default ) { label.PrintTo = groupType.GroupType.AttendancePrintTo; } if ( label.PrintTo == PrintTo.Kiosk ) { var device = checkInState.Kiosk.Device; if ( device != null ) { label.PrinterDeviceId = device.PrinterDeviceId; } } else if ( label.PrintTo == PrintTo.Location ) { // Should only be one var group = groupType.Groups.Where( g => g.Selected ).FirstOrDefault(); if ( group != null ) { var location = group.Locations.Where( l => l.Selected ).FirstOrDefault(); if ( location != null ) { var device = location.Location.PrinterDevice; if ( device != null ) { label.PrinterDeviceId = device.PrinterDeviceId; } } } } if ( label.PrinterDeviceId.HasValue ) { if ( PrinterIPs.ContainsKey( label.PrinterDeviceId.Value ) ) { label.PrinterAddress = PrinterIPs[label.PrinterDeviceId.Value]; } else { var printerDevice = new DeviceService().Get( label.PrinterDeviceId.Value ); if ( printerDevice != null ) { PrinterIPs.Add( printerDevice.Id, printerDevice.IPAddress ); label.PrinterAddress = printerDevice.IPAddress; } } } } } } } } } return true; } return false; }
private void BindGrid() { string type = PageParameter("SearchType"); string term = PageParameter("SearchTerm"); var people = new List <Person>(); if (!String.IsNullOrWhiteSpace(type) && !String.IsNullOrWhiteSpace(term)) { using (var uow = new Rock.Data.UnitOfWorkScope()) { var personService = new PersonService(); switch (type.ToLower()) { case ("name"): people = personService.GetByFullName(term, true).ToList(); break; case ("phone"): var phoneService = new PhoneNumberService(); var personIds = phoneService.Queryable(). Where(n => n.Number.Contains(term)). Select(n => n.PersonId).Distinct(); people = personService.Queryable(). Where(p => personIds.Contains(p.Id)). OrderBy(p => p.LastName).ThenBy(p => (p.FirstName)). ToList(); break; case ("address"): break; case ("email"): people = personService.Queryable(). Where(p => p.Email.Contains(term)). OrderBy(p => p.LastName).ThenBy(p => (p.FirstName)). ToList(); break; } } } if (people.Count == 1) { Response.Redirect(string.Format("~/Person/{0}", people[0].Id), false); Context.ApplicationInstance.CompleteRequest(); } else { gPeople.DataSource = people; gPeople.DataBind(); } }
private void BindGrid() { string type = PageParameter( "SearchType" ); string term = PageParameter( "SearchTerm" ); List<Person> personList = null; if ( !String.IsNullOrWhiteSpace( type ) && !String.IsNullOrWhiteSpace( term ) ) { using ( var uow = new Rock.Data.UnitOfWorkScope() ) { IQueryable<Person> people = null; var personService = new PersonService(); switch ( type.ToLower() ) { case ( "name" ): people = personService.GetByFullName( term, true ); break; case ( "phone" ): var phoneService = new PhoneNumberService(); var personIds = phoneService.GetPersonIdsByNumber( term ); people = personService.Queryable().Where( p => personIds.Contains( p.Id ) ); break; case ( "address" ): var groupMemberService = new GroupMemberService(); var personIds2 = groupMemberService.GetPersonIdsByHomeAddress( term ); people = personService.Queryable().Where( p => personIds2.Contains( p.Id ) ); break; case ( "email" ): people = personService.Queryable().Where( p => p.Email.Contains( term ) ); break; } SortProperty sortProperty = gPeople.SortProperty; if ( sortProperty != null ) { people = people.Sort( sortProperty ); } else { people = people.OrderBy( p => p.LastName ).ThenBy( p => p.FirstName ); } personList = people.ToList(); } } if ( personList != null ) { if ( personList.Count == 1 ) { Response.Redirect( string.Format( "~/Person/{0}", personList[0].Id ), false ); Context.ApplicationInstance.CompleteRequest(); } else { gPeople.DataSource = personList; gPeople.DataBind(); } } }
public Rock.CMS.DTO.Page ApiGet( string id, string apiKey ) { using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault(); if (user != null) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CMS.PageService PageService = new Rock.CMS.PageService(); Rock.CMS.Page Page = PageService.Get( int.Parse( id ) ); if ( Page.Authorized( "View", user ) ) return Page.DataTransferObject; else throw new WebFaultException<string>( "Not Authorized to View this Page", System.Net.HttpStatusCode.Forbidden ); } else throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden ); } }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="action">The workflow action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override bool Execute(Model.WorkflowAction action, Object entity, out List <string> errorMessages) { var checkInState = GetCheckInState(entity, out errorMessages); var labels = new List <CheckInLabel>(); if (checkInState != null) { int labelFileTypeId = new BinaryFileTypeService() .Queryable() .Where(f => f.Guid == new Guid(SystemGuid.BinaryFiletype.CHECKIN_LABEL)) .Select(f => f.Id) .FirstOrDefault(); if (labelFileTypeId != 0) { using (var uow = new Rock.Data.UnitOfWorkScope()) { foreach (var family in checkInState.CheckIn.Families.Where(f => f.Selected)) { foreach (var person in family.People.Where(p => p.Selected)) { foreach (var groupType in person.GroupTypes.Where(g => g.Selected)) { var mergeObjects = new Dictionary <string, object>(); mergeObjects.Add("person", person); mergeObjects.Add("groupType", groupType); groupType.Labels = new List <CheckInLabel>(); GetGroupTypeLabels(groupType.GroupType, groupType.Labels, labelFileTypeId, mergeObjects); var PrinterIPs = new Dictionary <int, string>(); foreach (var label in groupType.Labels) { label.PrintFrom = checkInState.Kiosk.Device.PrintFrom; label.PrintTo = checkInState.Kiosk.Device.PrintToOverride; if (label.PrintTo == PrintTo.Default) { label.PrintTo = groupType.GroupType.AttendancePrintTo; } if (label.PrintTo == PrintTo.Kiosk) { var device = checkInState.Kiosk.Device; if (device != null) { label.PrinterDeviceId = device.PrinterDeviceId; } } else if (label.PrintTo == PrintTo.Location) { // Should only be one var group = groupType.Groups.Where(g => g.Selected).FirstOrDefault(); if (group != null) { var location = group.Locations.Where(l => l.Selected).FirstOrDefault(); if (location != null) { var device = location.Location.PrinterDevice; if (device != null) { label.PrinterDeviceId = device.PrinterDeviceId; } } } } if (label.PrinterDeviceId.HasValue) { if (PrinterIPs.ContainsKey(label.PrinterDeviceId.Value)) { label.PrinterAddress = PrinterIPs[label.PrinterDeviceId.Value]; } else { var printerDevice = new DeviceService().Get(label.PrinterDeviceId.Value); if (printerDevice != null) { PrinterIPs.Add(printerDevice.Id, printerDevice.IPAddress); label.PrinterAddress = printerDevice.IPAddress; } } } } } } } } } return(true); } return(false); }