Exemplo n.º 1
0
        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);
                }
            }
        }
Exemplo n.º 2
0
        public void ApiCreateBlockInstance(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 = new Rock.CMS.BlockInstance();
                    BlockInstanceService.Add(existingBlockInstance, user.PersonId);
                    uow.objectContext.Entry(existingBlockInstance).CurrentValues.SetValues(BlockInstance);

                    if (existingBlockInstance.IsValid)
                    {
                        BlockInstanceService.Save(existingBlockInstance, user.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>(existingBlockInstance.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Exemplo n.º 3
0
        public void ApiCreateBlockInstance( 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 = new Rock.CMS.BlockInstance();
                    BlockInstanceService.Add( existingBlockInstance, user.PersonId );
                    uow.objectContext.Entry(existingBlockInstance).CurrentValues.SetValues(BlockInstance);

                    if (existingBlockInstance.IsValid)
                        BlockInstanceService.Save( existingBlockInstance, user.PersonId );
                    else
                        throw new WebFaultException<string>( existingBlockInstance.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
Exemplo n.º 4
0
        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 );
            }
        }
Exemplo n.º 5
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Rock.CMS.BlockInstance blockInstance;

            int blockInstanceId = 0;

            if (!Int32.TryParse(hfBlockInstanceId.Value, out blockInstanceId))
            {
                blockInstanceId = 0;
            }

            if (blockInstanceId == 0)
            {
                blockInstance = new Rock.CMS.BlockInstance();

                Rock.Web.Cache.BlockInstanceLocation location = hfBlockLocation.Value.ConvertToEnum <Rock.Web.Cache.BlockInstanceLocation>();
                if (location == Rock.Web.Cache.BlockInstanceLocation.Layout)
                {
                    blockInstance.Layout = _page.Layout;
                    blockInstance.PageId = null;
                }
                else
                {
                    blockInstance.Layout = null;
                    blockInstance.PageId = _page.Id;
                }

                blockInstance.Zone = _zoneName;

                Rock.CMS.BlockInstance lastBlock =
                    blockInstanceService.GetByLayoutAndPageIdAndZone(null, _page.Id, _zoneName).
                    OrderByDescending(b => b.Order).FirstOrDefault();

                if (lastBlock != null)
                {
                    blockInstance.Order = lastBlock.Order + 1;
                }
                else
                {
                    blockInstance.Order = 0;
                }

                blockInstanceService.Add(blockInstance, CurrentPersonId);
            }
            else
            {
                blockInstance = blockInstanceService.Get(blockInstanceId);
            }

            blockInstance.Name    = tbBlockName.Text;
            blockInstance.BlockId = Convert.ToInt32(ddlBlockType.SelectedValue);

            blockInstanceService.Save(blockInstance, CurrentPersonId);

            Rock.Security.Authorization.CopyAuthorization(_page, blockInstance, CurrentPersonId);
            _page.FlushBlockInstances();

            BindGrids();

            pnlDetails.Visible = false;
            pnlLists.Visible   = true;
        }