Example #1
0
        public Rock.CRM.DTO.PersonTrail 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.CRM.PersonTrailService PersonTrailService = new Rock.CRM.PersonTrailService();
                    Rock.CRM.PersonTrail        PersonTrail        = PersonTrailService.Get(int.Parse(id));
                    if (PersonTrail.Authorized("View", user))
                    {
                        return(PersonTrail.DataTransferObject);
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to View this PersonTrail", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Example #2
0
        public void UpdatePersonTrail(string id, Rock.CRM.DTO.PersonTrail PersonTrail)
        {
            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.CRM.PersonTrailService PersonTrailService  = new Rock.CRM.PersonTrailService();
                Rock.CRM.PersonTrail        existingPersonTrail = PersonTrailService.Get(int.Parse(id));
                if (existingPersonTrail.Authorized("Edit", currentUser))
                {
                    uow.objectContext.Entry(existingPersonTrail).CurrentValues.SetValues(PersonTrail);

                    if (existingPersonTrail.IsValid)
                    {
                        PersonTrailService.Save(existingPersonTrail, currentUser.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>(existingPersonTrail.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this PersonTrail", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Example #3
0
        public void DeletePersonTrail(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.CRM.PersonTrailService PersonTrailService = new Rock.CRM.PersonTrailService();
                Rock.CRM.PersonTrail        PersonTrail        = PersonTrailService.Get(int.Parse(id));
                if (PersonTrail.Authorized("Edit", currentUser))
                {
                    PersonTrailService.Delete(PersonTrail, currentUser.PersonId);
                    PersonTrailService.Save(PersonTrail, currentUser.PersonId);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this PersonTrail", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Example #4
0
        public void ApiCreatePersonTrail(string apiKey, Rock.CRM.DTO.PersonTrail PersonTrail)
        {
            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.CRM.PersonTrailService PersonTrailService  = new Rock.CRM.PersonTrailService();
                    Rock.CRM.PersonTrail        existingPersonTrail = new Rock.CRM.PersonTrail();
                    PersonTrailService.Add(existingPersonTrail, user.PersonId);
                    uow.objectContext.Entry(existingPersonTrail).CurrentValues.SetValues(PersonTrail);

                    if (existingPersonTrail.IsValid)
                    {
                        PersonTrailService.Save(existingPersonTrail, user.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>(existingPersonTrail.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Example #5
0
        public Rock.CRM.DTO.PersonTrail 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.CRM.PersonTrailService PersonTrailService = new Rock.CRM.PersonTrailService();
                Rock.CRM.PersonTrail        PersonTrail        = PersonTrailService.Get(int.Parse(id));
                if (PersonTrail.Authorized("View", currentUser))
                {
                    return(PersonTrail.DataTransferObject);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to View this PersonTrail", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Example #6
0
        public void ApiCreatePersonTrail( string apiKey, Rock.CRM.DTO.PersonTrail PersonTrail )
        {
            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.CRM.PersonTrailService PersonTrailService = new Rock.CRM.PersonTrailService();
                    Rock.CRM.PersonTrail existingPersonTrail = new Rock.CRM.PersonTrail();
                    PersonTrailService.Add( existingPersonTrail, user.PersonId );
                    uow.objectContext.Entry(existingPersonTrail).CurrentValues.SetValues(PersonTrail);

                    if (existingPersonTrail.IsValid)
                        PersonTrailService.Save( existingPersonTrail, user.PersonId );
                    else
                        throw new WebFaultException<string>( existingPersonTrail.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
Example #7
0
        public void CreatePersonTrail( Rock.CRM.DTO.PersonTrail PersonTrail )
        {
            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.CRM.PersonTrailService PersonTrailService = new Rock.CRM.PersonTrailService();
                Rock.CRM.PersonTrail existingPersonTrail = new Rock.CRM.PersonTrail();
                PersonTrailService.Add( existingPersonTrail, currentUser.PersonId );
                uow.objectContext.Entry(existingPersonTrail).CurrentValues.SetValues(PersonTrail);

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