예제 #1
0
    public static msPortalPageLayoutContainer GetAppropriatePageLayout(this MemberSuiteObject mso)
    {
        var typeId     = mso.SafeGetValue <string>("Type");
        var objectType = mso.ClassType;

        if (string.IsNullOrWhiteSpace(typeId))
        {
            return(GetDefaultPageLayout(objectType));
        }

        var key = string.Format("GetAppropriatePageLayout::{0}_{1}", objectType, typeId);

        return(SessionManager.Get(key, () =>
        {
            // let's get the type
            using (var api = ConciergeAPIProxyGenerator.GenerateProxy())
            {
                var msoType = api.Get(typeId).ResultValue;
                var layoutId = msoType.SafeGetValue <string>("PortalPageLayout");

                if (string.IsNullOrWhiteSpace(layoutId))
                {
                    return GetDefaultPageLayout(objectType);
                }

                var pageLayout = api.Get(layoutId).ResultValue.ConvertTo <msPortalPageLayoutContainer>();

                return pageLayout;
            }
        }));
    }
예제 #2
0
    protected void UnbindRelationship()
    {
        // Test to ensure this change does not violate Org Contact Restrictions
        var orgId = leftSide.ClassType == msOrganization.CLASS_NAME
            ? leftSide.SafeGetValue <string>("ID")
            : rightSide.SafeGetValue <string>("ID");


        var indId = leftSide.ClassType == msIndividual.CLASS_NAME
            ? leftSide.SafeGetValue <string>("ID")
            : rightSide.SafeGetValue <string>("ID");

        CRMLogic.ErrorOutIfOrganizationContactRestrictionApplies(
            orgId,
            ddlRelationshipType.SelectedValue,
            indId);

        targetRelationship.Type        = ddlRelationshipType.SelectedValue;
        targetRelationship.StartDate   = dtpStartDate.SelectedDate;
        targetRelationship.EndDate     = dtpEndDate.SelectedDate;
        targetRelationship.Description = tbDescription.Text;
    }
예제 #3
0
    private static msAuditLog constructAuditLog(msUser currentUser, Exception ex, string contextId, MemberSuiteObject contextObject)
    {
        msAuditLog result = new msAuditLog();
        result.AffectedRecord_ID = contextId;
        result.Type = AuditLogType.Error;

        if (currentUser != null)
            result.Actor = currentUser.ID;

        if (contextObject != null)
        {
            result.AffectedRecord_Type = contextObject.ClassType;
            result.AffectedRecord_Name = contextObject.SafeGetValue<string>("Name");
        }

        result.Description = ex.ToString();

        return result;
    }
