Пример #1
0
    public static bool CanViewMembershipDocuments(IConciergeAPIService api, string membershipObjectID, string entityID)
    {
        // checks to see if you can view section/chapter/org layer docs
        var typeName = api.DetermineObjectType(membershipObjectID).ResultValue;

        if (typeName == msOrganizationalLayer.CLASS_NAME) // special logic
        {
            string orgLayerID = membershipObjectID;
            var    results    = api.GetSearchResult(MembershipLogic.GetSearchForOrganizationalLayerMemberships(), 0, null).Table;

            // search all the columns for the id
            foreach (DataRow dr in results.Rows)
            {
                foreach (DataColumn dc in results.Columns)
                {
                    if (Convert.ToString(dr[dc.ColumnName]) == orgLayerID)
                    {
                        return(true);    // great! We're a member
                    }
                }
            }
            return(false);
        }

        var sFlowDown = new Search("MembershipWithFlowDown");
        sFlowDown.AddCriteria(Expr.Equals("Owner", entityID));

        var flowdownMembership = api.GetSearchResult(sFlowDown, 0, 1);

        // is the person a member of the chapter?
        Search s = new Search(typeName + "Membership");
        var sog  = new SearchOperationGroup {
            GroupType = SearchOperationGroupType.Or
        };
        sog.Criteria.Add(Expr.Equals("Membership.Owner", entityID));
        if (flowdownMembership != null && flowdownMembership.TotalRowCount > 0)
        {
            sog.Criteria.Add(Expr.Equals("Membership", flowdownMembership.Table.Rows[0]["ID"]));
        }
        s.AddCriteria(sog);
        s.AddCriteria(Expr.Equals(typeName, membershipObjectID));
        s.AddCriteria(Expr.Equals("IsCurrent", true));
        s.AddOutputColumn("Membership");
        s.AddSortColumn("ListIndex");

        if (api.GetSearchResult(s, 0, 1).TotalRowCount > 0)
        {
            return(true);    // yep
        }
        // ok - what about a leader?
        Search sLeaders = new Search(typeName + "Leader");
        sLeaders.AddCriteria(Expr.Equals(typeName, membershipObjectID));
        sLeaders.AddCriteria(Expr.Equals(msMembershipLeader.FIELDS.Individual, entityID));
        sLeaders.AddOutputColumn(typeName);
        sLeaders.AddSortColumn("ListIndex");

        if (api.GetSearchResult(sLeaders, 0, 1).TotalRowCount > 0)
        {
            return(true);    // they are a leader
        }
        return(false);
    }
