Пример #1
0
        public void UpdatePhoneNumber(string id, Rock.CRM.DTO.PhoneNumber PhoneNumber)
        {
            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.PhoneNumberService PhoneNumberService  = new Rock.CRM.PhoneNumberService();
                Rock.CRM.PhoneNumber        existingPhoneNumber = PhoneNumberService.Get(int.Parse(id));
                if (existingPhoneNumber.Authorized("Edit", currentUser))
                {
                    uow.objectContext.Entry(existingPhoneNumber).CurrentValues.SetValues(PhoneNumber);

                    if (existingPhoneNumber.IsValid)
                    {
                        PhoneNumberService.Save(existingPhoneNumber, currentUser.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>(existingPhoneNumber.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this PhoneNumber", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #2
0
        public Rock.CRM.DTO.PhoneNumber 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.PhoneNumberService PhoneNumberService = new Rock.CRM.PhoneNumberService();
                    Rock.CRM.PhoneNumber        PhoneNumber        = PhoneNumberService.Get(int.Parse(id));
                    if (PhoneNumber.Authorized("View", user))
                    {
                        return(PhoneNumber.DataTransferObject);
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to View this PhoneNumber", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #3
0
        public void ApiDeletePhoneNumber(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.PhoneNumberService PhoneNumberService = new Rock.CRM.PhoneNumberService();
                    Rock.CRM.PhoneNumber        PhoneNumber        = PhoneNumberService.Get(int.Parse(id));
                    if (PhoneNumber.Authorized("Edit", user))
                    {
                        PhoneNumberService.Delete(PhoneNumber, user.PersonId);
                        PhoneNumberService.Save(PhoneNumber, user.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to Edit this PhoneNumber", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #4
0
        public void DeletePhoneNumber(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.PhoneNumberService PhoneNumberService = new Rock.CRM.PhoneNumberService();
                Rock.CRM.PhoneNumber        PhoneNumber        = PhoneNumberService.Get(int.Parse(id));
                if (PhoneNumber.Authorized("Edit", currentUser))
                {
                    PhoneNumberService.Delete(PhoneNumber, currentUser.PersonId);
                    PhoneNumberService.Save(PhoneNumber, currentUser.PersonId);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this PhoneNumber", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #5
0
        public Rock.CRM.DTO.PhoneNumber 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.PhoneNumberService PhoneNumberService = new Rock.CRM.PhoneNumberService();
                Rock.CRM.PhoneNumber        PhoneNumber        = PhoneNumberService.Get(int.Parse(id));
                if (PhoneNumber.Authorized("View", currentUser))
                {
                    return(PhoneNumber.DataTransferObject);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to View this PhoneNumber", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #6
0
        public void ApiUpdatePhoneNumber(string id, string apiKey, Rock.CRM.DTO.PhoneNumber PhoneNumber)
        {
            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.PhoneNumberService PhoneNumberService  = new Rock.CRM.PhoneNumberService();
                    Rock.CRM.PhoneNumber        existingPhoneNumber = PhoneNumberService.Get(int.Parse(id));
                    if (existingPhoneNumber.Authorized("Edit", user))
                    {
                        uow.objectContext.Entry(existingPhoneNumber).CurrentValues.SetValues(PhoneNumber);

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