Beispiel #1
0
        public void UpdateSite(string id, Rock.CMS.DTO.Site Site)
        {
            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.SiteService SiteService  = new Rock.CMS.SiteService();
                Rock.CMS.Site        existingSite = SiteService.Get(int.Parse(id));
                if (existingSite.Authorized("Edit", currentUser))
                {
                    uow.objectContext.Entry(existingSite).CurrentValues.SetValues(Site);

                    if (existingSite.IsValid)
                    {
                        SiteService.Save(existingSite, currentUser.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>(existingSite.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this Site", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Beispiel #2
0
        public Rock.CMS.DTO.Site 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.SiteService SiteService = new Rock.CMS.SiteService();
                    Rock.CMS.Site        Site        = SiteService.Get(int.Parse(id));
                    if (Site.Authorized("View", user))
                    {
                        return(Site.DataTransferObject);
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to View this Site", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Beispiel #3
0
        public void ApiDeleteSite(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.SiteService SiteService = new Rock.CMS.SiteService();
                    Rock.CMS.Site        Site        = SiteService.Get(int.Parse(id));
                    if (Site.Authorized("Edit", user))
                    {
                        SiteService.Delete(Site, user.PersonId);
                        SiteService.Save(Site, user.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to Edit this Site", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Beispiel #4
0
        public void DeleteSite(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.SiteService SiteService = new Rock.CMS.SiteService();
                Rock.CMS.Site        Site        = SiteService.Get(int.Parse(id));
                if (Site.Authorized("Edit", currentUser))
                {
                    SiteService.Delete(Site, currentUser.PersonId);
                    SiteService.Save(Site, currentUser.PersonId);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this Site", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Beispiel #5
0
        public Rock.CMS.DTO.Site 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.SiteService SiteService = new Rock.CMS.SiteService();
                Rock.CMS.Site        Site        = SiteService.Get(int.Parse(id));
                if (Site.Authorized("View", currentUser))
                {
                    return(Site.DataTransferObject);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to View this Site", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Beispiel #6
0
        public void ApiUpdateSite(string id, string apiKey, Rock.CMS.DTO.Site Site)
        {
            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.SiteService SiteService  = new Rock.CMS.SiteService();
                    Rock.CMS.Site        existingSite = SiteService.Get(int.Parse(id));
                    if (existingSite.Authorized("Edit", user))
                    {
                        uow.objectContext.Entry(existingSite).CurrentValues.SetValues(Site);

                        if (existingSite.IsValid)
                        {
                            SiteService.Save(existingSite, user.PersonId);
                        }
                        else
                        {
                            throw new WebFaultException <string>(existingSite.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                        }
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to Edit this Site", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }