Exemple #1
0
        /// <summary>
        /// Create an Opportunity in OSC
        /// </summary>
        /// <param name="opportunityModel">OpportunityModel</param>
        /// <returns></returns>
        public OpportunityModel CreateOpportunity(OpportunityModel opportunityModel)
        {
            OpportunityModel resultModel = null;

            try
            {
                if (opportunityModel != null)
                {
                    Opportunity opportunity = new Opportunity();
                    opportunity.Name                          = opportunityModel.Name;
                    opportunity.TargetPartyId                 = opportunityModel.TargetPartyId;
                    opportunity.TargetPartyIdSpecified        = opportunityModel.TargetPartyIdSpecified;
                    opportunity.OwnerResourcePartyId          = opportunityModel.OwnerResourcePartyId;
                    opportunity.OwnerResourcePartyIdSpecified = opportunityModel.OwnerResourcePartyIdSpecified;
                    opportunity.KeyContactId                  = opportunityModel.KeyContactId;
                    opportunity.KeyContactIdSpecified         = opportunityModel.KeyContactIdSpecified;

                    OpportunityResource resource = new OpportunityResource();
                    resource.ResourceId          = opportunityModel.OpportunityResourceModel.ResourceId;
                    resource.ResourceIdSpecified = opportunityModel.OpportunityResourceModel.ResourceIdSpecified;
                    resource.OwnerFlag           = opportunityModel.OpportunityResourceModel.OwnerFlag;
                    resource.OwnerFlagSpecified  = opportunityModel.OpportunityResourceModel.OwnerFlagSpecified;

                    OpportunityResource[] resources = new OpportunityResource[] { resource };
                    opportunity.OpportunityResource = resources;
                    if (!OSCCommonUtil.ValidateCurrentSiteName())
                    {
                        resultModel = new OpportunityModel();
                        resultModel.OpportunityId = OSCOpportunitiesCommon.DefaultOpportunitySalesLeadID;
                        return(resultModel);
                    }
                    Opportunity result = _opportunityService._opportunityClient.createOpportunity(opportunity);

                    resultModel = new OpportunityModel();
                    resultModel.OpportunityId = result.OptyId;
                }
            }
            catch (Exception exception)
            {
                _logger.Debug("Error occured while creating opportunity. Opportunity Not Created in Sales Cloud.", exception.StackTrace);
                MessageBox.Show(OSCExceptionMessages.LeadOpportunityCannotBeCreated, OSCExceptionMessages.LeadNotCreatedTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(resultModel);
        }
Exemple #2
0
        /// <summary>
        /// Create a ServiceLead in OSC
        /// </summary>
        /// <param name="leadModel">LeadModel</param>
        /// <returns></returns>
        public LeadModel CreateServiceLead(LeadModel leadModel)
        {
            LeadModel resultModel = null;

            try
            {
                if (leadModel != null)
                {
                    SalesLead lead = new SalesLead();
                    lead.Name                      = leadModel.Name;
                    lead.CustomerId                = leadModel.CustomerId;
                    lead.CustomerIdSpecified       = leadModel.CustomerIdSpecified;
                    lead.PrimaryContactId          = leadModel.PrimaryContactId;
                    lead.PrimaryContactIdSpecified = leadModel.PrimaryContactIdSpecified;
                    lead.OwnerId                   = leadModel.OwnerId;
                    lead.OwnerIdSpecified          = leadModel.OwnerIdSpecified;

                    if (!OSCCommonUtil.ValidateCurrentSiteName())
                    {
                        resultModel        = new LeadModel();
                        resultModel.LeadId = OSCOpportunitiesCommon.DefaultOpportunitySalesLeadID;
                        return(resultModel);
                    }

                    SalesLeadResult leadResult = _leadService._leadClient.createSalesLead(lead);
                    var             result     = leadResult.Value.FirstOrDefault();

                    if (result != null)
                    {
                        resultModel        = new LeadModel();
                        resultModel.LeadId = result.LeadId;
                    }
                }
            }
            catch (Exception exception)
            {
                _logger.Debug("Error occured while creating lead. Lead Not Created in Sales Cloud. Exception: " + exception.StackTrace);
                MessageBox.Show(OSCExceptionMessages.LeadOpportunityCannotBeCreated, OSCExceptionMessages.LeadNotCreatedTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(resultModel);
        }