Esempio n. 1
0
        /// <summary>
        /// Find open opportunities based on contact or org.
        /// </summary>
        /// <param name="attribute"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public List <OpportunityModel> FindOpenOpportunities(string attribute, string value)
        {
            try
            {
                ViewCriteriaItem item = new ViewCriteriaItem();
                item.upperCaseCompare = false;
                item.attribute        = attribute;
                item.@operator        = "=";
                item.Items            = new[] { value };

                ViewCriteriaItem item2 = new ViewCriteriaItem();
                item2.upperCaseCompare = true;
                item2.attribute        = "StatusCode";
                item2.@operator        = "=";
                item2.Items            = new[] { "Open" };

                ViewCriteriaRow condition1 = new ViewCriteriaRow();
                condition1.upperCaseCompare = false;
                condition1.item             = new[] { item, item2 };

                ViewCriteria viewCriteria = new ViewCriteria();
                viewCriteria.conjunction = Conjunction.And;
                viewCriteria.group       = new[] { condition1 };

                //Sorting by Creation date.
                SortAttribute sortAttr = new SortAttribute();
                sortAttr.name       = "CreationDate";
                sortAttr.descending = true;

                FindCriteria findCriteria = new FindCriteria();
                findCriteria.fetchStart = 0;
                findCriteria.fetchSize  = 500;
                findCriteria.filter     = viewCriteria;
                findCriteria.sortOrder  = new[] { sortAttr };

                findCriteria.findAttribute = new string[]
                {
                    "KeyContactId",
                    "PrimaryContactPartyName",
                    "SalesAccountId",
                    "TargetPartyName",
                    "OptyId",
                    "OptyNumber",
                    "PartyName1",
                    "EmailAddress",
                    "Name",
                    "Description",
                    "StatusCode",
                    "SalesMethod",
                    "SalesStage",
                    "SalesChannelCd",
                    "CurrencyCode",
                    "Revenue",
                    "WinProb",
                    "CreatedBy",
                    "CreationDate",
                    "EffectiveDate"
                };

                FindControl findControl = new FindControl();

                Opportunity[] opp = _opportunityClient.findOpportunity(findCriteria, findControl);

                return(getOpportunityModels(opp));
            }
            catch (EndpointNotFoundException wex)
            {
                //Handling incorrect opportunity endpoint
                _logger.Error(wex.Message, wex.StackTrace);
                MessageBox.Show(OSCExceptionMessages.EndpointNotFound,
                                OSCOpportunitiesCommon.EndpointNotFound, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (MessageSecurityException mse)
            {
                //Handling incorrect credentials
                _logger.Error(mse.Message, mse.StackTrace);
                MessageBox.Show(OSCExceptionMessages.OpportunityAuthError,
                                OSCOpportunitiesCommon.OpportunityAuthError, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (CommunicationException ce)
            {
                //Handling maximum reponse size exceeded
                _logger.Error(ce.Message, ce.StackTrace);
                MessageBox.Show(OSCExceptionMessages.MaxReceivedMessageSizeExceeded,
                                OSCOpportunitiesCommon.MaxReceivedMessageSizeExceededTitle, MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message, ex.StackTrace);
                MessageBox.Show(OSCExceptionMessages.UnexpectedError,
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(null);
        }
        /// <summary>
        /// Find open opportunities based on contact or org.
        /// </summary>
        /// <param name="attribute"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public List<OpportunityModel> FindOpenOpportunities(string attribute, string value)
        {
            try
            {
                ViewCriteriaItem item = new ViewCriteriaItem();
                item.upperCaseCompare = false;
                item.attribute = attribute;
                item.@operator = "=";
                item.Items = new[] {value};

                ViewCriteriaItem item2 = new ViewCriteriaItem();
                item2.upperCaseCompare = true;
                item2.attribute = "StatusCode";
                item2.@operator = "=";
                item2.Items = new[] {"Open"};

                ViewCriteriaRow condition1 = new ViewCriteriaRow();
                condition1.upperCaseCompare = false;
                condition1.item = new[] {item, item2};

                ViewCriteria viewCriteria = new ViewCriteria();
                viewCriteria.conjunction = Conjunction.And;
                viewCriteria.group = new[] {condition1};

                //Sorting by Creation date.
                SortAttribute sortAttr = new SortAttribute();
                sortAttr.name = "CreationDate";
                sortAttr.descending = true;

                FindCriteria findCriteria = new FindCriteria();
                findCriteria.fetchStart = 0;
                findCriteria.fetchSize = 500;
                findCriteria.filter = viewCriteria;
                findCriteria.sortOrder = new[] {sortAttr};

                findCriteria.findAttribute = new string[]
                {
                    "KeyContactId",
                    "PrimaryContactPartyName",
                    "SalesAccountId",
                    "TargetPartyName",
                    "OptyId",
                    "OptyNumber",
                    "PartyName1",
                    "EmailAddress",
                    "Name",
                    "Description",
                    "StatusCode",
                    "SalesMethod",
                    "SalesStage",
                    "SalesChannelCd",
                    "CurrencyCode",
                    "Revenue",
                    "WinProb",
                    "CreatedBy",
                    "CreationDate",
                    "EffectiveDate"
                };

                FindControl findControl = new FindControl();

                Opportunity[] opp = _opportunityClient.findOpportunity(findCriteria, findControl);

                return getOpportunityModels(opp);
            }
            catch (EndpointNotFoundException wex)
            {
                //Handling incorrect opportunity endpoint
                _logger.Error(wex.Message, wex.StackTrace);
                MessageBox.Show(OSCExceptionMessages.EndpointNotFound,
                    OSCOpportunitiesCommon.EndpointNotFound, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (MessageSecurityException mse)
            {
                //Handling incorrect credentials
                _logger.Error(mse.Message, mse.StackTrace);
                MessageBox.Show(OSCExceptionMessages.OpportunityAuthError,
                    OSCOpportunitiesCommon.OpportunityAuthError, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (CommunicationException ce)
            {
                //Handling maximum reponse size exceeded
                _logger.Error(ce.Message, ce.StackTrace);
                MessageBox.Show(OSCExceptionMessages.MaxReceivedMessageSizeExceeded,
                        OSCOpportunitiesCommon.MaxReceivedMessageSizeExceededTitle, MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message, ex.StackTrace);
                MessageBox.Show(OSCExceptionMessages.UnexpectedError,
                       "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return null;
        }