Esempio n. 1
0
        public Object GetProfileList(String profileID, String profileType, int start, int max, String fields)
        {
            ProfileCollection profiles = null;

            Contracts.ProfileMapper mapper = null;
            Contracts.GenericListResult <Contracts.Profile>          listP = new Contracts.GenericListResult <Contracts.Profile>();
            Contracts.GenericListResult <Contracts.GenericReference> listR = new Contracts.GenericListResult <Contracts.GenericReference>();
            int i;


            if (profileType != null)
            {
                profiles = new ProfileCollection();
                profiles.LoadChildProfiles(-1, RestApi.DefaultOrganizationID(), (Arena.Enums.ProfileType)Convert.ToInt32(profileType), ArenaContext.Current.Person.PersonID);
            }
            else if (profileID != null)
            {
                Profile profile;

                if (RestApi.ProfileOperationAllowed(ArenaContext.Current.Person.PersonID, Convert.ToInt32(profileID), OperationType.View) == false)
                {
                    throw new Exception("Access denied.");
                }

                profile  = new Profile(Convert.ToInt32(profileID));
                profiles = profile.ChildProfiles;
            }
            else
            {
                throw new Exception("Required parameters not provided.");
            }

            //
            // Sort the list of profiles and determine if we are going to
            // be returning references or full objects.
            //
            profiles.Sort(delegate(Profile p1, Profile p2) { return(p1.Name.CompareTo(p2.Name)); });
            mapper = (string.IsNullOrEmpty(fields) ? null : new Contracts.ProfileMapper(new List <string>(fields.Split(','))));

            //
            // Prepare the appropraite list object.
            //
            if (mapper != null)
            {
                listP.Start = start;
                listP.Max   = max;
                listP.Total = 0;
                listP.Items = new List <Contracts.Profile>();
            }
            else
            {
                listR.Start = start;
                listR.Max   = max;
                listR.Total = 0;
                listR.Items = new List <Contracts.GenericReference>();
            }
            for (i = 0; i < profiles.Count; i++)
            {
                if (RestApi.ProfileOperationAllowed(ArenaContext.Current.Person.PersonID, profiles[i].ProfileID, OperationType.View) == false)
                {
                    continue;
                }

                if (mapper != null)
                {
                    if (listP.Total >= start && (max <= 0 ? true : listP.Items.Count < max))
                    {
                        listP.Items.Add(mapper.FromArena(profiles[i]));
                    }
                    listP.Total += 1;
                }
                else
                {
                    if (listR.Total >= start && (max <= 0 ? true : listR.Items.Count < max))
                    {
                        listR.Items.Add(new Contracts.GenericReference(profiles[i]));
                    }
                    listR.Total += 1;
                }
            }

            return(mapper != null ? (Object)listP : (Object)listR);
        }
Esempio n. 2
0
        public Contracts.GenericListResult <Contracts.ProfileMember> GetPersonProfileMembership(int id, int type, string inactive, int start, int max)
        {
            Contracts.GenericListResult <Contracts.ProfileMember> list = new Contracts.GenericListResult <Contracts.ProfileMember>();
            ProfileCollection pmc = new ProfileCollection();
            bool activeOnly       = true;
            int  i;


            //
            // Check if they want to include inactive records.
            //
            try
            {
                if (Convert.ToInt32(inactive) == 1)
                {
                    activeOnly = false;
                }
            }
            catch { }

            //
            // Check general.
            //
            if (type == (int)Enums.ProfileType.Ministry && RestApi.PersonFieldOperationAllowed(ArenaContext.Current.Person.PersonID, PersonFields.Activity_Ministry_Tags, OperationType.View) == false)
            {
                throw new Exception("Access denied");
            }
            else if (type == (int)Enums.ProfileType.Serving && RestApi.PersonFieldOperationAllowed(ArenaContext.Current.Person.PersonID, PersonFields.Activity_Serving_Tags, OperationType.View) == false)
            {
                throw new Exception("Access denied");
            }
            else if (type != (int)Enums.ProfileType.Personal && type != (int)Enums.ProfileType.Ministry && type != (int)Enums.ProfileType.Serving)
            {
                throw new Exception("Access denied");
            }

            //
            // If they are requesting membership in their own personal profiles
            // then retrieve those, otherwise retrieve the general profile
            // information.
            //
            if (type == (int)Enums.ProfileType.Personal)
            {
                pmc.LoadMemberPrivateProfiles(RestApi.DefaultOrganizationID(), ArenaContext.Current.Person.PersonID, id, activeOnly);
            }
            else
            {
                pmc.LoadMemberProfiles(RestApi.DefaultOrganizationID(), (Enums.ProfileType)type, id, activeOnly);
            }

            list.Items = new List <Contracts.ProfileMember>();
            list.Start = start;
            list.Max   = max;
            foreach (Profile p in pmc)
            {
                if (RestApi.ProfileOperationAllowed(ArenaContext.Current.Person.PersonID, p.ProfileID, OperationType.View) == false)
                {
                    continue;
                }

                if (list.Total >= start && list.Items.Count < max)
                {
                    list.Items.Add(new Contracts.ProfileMember(new ProfileMember(p.ProfileID, id)));
                }
                list.Total += 1;
            }

            return(list);
        }
Esempio n. 3
0
        GetProfileMemberActivity(int profileID, int personID, int start, int max)
        {
            Contracts.GenericListResult <Contracts.ProfileMemberActivity> list = new Contracts.GenericListResult <Contracts.ProfileMemberActivity>();
            Profile   profile = new Profile(profileID);
            DataTable dt;
            int       i;


            //
            // Check if the profile exists.
            //
            if (profile.ProfileID == -1)
            {
                throw new Arena.Services.Exceptions.ResourceNotFoundException("Invalid profile ID");
            }

            //
            // Check if the user has access to work with the profile.
            //
            if (RestApi.ProfileOperationAllowed(ArenaContext.Current.Person.PersonID, profile.ProfileID, OperationType.View) == false)
            {
                throw new Exception("Access denied.");
            }

            dt         = new ProfileMemberActivityData().GetProfileMemberActivityDetails_DT(RestApi.DefaultOrganizationID(), profile.ProfileType, profile.Owner.PersonID, personID);
            list.Start = start;
            list.Max   = max;
            list.Items = new List <Contracts.ProfileMemberActivity>();
            for (i = 0; i < dt.Rows.Count; i++)
            {
                if (RestApi.ProfileOperationAllowed(ArenaContext.Current.Person.PersonID, Convert.ToInt32(dt.Rows[i]["profile_id"]), OperationType.View) == false)
                {
                    continue;
                }

                if (list.Total >= start && (max <= 0 ? true : list.Items.Count < max))
                {
                    list.Items.Add(new Contracts.ProfileMemberActivity(dt.Rows[i]));
                }
                list.Total += 1;
            }

            return(list);
        }