public void ApiCreatePageRoute(string apiKey, Rock.CMS.DTO.PageRoute PageRoute)
        {
            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.PageRouteService PageRouteService  = new Rock.CMS.PageRouteService();
                    Rock.CMS.PageRoute        existingPageRoute = new Rock.CMS.PageRoute();
                    PageRouteService.Add(existingPageRoute, user.PersonId);
                    uow.objectContext.Entry(existingPageRoute).CurrentValues.SetValues(PageRoute);

                    if (existingPageRoute.IsValid)
                    {
                        PageRouteService.Save(existingPageRoute, user.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>(existingPageRoute.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
        public void CreatePageRoute(Rock.CMS.DTO.PageRoute PageRoute)
        {
            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.PageRouteService PageRouteService  = new Rock.CMS.PageRouteService();
                Rock.CMS.PageRoute        existingPageRoute = new Rock.CMS.PageRoute();
                PageRouteService.Add(existingPageRoute, currentUser.PersonId);
                uow.objectContext.Entry(existingPageRoute).CurrentValues.SetValues(PageRoute);

                if (existingPageRoute.IsValid)
                {
                    PageRouteService.Save(existingPageRoute, currentUser.PersonId);
                }
                else
                {
                    throw new WebFaultException <string>(existingPageRoute.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                }
            }
        }
Beispiel #3
0
        public void ApiCreatePageRoute( string apiKey, Rock.CMS.DTO.PageRoute PageRoute )
        {
            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.PageRouteService PageRouteService = new Rock.CMS.PageRouteService();
                    Rock.CMS.PageRoute existingPageRoute = new Rock.CMS.PageRoute();
                    PageRouteService.Add( existingPageRoute, user.PersonId );
                    uow.objectContext.Entry(existingPageRoute).CurrentValues.SetValues(PageRoute);

                    if (existingPageRoute.IsValid)
                        PageRouteService.Save( existingPageRoute, user.PersonId );
                    else
                        throw new WebFaultException<string>( existingPageRoute.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
Beispiel #4
0
        public void CreatePageRoute( Rock.CMS.DTO.PageRoute PageRoute )
        {
            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.PageRouteService PageRouteService = new Rock.CMS.PageRouteService();
                Rock.CMS.PageRoute existingPageRoute = new Rock.CMS.PageRoute();
                PageRouteService.Add( existingPageRoute, currentUser.PersonId );
                uow.objectContext.Entry(existingPageRoute).CurrentValues.SetValues(PageRoute);

                if (existingPageRoute.IsValid)
                    PageRouteService.Save( existingPageRoute, currentUser.PersonId );
                else
                    throw new WebFaultException<string>( existingPageRoute.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
            }
        }