Exemplo n.º 1
0
        public void SetProfile(string token, Person person)
        {
            var contactDictionary = getDictionary(person.GetContact());
            var householdDictionary = getDictionary(person.GetHousehold());
            var addressDictionary = getDictionary(person.GetAddress());
            addressDictionary.Add("State/Region", addressDictionary["State"]);

            // Some front-end consumers require an Address (e.g., /profile/personal), and
            // some do not (e.g., /undivided/facilitator).  Don't attempt to create/update
            // an Address record if we have no data.
            if (addressDictionary.Values.All(i => i == null))
            {
                addressDictionary = null;
            }

            _contactRepository.UpdateContact(person.ContactId, contactDictionary, householdDictionary, addressDictionary);
            var configuration = MpObjectAttributeConfigurationFactory.Contact();            
            _objectAttributeService.SaveObjectAttributes(person.ContactId, person.AttributeTypes, person.SingleAttributes, configuration);

            var participant = _participantService.GetParticipant(person.ContactId);
            if (participant.AttendanceStart != person.AttendanceStartDate)
            {                
                participant.AttendanceStart = person.AttendanceStartDate;
                _participantService.UpdateParticipant(participant);
            }

            // TODO: It appears we are updating the contact records email address above if the email address is changed
            // TODO: If the password is invalid we would not run the update on user, and therefore create a data integrity problem
            // TODO: See About moving the check for new password above or moving the update for user / person into an atomic operation
            //
            // update the user values if the email and/or password has changed
            if (!(String.IsNullOrEmpty(person.NewPassword)) || (person.EmailAddress != person.OldEmail && person.OldEmail != null))
            {
                var authData = _authenticationService.Authenticate(person.OldEmail, person.OldPassword);

                if (authData == null)
                {
                    throw new Exception("Old password did not match profile");
                }
                else
                {
                    var userUpdateValues = person.GetUserUpdateValues();
                    userUpdateValues["User_ID"] = _userRepository.GetUserIdByUsername(person.OldEmail);
                    _userRepository.UpdateUser(userUpdateValues);
                }
            }
        }
Exemplo n.º 2
0
        public void SetProfile(String token, Person person)
        {
            var contactDictionary   = getDictionary(person.GetContact());
            var householdDictionary = getDictionary(person.GetHousehold());
            var addressDictionary   = getDictionary(person.GetAddress());

            addressDictionary.Add("State/Region", addressDictionary["State"]);
            _contactService.UpdateContact(person.ContactId, contactDictionary, householdDictionary, addressDictionary);

            var configuration = MpObjectAttributeConfigurationFactory.Contact();

            _objectAttributeService.SaveObjectAttributes(person.ContactId, person.AttributeTypes, person.SingleAttributes, configuration);

            var participant = _participantService.GetParticipant(person.ContactId);

            if (participant.AttendanceStart != person.AttendanceStartDate)
            {
                participant.AttendanceStart = person.AttendanceStartDate;
                _participantService.UpdateParticipant(participant);
            }

            // TODO: It appears we are updating the contact records email address above if the email address is changed
            // TODO: If the password is invalid we would not run the update on user, and therefore create a data integrity problem
            // TODO: See About moving the check for new password above or moving the update for user / person into an atomic operation
            //
            // update the user values if the email and/or password has changed
            if (!(String.IsNullOrEmpty(person.NewPassword)) || (person.EmailAddress != person.OldEmail && person.OldEmail != null))
            {
                var authData = TranslationService.Login(person.OldEmail, person.OldPassword);

                if (authData == null)
                {
                    throw new Exception("Old password did not match profile");
                }
                else
                {
                    var userUpdateValues = person.GetUserUpdateValues();
                    userUpdateValues["User_ID"] = _userService.GetUserIdByUsername(person.OldEmail);
                    _userService.UpdateUser(userUpdateValues);
                }
            }
        }