Exemple #1
0
        /// <summary>
        /// Add a placemark object to a profile. If the placemark is a PersonPlacemark
        /// then the associated person record is used. If it is a FamilyPlacemark then
        /// all the members of the family are used. Otherwise the placemark is ignored.
        /// This method only adds individuals who are not already a member of the tag.
        /// </summary>
        /// <param name="placemark">The placemark to add to the profile.</param>
        /// <param name="profile">The profile to add the members to.</param>
        private void AddPlacemarkToProfile(Placemark placemark, Profile profile)
        {
            List <Person> people = new List <Person>();


            //
            // Convert the placemark into a list of people that should be added.
            //
            if (placemark.GetType() == typeof(PersonPlacemark))
            {
                people.Add(((PersonPlacemark)placemark).GetPerson());
            }
            else if (placemark.GetType() == typeof(FamilyPlacemark))
            {
                foreach (Person p in ((FamilyPlacemark)placemark).GetFamily().FamilyMembersActive)
                {
                    people.Add(p);
                }
            }

            //
            // For each person found, verify that they should be added and then
            // add them if they are not already in the profile.
            //
            foreach (Person p in people)
            {
                ProfileMember pm;

                //
                // Verify they are an adult if the user wants only adults.
                //
                if (profileOnlyAdults.Checked == true)
                {
                    FamilyMember fm = new FamilyMember(p.FamilyId, p.PersonID);

                    if (!fm.FamilyRole.Guid.ToString().Equals("e410e1a6-8715-4bfb-bf03-1cd18051f815", StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }
                }

                //
                // Verify they are not already in the profile.
                //
                pm = new ProfileMember(profile.ProfileID, p);
                if (pm.ProfileID == -1)
                {
                    pm = new ProfileMember();

                    //
                    // Add them to the profile.
                    //
                    pm.ProfileID  = profile.ProfileID;
                    pm.PersonID   = p.PersonID;
                    pm.Source     = ProfileSource;
                    pm.Status     = ProfileStatus;
                    pm.DateActive = DateTime.Now;
                    pm.Save(ArenaContext.Current.User.Identity.Name);

                    //
                    // If this is a serving profile, we need a little more information.
                    //
                    if (profile.ProfileType == Enums.ProfileType.Serving)
                    {
                        ServingProfile       sp  = new ServingProfile(profile.ProfileID);
                        ServingProfileMember spm = new ServingProfileMember(pm.ProfileID, pm.PersonID);

                        spm.HoursPerWeek = sp.DefaultHoursPerWeek;
                        spm.Save(ArenaContext.Current.User.Identity.Name);
                    }
                }
            }
        }