예제 #1
0
        public void UpdateDefinedType(string id, Rock.Core.DTO.DefinedType DefinedType)
        {
            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.DefinedTypeService DefinedTypeService  = new Rock.Core.DefinedTypeService();
                Rock.Core.DefinedType        existingDefinedType = DefinedTypeService.Get(int.Parse(id));
                if (existingDefinedType.Authorized("Edit", currentUser))
                {
                    uow.objectContext.Entry(existingDefinedType).CurrentValues.SetValues(DefinedType);

                    if (existingDefinedType.IsValid)
                    {
                        DefinedTypeService.Save(existingDefinedType, currentUser.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>(existingDefinedType.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this DefinedType", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
예제 #2
0
        public Rock.Core.DTO.DefinedType 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.Core.DefinedTypeService DefinedTypeService = new Rock.Core.DefinedTypeService();
                    Rock.Core.DefinedType        DefinedType        = DefinedTypeService.Get(int.Parse(id));
                    if (DefinedType.Authorized("View", user))
                    {
                        return(DefinedType.DataTransferObject);
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to View this DefinedType", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
예제 #3
0
        public void DeleteDefinedType(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.DefinedTypeService DefinedTypeService = new Rock.Core.DefinedTypeService();
                Rock.Core.DefinedType        DefinedType        = DefinedTypeService.Get(int.Parse(id));
                if (DefinedType.Authorized("Edit", currentUser))
                {
                    DefinedTypeService.Delete(DefinedType, currentUser.PersonId);
                    DefinedTypeService.Save(DefinedType, currentUser.PersonId);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this DefinedType", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
예제 #4
0
        public void ApiCreateDefinedType(string apiKey, Rock.Core.DTO.DefinedType DefinedType)
        {
            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.DefinedTypeService DefinedTypeService  = new Rock.Core.DefinedTypeService();
                    Rock.Core.DefinedType        existingDefinedType = new Rock.Core.DefinedType();
                    DefinedTypeService.Add(existingDefinedType, user.PersonId);
                    uow.objectContext.Entry(existingDefinedType).CurrentValues.SetValues(DefinedType);

                    if (existingDefinedType.IsValid)
                    {
                        DefinedTypeService.Save(existingDefinedType, user.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>(existingDefinedType.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
예제 #5
0
        public Rock.Core.DTO.DefinedType 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.DefinedTypeService DefinedTypeService = new Rock.Core.DefinedTypeService();
                Rock.Core.DefinedType        DefinedType        = DefinedTypeService.Get(int.Parse(id));
                if (DefinedType.Authorized("View", currentUser))
                {
                    return(DefinedType.DataTransferObject);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to View this DefinedType", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }