Пример #1
0
        public void UpdateEntityChange(string id, 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 = EntityChangeService.Get(int.Parse(id));
                if (existingEntityChange.Authorized("Edit", currentUser))
                {
                    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);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this EntityChange", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #2
0
        public Rock.Core.DTO.EntityChange 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.EntityChangeService EntityChangeService = new Rock.Core.EntityChangeService();
                    Rock.Core.EntityChange        EntityChange        = EntityChangeService.Get(int.Parse(id));
                    if (EntityChange.Authorized("View", user))
                    {
                        return(EntityChange.DataTransferObject);
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to View this EntityChange", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #3
0
        public void DeleteEntityChange(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.EntityChangeService EntityChangeService = new Rock.Core.EntityChangeService();
                Rock.Core.EntityChange        EntityChange        = EntityChangeService.Get(int.Parse(id));
                if (EntityChange.Authorized("Edit", currentUser))
                {
                    EntityChangeService.Delete(EntityChange, currentUser.PersonId);
                    EntityChangeService.Save(EntityChange, currentUser.PersonId);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this EntityChange", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #4
0
        public Rock.Core.DTO.EntityChange 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.EntityChangeService EntityChangeService = new Rock.Core.EntityChangeService();
                Rock.Core.EntityChange        EntityChange        = EntityChangeService.Get(int.Parse(id));
                if (EntityChange.Authorized("View", currentUser))
                {
                    return(EntityChange.DataTransferObject);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to View this EntityChange", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #5
0
        public void ApiUpdateEntityChange(string id, 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 = EntityChangeService.Get(int.Parse(id));
                    if (existingEntityChange.Authorized("Edit", user))
                    {
                        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>("Not Authorized to Edit this EntityChange", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }