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); } } }
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); } } }