예제 #4
0
    protected void ParseSearchCriteria(List <FieldMetadata> targetCriteriaFields, MemberSuiteObject criteria, SearchBuilder sb)
    {
        foreach (var fieldMetadata in targetCriteriaFields)
        {
            string fieldName = Formats.GetSafeFieldName(fieldMetadata.Name);
            bool   found     = false;

            if (_isValidRange(criteria.SafeGetValue(fieldName + "__from")))
            {
                // let's create a greater than
                sb.AddOperation(Expr.IsGreaterThanOrEqualTo(fieldMetadata.Name, criteria[fieldName + "__from"]), SearchOperationGroupType.And);
                found = true;
            }

            if (_isValidRange(criteria.SafeGetValue(fieldName + "__to")))
            {
                // let's create a less than
                sb.AddOperation(Expr.IsLessThanOrEqual(fieldMetadata.Name, criteria[fieldName + "__to"]), SearchOperationGroupType.And);
                found = true;
            }

            if (found || !criteria.Fields.ContainsKey(fieldName))
            {
                continue;
            }

            var fieldValue = criteria.Fields[fieldName];
            if (fieldValue == null)
            {
                continue;
            }

            SearchOperation so = new Equals(); //default
            so.ValuesToOperateOn = new List <object> {
                fieldValue
            };

            if (fieldValue is string)
            {
                string fieldValueAsString = (string)fieldValue;
                if (String.IsNullOrWhiteSpace(fieldValueAsString))
                {
                    continue;
                }

                if (fieldMetadata.DataType == FieldDataType.Boolean)
                {
                    bool b = false;
                    if (Boolean.TryParse(fieldValueAsString, out b))
                    {
                        so.ValuesToOperateOn = new List <object>()
                        {
                            b
                        }
                    }
                    ;
                }
                else
                {
                    so = new Contains(); //string should use contains instead of equals
                    so.ValuesToOperateOn = new List <object>()
                    {
                        fieldValueAsString.Trim()
                    };
                }
            }

            if (fieldValue is List <string> )
            {
                List <string> fieldValueAsList = fieldValue as List <string>;
                if (fieldValueAsList.Count == 0)
                {
                    continue;
                }

                so = new ContainsOneOfTheFollowing(); //Lists just look for one hit
                List <object> values = new List <object>();
                values.AddRange(fieldValueAsList);

                so.ValuesToOperateOn = values;
            }

            so.FieldName = fieldMetadata.Name;

            sb.AddOperation(so, SearchOperationGroupType.And);
        }
    }
        public override void Run()
        {
            /* The purpose of this sample is to show you how to use the API to execute a portal login
             * on behalf of an individual, and once that portal login is completed, how to query on a member's status.
             * We reuse some of what's in DeterminingMembershipStatus here.
             */

            // First, we need to prepare the proxy with the proper security settings.
            // This allows the proxy to generate the appropriate security header. For more information
            // on how to get these settings, see http://api.docs.membersuite.com in the Getting Started section
            if (!ConciergeAPIProxyGenerator.IsSecretAccessKeySet)
            {
                ConciergeAPIProxyGenerator.SetAccessKeyId(ConfigurationManager.AppSettings["AccessKeyID"]);
                ConciergeAPIProxyGenerator.SetSecretAccessKey(ConfigurationManager.AppSettings["SecretAccessKey"]);
                ConciergeAPIProxyGenerator.AssociationId = ConfigurationManager.AppSettings["AssociationID"];
            }

            // ok, let's generate our API proxy
            using (var api = ConciergeAPIProxyGenerator.GenerateProxy())
            {
                Console.WriteLine(
                    "Please enter login credentials. If you don't have specific credentials, try 'test' for both the user and password to get Terry Smith.");
                Console.WriteLine();
                Console.WriteLine("Please enter the username and hit ENTER.");
                string username = Console.ReadLine();

                Console.WriteLine("Please enter the password and hit ENTER.");
                string password = Console.ReadLine();

                ConciergeResult <LoginResult> portalLoginResult = api.LoginToPortal(username, password);

                if (!portalLoginResult.Success)
                {
                    Console.WriteLine("Portal login failed with this error: " + portalLoginResult.FirstErrorMessage);
                    return;
                }

                Console.WriteLine("Portal login successful - accessing member information...");

                // this is the "entity" that you've logged in as.
                // remember an entity is either an organization OR an individual - it's a base class.
                MemberSuiteObject entity = portalLoginResult.ResultValue.PortalEntity;

                // now, let's get that entity's ID
                string entityID = entity.SafeGetValue <string>("ID");

                // there's a lot of confusion between the different types of users, so let's list them
                Console.WriteLine();
                Console.WriteLine("Users");
                Console.WriteLine("-----------------------------");
                Console.WriteLine();
                Console.WriteLine("API User: {0} - this is the security context that your application is using.",
                                  portalLoginResult.ResultValue.User["Name"]);
                Console.WriteLine(
                    "Portal User: {0} - this is the security context that you are logging your member in as. It's linked to the actual member record via the Owner property.",
                    portalLoginResult.ResultValue.PortalUser["Name"]);
                Console.WriteLine(
                    "Individual/Organization: {0} - this is the entity record that the portal user is tied to. ",
                    portalLoginResult.ResultValue.PortalEntity["Name"]);
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("The owner of the login has an ID of '{0}' - accessing...",
                                  entityID);

                // ok, let's get the membership status
                string msql = string.Format(
                    "select TOP 1 FirstName, LocalID, LastName, Membership.Type.Name, Membership.PrimaryChapter.Name, Membership.ExpirationDate, Membership.ReceivesMemberBenefits from Individual where ID = '{0}' order by LastName",
                    entityID);

                var result = api.ExecuteMSQL(msql, 0, null);

                if (!result.Success)
                {
                    Console.WriteLine("Search failed: {0}", result.FirstErrorMessage);
                    return;
                }

                DataRow resultRow = result.ResultValue.SearchResult.Table.Rows[0];
                // we know there's only one row, since the ID is unqiue
                Console.WriteLine("ID: " + resultRow["LocalID"]);
                Console.WriteLine("First Name: " + resultRow["FirstName"]);
                Console.WriteLine("Last Name: " + resultRow[msIndividual.FIELDS.LastName]);
                // <--- this is how you would use constants, which is the better way to go
                Console.WriteLine("Member? " + resultRow["Membership.ReceivesMemberBenefits"]);
                Console.WriteLine("Member Type: " + resultRow["Membership.Type.Name"]);
                Console.WriteLine("Chapter: " + resultRow["Membership.PrimaryChapter.Name"]);
                Console.WriteLine("Expiration Date: " + resultRow["Membership.ExpirationDate"]);
                Console.WriteLine("Search successful: {0} results returned.",
                                  result.ResultValue.SearchResult.TotalRowCount);
            }
        }
    private void setupChapters(msMembershipOrganization mo, msMembershipDuesProduct product)
    {
        ChapterMode cm = mo.ChapterMode;

        // check to see if we need to override on product
        if (product[msMembershipDuesProduct.FIELDS.ChapterMode] != null)
        {
            cm = product.SafeGetValue <ChapterMode>(msMembershipDuesProduct.FIELDS.ChapterMode);
        }

        switch (cm)
        {
        case ChapterMode.ChaptersDisabled:
            divChapter.Visible = false;     // don't show it
            return;

        case ChapterMode.MemberJoinsOneChapter:
            divChapter.Visible            = true;
            divAdditionalChapters.Visible = false;
            break;

        case ChapterMode.MemberCanJoinMultipleChapters:
            divChapter.Visible            = true;
            divAdditionalChapters.Visible = true;
            break;
        }

        // let's pull all of the chapters
        List <NameValueStringPair> tblChapters;

        using (var api = GetServiceAPIProxy())
        {
            tblChapters = api.GetApplicableChaptersForMembershipType(targetMembership.Type).ResultValue;
        }
        ddlSelectChapter.DataSource     = tblChapters;
        ddlSelectChapter.DataTextField  = "Name";
        ddlSelectChapter.DataValueField = "Value";
        ddlSelectChapter.DataBind();


        if (divAdditionalChapters.Visible)    // bind the list box, too
        {
            lbAdditionalChapters.DataSource     = tblChapters;
            lbAdditionalChapters.DataTextField  = "Name";
            lbAdditionalChapters.DataValueField = "Value";
            lbAdditionalChapters.DataBind();
        }

        ddlSelectChapter.Items.Insert(0, new ListItem("---- Select a Chapter ----", ""));

        // ok - are we suggesting a chapter based on zip code?
        var cpm = mo.ChapterPostalCodeMappingMode;

        // check to see if we need to override on product
        if (product[msMembershipDuesProduct.FIELDS.ChapterPostalCodeMappingMode] != null)
        {
            cpm = product.SafeGetValue <ChapterPostalCodeMappingMode>(msMembershipDuesProduct.FIELDS.ChapterPostalCodeMappingMode);
        }

        if (cpm != ChapterPostalCodeMappingMode.Disabled)
        {
            MemberSuiteObject msoChapter = null;
            using (var api = GetServiceAPIProxy())
                msoChapter = api.SuggestChapter(mo.ID, targetEntity.ID).ResultValue;

            if (msoChapter != null)   // have have a chapter
            {
                ListItem li = ddlSelectChapter.Items.FindByValue(msoChapter.SafeGetValue <string>("ID"));

                if (li != null)   // we have a match
                {
                    li.Selected = true;

                    if (cpm == ChapterPostalCodeMappingMode.Assign)
                    {
                        ddlSelectChapter.Enabled  = false; // can't be changed
                        trChapterAssigned.Visible = true;
                    }

                    // if a chapter matches, that's it, we're done
                    return;
                }
            }
        }


        // let's try and set to the default chapter
        if (targetMembership != null && targetMembership.Chapters != null)
        {
            // find the primary


            var cPrimary = (targetMembership.Chapters.Find(x => x.IsPrimary));

            // MS-4984 - only set the default chapter if it's set up in the mem org
            if (cPrimary != null && mo.MembersShouldInheritPreviousChapterUponRenewal)
            {
                ddlSelectChapter.SafeSetSelectedValue(cPrimary.Chapter);
            }


            // now, let's try to select the additional
            if (divAdditionalChapters.Visible)
            {
                foreach (var c in targetMembership.Chapters)
                {
                    if ((c.ExpirationDate == null || c.ExpirationDate == targetMembership.ExpirationDate) &&
                        (cPrimary == null || c.Chapter != cPrimary.Chapter))
                    {
                        ListItem li = lbAdditionalChapters.Items.FindByValue(c.Chapter);
                        if (li != null)
                        {
                            li.Selected = true;
                        }
                    }
                }
            }
        }
    }