Exemplo n.º 1
0
        public void ApiCreatePhoneNumber(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 = new Rock.CRM.PhoneNumber();
                    PhoneNumberService.Add(existingPhoneNumber, user.PersonId);
                    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>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Exemplo n.º 2
0
        public void CreatePhoneNumber(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 = new Rock.CRM.PhoneNumber();
                PhoneNumberService.Add(existingPhoneNumber, currentUser.PersonId);
                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);
                }
            }
        }