Example #1
0
        /// <summary>
        /// Returns most recent membership for each org wich is active or terminated within the grace period
        /// </summary>
        /// <param name="orgs">List of ids. If empty, all orgs</param>
        /// <param name="gracePeriod">For exired, number of days to add to allow it to be returned</param>
        /// <returns></returns>
        public Memberships GetRecentMemberships(List <int> orgs, int gracePeriod)
        {
            Memberships memberships = this.GetMemberships(true);
            Dictionary <int, Membership> collectMembers = new Dictionary <int, Membership>();

            memberships.Sort(delegate(Membership ms1, Membership ms2)
            {
                return(ms2.DateTerminated.CompareTo(ms1.DateTerminated));
            });

            //Keep one for each org, the active one or the one with the highest Terminationdate
            foreach (Membership membership in memberships)
            {
                if (orgs.Count == 0 || orgs.Contains(membership.OrganizationId))
                {
                    if (membership.Active)
                    {
                        collectMembers[membership.OrganizationId] = membership;
                    }
                    else if (membership.DateTerminated.AddDays(gracePeriod) > DateTime.Today)
                    {
                        if (!collectMembers.ContainsKey(membership.OrganizationId) ||
                            collectMembers[membership.OrganizationId].Active == false)
                        {
                            collectMembers[membership.OrganizationId] = membership;
                        }
                    }
                }
            }

            Memberships collectedMS = new Memberships();

            collectedMS.AddRange(collectMembers.Values);

            if (collectedMS.Count > 0)
            { //sort to get most recent first
                collectedMS.Sort(delegate(Membership ms1, Membership ms2)
                {
                    if (ms1.Active && ms1.Active != ms2.Active)
                    {
                        return(-1); // active before terminated
                    }
                    else if (ms1.Active != ms2.Active)
                    {
                        return(1);// active before terminated
                    }
                    else if (ms1.Active)
                    {
                        return(ms1.Expires.CompareTo(ms2.Expires)); // active with lowest expiry
                    }
                    else
                    {
                        return(ms2.DateTerminated.CompareTo(ms1.DateTerminated)); // terminated with latest terminationdate
                    }
                });
            }

            return(collectedMS);
        }
Example #2
0
        public Memberships GetMemberships(bool includeTerminated)
        {
            if (!includeTerminated)
            {
                return(GetMemberships());
            }

            return(Memberships.FromArray(SwarmDb.GetDatabaseForReading().GetMemberships(this)));
        }
Example #3
0
        public static People FromMemberships(Memberships memberships)
        {
            List <int> personIds = new List <int>();

            foreach (Membership membership in memberships)
            {
                personIds.Add(membership.PersonId);
            }

            return(FromIdentities(personIds.ToArray()));
        }
Example #4
0
        public static Memberships FromArray(BasicMembership[] basicArray)
        {
            Memberships result = new Memberships();

            result.Capacity = basicArray.Length * 11 / 10;
            foreach (BasicMembership basic in basicArray)
            {
                result.Add(Membership.FromBasic(basic));
            }

            return(result);
        }
Example #5
0
        //Optimization metod, loadMultiple in one call
        public static void LoadPaymentStatuses(Memberships mss)
        {
            Dictionary <int, BasicMembershipPaymentStatus> statuses =
                SwarmDb.GetDatabaseForReading().GetMembershipPaymentStatuses(mss.Identities);

            foreach (Membership ms in mss)
            {
                if (ms.paymentStatus == null && statuses.ContainsKey(ms.Identity))
                {
                    ms.paymentStatus = statuses[ms.Identity];
                }
            }
        }
Example #6
0
        public bool MemberOfWithInherited(int orgId)
        {
            Memberships memberships = this.GetMemberships();

            foreach (Membership membership in memberships)
            {
                if (membership.Organization.IsOrInherits(orgId))
                {
                    return(true);
                }
            }
            return(false);
        }
Example #7
0
        public bool MemberOf(int orgId)
        {
            Memberships memberships = this.GetMemberships();

            foreach (Membership membership in memberships)
            {
                if (membership.OrganizationId == orgId)
                {
                    return(true);
                }
            }

            return(false);
        }
Example #8
0
        /// <summary>
        /// Returns the most recent membership for an org wich is active or terminated within the grace period
        /// </summary>
        /// <param name="gracePeriod">For exired, number of days to add to allow it to be returned</param>
        /// <param name="orgId"></param>
        /// <returns></returns>
        public Membership GetRecentMembership(int gracePeriod, int orgId)
        {
            List <int> orgIdList = new List <int>();

            orgIdList.Add(orgId);
            Memberships mss = GetRecentMemberships(orgIdList, gracePeriod);

            foreach (Membership ms in mss)
            {
                if (ms.OrganizationId == orgId)
                {
                    return(ms);
                }
            }
            return(null);
        }
Example #9
0
 public Memberships GetMemberships()
 {
     return(Memberships.FromArray(SwarmDb.GetDatabaseForReading().GetMemberships(this, DatabaseCondition.ActiveTrue)));
 }