Ejemplo 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);
                }
            }
        }
Ejemplo 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);
                }
            }
        }
Ejemplo n.º 3
0
        public CampReservationDTO SaveCampReservation(CampReservationDTO campReservation, int eventId, string token)
        {
            var nickName  = string.IsNullOrWhiteSpace(campReservation.PreferredName) ? campReservation.FirstName : campReservation.PreferredName;
            var contactId = Convert.ToInt32(campReservation.ContactId);

            var minorContact = new MpContact
            {
                FirstName           = campReservation.FirstName,
                LastName            = campReservation.LastName,
                PreferredName       = $"{campReservation.LastName}, {campReservation.FirstName}",
                MiddleName          = campReservation.MiddleName,
                MobilePhone         = campReservation.MobilePhone,
                BirthDate           = Convert.ToDateTime(campReservation.BirthDate),
                Gender              = campReservation.Gender,
                Nickname            = nickName,
                SchoolAttending     = campReservation.SchoolAttending,
                HouseholdId         = (_contactRepository.GetMyProfile(token)).Household_ID,
                HouseholdPositionId = 2
            };

            MpParticipant participant;

            if (campReservation.ContactId == null || campReservation.ContactId == 0)
            {
                var newMinorContact = _contactRepository.CreateContact(minorContact);
                contactId   = newMinorContact[0].RecordId;
                participant = _participantRepository.GetParticipant(contactId);
                campReservation.ContactId = contactId;
            }
            else
            {
                var updateToDictionary = new Dictionary <String, Object>
                {
                    { "Contact_ID", Convert.ToInt32(campReservation.ContactId) },
                    { "First_Name", minorContact.FirstName },
                    { "Last_Name", minorContact.LastName },
                    { "Middle_Name", minorContact.MiddleName },
                    { "Nickname", nickName },
                    { "Mobile_Phone", minorContact.MobilePhone },
                    { "Gender_ID", campReservation.Gender },
                    { "Date_Of_Birth", minorContact.BirthDate },
                    { "Current_School", minorContact.SchoolAttending },
                    { "Congregation_Name", (_congregationRepository.GetCongregationById(campReservation.CrossroadsSite)).Name }
                };

                _contactRepository.UpdateContact(Convert.ToInt32(campReservation.ContactId), updateToDictionary);
                participant = _participantRepository.GetParticipant(Convert.ToInt32(campReservation.ContactId));
            }

            // Save shirt size if set
            var configuration = MpObjectAttributeConfigurationFactory.Contact();

            _objectAttributeService.SaveObjectAttributes(contactId, campReservation.AttributeTypes, campReservation.SingleAttributes, configuration);

            // Save students in selected grade group
            var group = _groupRepository.GetGradeGroupForContact(contactId, _apiUserRepository.GetToken());

            if (group.Status && group.Value.GroupId != campReservation.CurrentGrade)
            {
                _groupRepository.endDateGroupParticipant(group.Value.GroupParticipantId, group.Value.GroupId, DateTime.Now);
                _groupRepository.addParticipantToGroup(participant.ParticipantId,
                                                       campReservation.CurrentGrade,
                                                       _configurationWrapper.GetConfigIntValue("Group_Role_Default_ID"),
                                                       false,
                                                       DateTime.Now);
            }
            else if (!group.Status)
            {
                _groupRepository.addParticipantToGroup(participant.ParticipantId,
                                                       campReservation.CurrentGrade,
                                                       _configurationWrapper.GetConfigIntValue("Group_Role_Default_ID"),
                                                       false,
                                                       DateTime.Now);
            }

            // Check if this person is already an event participant
            var eventParticipant = _eventParticipantRepository.GetEventParticipantEligibility(eventId, contactId);
            var currentlyActive  = (eventParticipant != null && (eventParticipant.EndDate == null || eventParticipant.EndDate >= DateTime.Now));
            var rulesPass        = true;

            if (!currentlyActive)
            {
                rulesPass = _campRules.VerifyCampRules(eventId, campReservation.Gender);
            }

            // ALL OF THE BELOW CODE SHOULD ONLY HAPPEN IF THE RULES PASS
            if (rulesPass)
            {
                //Create eventParticipant
                int eventParticipantId;

                // This is a new event participant, determine their pending timeout and create their entry in the database
                if (eventParticipant == null)
                {
                    var endDate = DetermineEndDate(eventId);
                    eventParticipantId = _eventRepository.RegisterInterestedParticipantWithEndDate(participant.ParticipantId, eventId, endDate);
                }
                else
                {
                    eventParticipantId = eventParticipant.EventParticipantId;

                    // If the participant had previously started an application which expired, update its End Date now
                    if (eventParticipant.EndDate != null && eventParticipant.EndDate < DateTime.Now)
                    {
                        var endDate = DetermineEndDate(eventId);
                        _eventRepository.UpdateParticipantEndDate(eventParticipantId, endDate);
                    }
                }
                var crossroadsSite = _congregationRepository.GetCongregationById(campReservation.CrossroadsSite);

                //form response
                var answers = new List <MpFormAnswer>
                {
                    new MpFormAnswer
                    {
                        Response           = campReservation.SchoolAttendingNext,
                        FieldId            = _configurationWrapper.GetConfigIntValue("SummerCampForm.SchoolAttendingNextYear"),
                        EventParticipantId = eventParticipantId
                    },
                    new MpFormAnswer
                    {
                        Response           = campReservation.RoomMate,
                        FieldId            = _configurationWrapper.GetConfigIntValue("SummerCampForm.PreferredRoommate"),
                        EventParticipantId = eventParticipantId
                    },
                    new MpFormAnswer
                    {
                        Response           = crossroadsSite.Name,
                        FieldId            = _configurationWrapper.GetConfigIntValue("SummerCampForm.CamperCongregation"),
                        EventParticipantId = eventParticipantId
                    }
                };

                var formId       = _configurationWrapper.GetConfigIntValue("SummerCampFormID");
                var formResponse = new MpFormResponse
                {
                    ContactId   = contactId,
                    FormId      = formId,
                    FormAnswers = answers,
                    EventId     = eventId
                };

                _formSubmissionRepository.SubmitFormResponse(formResponse);
                return(campReservation);
            }
            throw new ApplicationException("Rules do not pass!");
        }