예제 #1
0
        public void ApiCreateEntityChange(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 = new Rock.Core.EntityChange();
                    EntityChangeService.Add(existingEntityChange, user.PersonId);
                    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>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
예제 #2
0
        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);
                }
            }
        }
예제 #3
0
        public void ApiCreateEntityChange( 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 = new Rock.Core.EntityChange();
                    EntityChangeService.Add( existingEntityChange, user.PersonId );
                    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>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
예제 #4
0
        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 );
            }
        }