Пример #2
0
    public override void GenerateSearchesToBeRun(List <Search> searchesToRun)
    {
        base.GenerateSearchesToBeRun(searchesToRun);

        //PS-760
        /*Lets get membership organizations already used by this entity*/

        var exclude = new List <string>();
        // MS-5444
        const string renewalRangeColumn   = "MembershipOrganization.NumberOfDaysPriorToExpirationToPromptForRenewal";
        const string expirationDateColumn = "ExpirationDate";

        using (var proxy = ConciergeAPIProxyGenerator.GenerateProxy())
        {
            var s = new Search(msMembership.CLASS_NAME);
            var portalPermissions = new SearchOperationGroup {
                GroupType = SearchOperationGroupType.Or
            };
            portalPermissions.Criteria.Add(Expr.Equals("MembershipOrganization.MembersCanJoinThroughThePortal", true));
            portalPermissions.Criteria.Add(Expr.Equals("MembershipOrganization.MembersCanRenewThroughThePortal", true));
            s.AddCriteria(portalPermissions);
            s.AddOutputColumn("MembershipOrganization");
            // MS-5444
            s.AddOutputColumn(renewalRangeColumn);
            s.AddOutputColumn(expirationDateColumn);
            s.AddOutputColumn("Product.Name");
            s.AddOutputColumn("Type.Name");
            var tGroup = new SearchOperationGroup {
                FieldName = "TerminationDate"
            };
            tGroup.Criteria.Add(Expr.Equals("TerminationDate", null));
            tGroup.Criteria.Add(Expr.IsGreaterThan("TerminationDate", DateTime.Now));
            tGroup.GroupType = SearchOperationGroupType.Or;

            s.Criteria.Add(tGroup);
            s.Criteria.Add(Expr.Equals("ReceivesMemberBenefits", true));
            s.AddCriteria(Expr.Equals("Owner", ConciergeAPI.CurrentEntity.ID));

            var members = proxy.GetSearchResult(s, 0, null);
            if (members.TotalRowCount > 0)
            {
                foreach (DataRow dr in members.Table.Rows)
                {
                    if (dr["MembershipOrganization"] == DBNull.Value)
                    {
                        continue;
                    }

                    var id = Convert.ToString(dr["MembershipOrganization"]);
                    if (string.IsNullOrEmpty(id) || exclude.Contains(id))
                    {
                        continue;
                    }

                    // MS-5444 Exclude current membership organization from renewal list only if member's expiration date is not within a renewal range.
                    var suppressRenew = true;
                    if (dr.Table.Columns.Contains(renewalRangeColumn) && dr[renewalRangeColumn] != DBNull.Value &&
                        dr.Table.Columns.Contains(expirationDateColumn) && dr[expirationDateColumn] != DBNull.Value)
                    {
                        var renewalRange   = Convert.ToInt32(dr[renewalRangeColumn]);
                        var expirationDate = Convert.ToDateTime(dr[expirationDateColumn]);
                        suppressRenew = DateTime.Now.AddDays(renewalRange) < expirationDate;
                    }

                    if (suppressRenew)
                    {
                        exclude.Add(id);
                    }

                    _exitingMembeships.Add(Convert.ToString(dr["ID"]), Convert.ToString(dr["Product.Name"]));

                    _existingMemOrgs.Add(id);
                }
            }
        }

        // now, we need the default membership organization
        var sDefaultMemOrg = new Search {
            Type = msMembershipOrganization.CLASS_NAME, ID = "MembershipOrganization"
        };

        //PS-760

        sDefaultMemOrg.AddCriteria(Expr.Equals("IsActive", true));
        foreach (var id in exclude)
        {
            sDefaultMemOrg.AddCriteria(Expr.DoesNotEqual("ID", id));
        }

        sDefaultMemOrg.AddOutputColumn("Name");
        sDefaultMemOrg.AddOutputColumn(msMembershipOrganization.FIELDS.MembersCanJoinThroughThePortal);
        sDefaultMemOrg.AddOutputColumn(msMembershipOrganization.FIELDS.MembersCanRenewThroughThePortal);
        sDefaultMemOrg.AddOutputColumn(msMembershipOrganization.FIELDS.NumberOfDaysPriorToExpirationToPromptForRenewal);
        searchesToRun.Add(sDefaultMemOrg);



        var terminationGroup = new SearchOperationGroup {
            FieldName = "Membership.TerminationDate"
        };

        terminationGroup.Criteria.Add(Expr.Equals("Membership.TerminationDate", null));
        terminationGroup.Criteria.Add(Expr.IsGreaterThan("Membership.TerminationDate", DateTime.Now));
        terminationGroup.GroupType = SearchOperationGroupType.Or;

        //Chapter Membership
        Search sChapterMembership = new Search {
            Type = msChapterMembership.CLASS_NAME, ID = "ChapterMembership"
        };

        sChapterMembership.AddOutputColumn("Chapter.ID");
        sChapterMembership.AddOutputColumn("Chapter.Name");
        sChapterMembership.AddSortColumn("Chapter.Name");
        sChapterMembership.AddCriteria(Expr.Equals("Membership.Owner.ID", ConciergeAPI.CurrentEntity.ID));
        sChapterMembership.AddCriteria(Expr.Equals("IsCurrent", true));
        sChapterMembership.AddCriteria(terminationGroup);
        searchesToRun.Add(sChapterMembership);


        var sOrganizationalLayerMembership = MembershipLogic.GetSearchForOrganizationalLayerMemberships();

        sOrganizationalLayerMembership.AddCriteria(terminationGroup);
        searchesToRun.Add(sOrganizationalLayerMembership);

        //Section Membership
        Search sSectionMembership = new Search {
            Type = msSectionMembership.CLASS_NAME, ID = "SectionMembership"
        };

        sSectionMembership.AddOutputColumn("Section.ID");
        sSectionMembership.AddOutputColumn("Section.Name");
        sSectionMembership.AddSortColumn("Section.Name");
        sSectionMembership.AddCriteria(Expr.Equals("Membership.Owner.ID", ConciergeAPI.CurrentEntity.ID));
        sSectionMembership.AddCriteria(Expr.Equals("IsCurrent", true));
        sSectionMembership.AddCriteria(terminationGroup);
        sSectionMembership.UniqueResult = true;
        searchesToRun.Add(sSectionMembership);

        //Chapter Leadership
        Search sChapterLeadership = new Search {
            Type = "ChapterLeader", ID = "ChapterLeadership"
        };

        sChapterLeadership.AddOutputColumn("Chapter.ID");
        sChapterLeadership.AddOutputColumn("Chapter.Name");
        sChapterLeadership.AddSortColumn("Chapter.Name");
        sChapterLeadership.AddCriteria(Expr.Equals("Individual.ID", ConciergeAPI.CurrentEntity.ID));
        searchesToRun.Add(sChapterLeadership);

        //Section Leadership
        Search sSectionLeadership = new Search {
            Type = "SectionLeader", ID = "SectionLeadership"
        };

        sSectionLeadership.AddOutputColumn("Section.ID");
        sSectionLeadership.AddOutputColumn("Section.Name");
        sSectionLeadership.AddSortColumn("Section.Name");
        sSectionLeadership.AddCriteria(Expr.Equals("Individual.ID", ConciergeAPI.CurrentEntity.ID));
        searchesToRun.Add(sSectionLeadership);

        //Organizational Layer Leadership
        Search sOrganizationalLayerLeadership = new Search {
            Type = "OrganizationalLayerLeader", ID = "OrganizationalLayerLeadership"
        };

        sOrganizationalLayerLeadership.AddOutputColumn("OrganizationalLayer.ID");
        sOrganizationalLayerLeadership.AddOutputColumn("OrganizationalLayer.Name");
        sOrganizationalLayerLeadership.AddOutputColumn("OrganizationalLayer.Type.Name");
        sOrganizationalLayerLeadership.AddSortColumn("OrganizationalLayer.Type.Name");
        sOrganizationalLayerLeadership.AddSortColumn("OrganizationalLayer.Name");
        sOrganizationalLayerLeadership.AddCriteria(Expr.Equals("Individual.ID", ConciergeAPI.CurrentEntity.ID));
        searchesToRun.Add(sOrganizationalLayerLeadership);
    }