コード例 #1
0
        // PUT: /api/contactinfo
        public void Put([FromBody] ContactInfoViewModel contactInfoViewModel)
        {
            // Get Person data model from the data service
            // we do not need account nor transactions
            var person = service.GetPersonByUsername(authenticatedUser, new PersonIncludes { Accounts = false, Addressses = false, Phones = false, AccountTransactions = false });

            // Update the Email Address in the person model
            person.EmailAddress = contactInfoViewModel.EmailAddress;

            person.Phones = new List<Phone>();
            person.Addresses = new List<PersonAddressAssn>();

            // Add the phone numbers to the person model
            foreach(PhoneViewModel phoneViewModel in contactInfoViewModel.PhoneNumbers)
            {
                if (!string.IsNullOrEmpty(phoneViewModel.Number))
                {
                    var phone = new Phone
                    {
                        PhoneTypeID = phoneViewModel.PhoneTypeID,
                        Number = phoneViewModel.Number
                    };
                    person.Phones.Add(phone);
                }                
            }

            // Add the addresses to the person model
            foreach(AddressViewModel addressViewModel in contactInfoViewModel.Addresses)
            {
                if (!string.IsNullOrEmpty(addressViewModel.StreetAddress))
                {
                    var address = new PersonAddressAssn
                    {
                        AddressTypeID = addressViewModel.AddressTypeID,
                        Address = new Address
                        {
                            StreetAddress = addressViewModel.StreetAddress,
                            City = addressViewModel.City,
                            State = addressViewModel.State,
                            Zip = addressViewModel.Zip
                        }
                    };
                    person.Addresses.Add(address);
                }                
            }

            // Update the data store
            var oppStatus = service.UpdatePerson(person);

            // Return success or error state
            if (!oppStatus.Success)
            {
                throw new Exception(oppStatus.Messages[0]);
            }
        }
コード例 #2
0
        private void updatePhone(Person person, Person updatedPerson, int phoneType, IFootlooseFSUnitOfWork unitOfWork)
        {
            var updatePhone = updatedPerson.Phones.Where(p => p.PhoneTypeID == phoneType).FirstOrDefault();
            if (updatePhone == null)
            {
                var phone = person.Phones.Where(p => p.PhoneTypeID == phoneType).FirstOrDefault();
                if (phone != null)
                    unitOfWork.Phones.Delete(phone);
            }
            else
            {
                var phone = person.Phones.Where(p => p.PhoneTypeID == phoneType).FirstOrDefault();
                if (phone == null)
                {
                    phone = new Phone();
                    phone.PersonID = updatePhone.PersonID;
                    phone.PhoneTypeID = updatePhone.PhoneTypeID;
                    person.Phones.Add(phone);
                }

                phone.Number = updatePhone.Number;
            }
        }