예제 #1
0
        public CRMRetrieveMultiple CRMRetrieveMultiple(CRMRetrieveMultiple retrieveMultiple)
        {
            List <CRMRetrieveMultipleReturn> results = new List <CRMRetrieveMultipleReturn>();

            OrganizationServiceProxy _serviceProxy;

            using (_serviceProxy = GetCRMConnection())
            {
                QueryExpression query;
                if (!string.IsNullOrEmpty(retrieveMultiple.ConditionAttributeName.Trim()))
                {
                    //Create Query Expression.
                    query = new QueryExpression()
                    {
                        EntityName   = retrieveMultiple.LinkFromEntityName.ToLower(),
                        ColumnSet    = new ColumnSet(true),
                        LinkEntities =
                        {
                            new LinkEntity
                            {
                                LinkFromEntityName    = retrieveMultiple.LinkFromEntityName.ToLower(),
                                LinkFromAttributeName = retrieveMultiple.LinkFromAttributeName,
                                LinkToEntityName      = retrieveMultiple.LinkToEntityName,
                                LinkToAttributeName   = retrieveMultiple.LinkToAttributeName,
                                LinkCriteria          = new FilterExpression
                                {
                                    FilterOperator = LogicalOperator.And,
                                    Conditions     =
                                    {
                                        new ConditionExpression
                                        {
                                            AttributeName = retrieveMultiple.ConditionAttributeName,
                                            Operator      = GetConditionOperator(retrieveMultiple.ConditionOperator),
                                            Values        = { retrieveMultiple.ConditionValue }
                                        }
                                    }
                                }
                            }
                        }
                    };
                }
                else
                {
                    //Create Query Expression.
                    query = new QueryExpression()
                    {
                        EntityName   = retrieveMultiple.LinkFromEntityName.ToLower(),
                        ColumnSet    = new ColumnSet(true),
                        LinkEntities =
                        {
                            new LinkEntity
                            {
                                LinkFromEntityName    = retrieveMultiple.LinkFromEntityName.ToLower(),
                                LinkFromAttributeName = retrieveMultiple.LinkFromAttributeName,
                                LinkToEntityName      = retrieveMultiple.LinkToEntityName,
                                LinkToAttributeName   = retrieveMultiple.LinkToAttributeName,
                            }
                        }
                    };
                }
                EntityCollection ec = _serviceProxy.RetrieveMultiple(query);

                foreach (Entity e in ec.Entities)
                {
                    CRMRetrieveMultipleReturn res = new CRMRetrieveMultipleReturn();
                    res.EntityId = e.Id.ToString();

                    string[] Columns = retrieveMultiple.ReturnAttributes.Split('|');
                    for (int i = 0; i < Columns.Length; i++)
                    {
                        if (e.Attributes.Contains(Columns[i].Trim()))
                        {
                            switch (i.ToString())
                            {
                            case "0":
                                res.ReturnAttribute0 = CRMTypeMapping(e.Attributes[Columns[i].Trim()].ToString());
                                break;

                            case "1":
                                res.ReturnAttribute1 = CRMTypeMapping(e.Attributes[Columns[i].Trim()].ToString());
                                break;

                            case "2":
                                res.ReturnAttribute2 = CRMTypeMapping(e.Attributes[Columns[i].Trim()].ToString());
                                break;

                            case "3":
                                res.ReturnAttribute3 = CRMTypeMapping(e.Attributes[Columns[i].Trim()].ToString());
                                break;

                            case "4":
                                res.ReturnAttribute4 = CRMTypeMapping(e.Attributes[Columns[i].Trim()].ToString());
                                break;

                            case "5":
                                res.ReturnAttribute5 = CRMTypeMapping(e.Attributes[Columns[i].Trim()].ToString());
                                break;

                            case "6":
                                res.ReturnAttribute6 = CRMTypeMapping(e.Attributes[Columns[i].Trim()].ToString());
                                break;

                            case "7":
                                res.ReturnAttribute7 = CRMTypeMapping(e.Attributes[Columns[i].Trim()].ToString());
                                break;

                            case "8":
                                res.ReturnAttribute8 = CRMTypeMapping(e.Attributes[Columns[i].Trim()].ToString());
                                break;

                            case "9":
                                res.ReturnAttribute9 = CRMTypeMapping(e.Attributes[Columns[i].Trim()].ToString());
                                break;
                            }
                        }
                    }
                    results.Add(res);
                }
                retrieveMultiple.Results = results;
            }
            return(retrieveMultiple);
        }
        public CRMRetrieveMultiple CRMRetrieveMultiple(CRMRetrieveMultiple retrieveMultiple)
        {
            List<CRMRetrieveMultipleReturn> results = new List<CRMRetrieveMultipleReturn>();

            OrganizationServiceProxy _serviceProxy;
            using (_serviceProxy = GetCRMConnection())
            {
                QueryExpression query;
                if (!string.IsNullOrEmpty(retrieveMultiple.ConditionAttributeName.Trim()))
                {
                    //Create Query Expression.
                    query = new QueryExpression()
                    {
                        EntityName = retrieveMultiple.LinkFromEntityName.ToLower(),
                        ColumnSet = new ColumnSet(true),
                        LinkEntities = 
                    {
                        new LinkEntity
                        {
                            LinkFromEntityName = retrieveMultiple.LinkFromEntityName.ToLower(),
                            LinkFromAttributeName = retrieveMultiple.LinkFromAttributeName,
                            LinkToEntityName = retrieveMultiple.LinkToEntityName,
                            LinkToAttributeName = retrieveMultiple.LinkToAttributeName,
                            LinkCriteria = new FilterExpression
                            {
                                FilterOperator = LogicalOperator.And,
                                Conditions = 
                                {
                                    new ConditionExpression
                                    {
                                        AttributeName = retrieveMultiple.ConditionAttributeName,
                                        Operator = GetConditionOperator(retrieveMultiple.ConditionOperator),
                                        Values = { retrieveMultiple.ConditionValue }
                                    }
                                }
                            }
                        }
                    }
                    };
                }
                else
                {
                    //Create Query Expression.
                    query = new QueryExpression()
                    {
                        EntityName = retrieveMultiple.LinkFromEntityName.ToLower(),
                        ColumnSet = new ColumnSet(true),
                        LinkEntities = 
                    {
                        new LinkEntity
                        {
                            LinkFromEntityName = retrieveMultiple.LinkFromEntityName.ToLower(),
                            LinkFromAttributeName = retrieveMultiple.LinkFromAttributeName,
                            LinkToEntityName = retrieveMultiple.LinkToEntityName,
                            LinkToAttributeName = retrieveMultiple.LinkToAttributeName,
                        }
                    }
                    };
                }
                EntityCollection ec = _serviceProxy.RetrieveMultiple(query);

                foreach (Entity e in ec.Entities)
                {
                    CRMRetrieveMultipleReturn res = new CRMRetrieveMultipleReturn();
                    res.EntityId = e.Id.ToString();

                    string[] Columns = retrieveMultiple.ReturnAttributes.Split('|');
                    for (int i = 0; i < Columns.Length; i++)
                    {
                        if (e.Attributes.Contains(Columns[i].Trim()))
                        {
                            switch (i.ToString())
                            {
                                case "0":
                                    res.ReturnAttribute0 = CRMTypeMapping(e.Attributes[Columns[i].Trim()].ToString());
                                    break;
                                case "1":
                                    res.ReturnAttribute1 = CRMTypeMapping(e.Attributes[Columns[i].Trim()].ToString());
                                    break;
                                case "2":
                                    res.ReturnAttribute2 = CRMTypeMapping(e.Attributes[Columns[i].Trim()].ToString());
                                    break;
                                case "3":
                                    res.ReturnAttribute3 = CRMTypeMapping(e.Attributes[Columns[i].Trim()].ToString());
                                    break;
                                case "4":
                                    res.ReturnAttribute4 = CRMTypeMapping(e.Attributes[Columns[i].Trim()].ToString());
                                    break;
                                case "5":
                                    res.ReturnAttribute5 = CRMTypeMapping(e.Attributes[Columns[i].Trim()].ToString());
                                    break;
                                case "6":
                                    res.ReturnAttribute6 = CRMTypeMapping(e.Attributes[Columns[i].Trim()].ToString());
                                    break;
                                case "7":
                                    res.ReturnAttribute7 = CRMTypeMapping(e.Attributes[Columns[i].Trim()].ToString());
                                    break;
                                case "8":
                                    res.ReturnAttribute8 = CRMTypeMapping(e.Attributes[Columns[i].Trim()].ToString());
                                    break;
                                case "9":
                                    res.ReturnAttribute9 = CRMTypeMapping(e.Attributes[Columns[i].Trim()].ToString());
                                    break;
                            }
                        }
                    }
                    results.Add(res);
                }
                retrieveMultiple.Results = results;
            }
            return retrieveMultiple;
        }
        private Property SetRetrieveMultipleReturnProperties(Property prop, CRMRetrieveMultipleReturn task)
        {
            switch (prop.Name.ToLower())
            {
                case "entityid":
                    prop.Value = task.EntityId;
                    break;
                case "returnattribute0":
                    prop.Value = task.ReturnAttribute0;
                    break;
                case "returnattribute1":
                    prop.Value = task.ReturnAttribute1;
                    break;
                case "returnattribute2":
                    prop.Value = task.ReturnAttribute2;
                    break;
                case "returnattribute3":
                    prop.Value = task.ReturnAttribute3;
                    break;
                case "returnattribute4":
                    prop.Value = task.ReturnAttribute4;
                    break;
                case "returnattribute5":
                    prop.Value = task.ReturnAttribute5;
                    break;
                case "returnattribute6":
                    prop.Value = task.ReturnAttribute6;
                    break;
                case "returnattribute7":
                    prop.Value = task.ReturnAttribute7;
                    break;
                case "returnattribute8":
                    prop.Value = task.ReturnAttribute8;
                    break;
                case "returnattribute9":
                    prop.Value = task.ReturnAttribute9;
                    break;
            }

            return prop;
        }