Пример #1
0
        public async Task <string> CreateOpportunityAsync(SalesForceResponse salesForceResponse, SalesForceOpprtunity opp)
        {
            LoggerService.Debug("Entered CreateOpportunityAsync", "INFO");
            string opportunityId = string.Empty;

            try
            {
                CreateOpportunityFields createOpportunityFields = new CreateOpportunityFields();

                createOpportunityFields.Name               = opp.OppurtunityName;
                createOpportunityFields.Contact__c         = opp.ContactID;
                createOpportunityFields.CloseDate          = opp.closedate;
                createOpportunityFields.StageName          = opp.stage;
                createOpportunityFields.AccountId          = opp.AccountID;
                createOpportunityFields.Byte_FileDataID__c = opp.ByteFileDataID;

                LoggerService.Debug("Setting Opp data, and calling CreateOpportunityAsync()", "");
                opportunityId = await CreateOpportunityAsync(salesForceResponse, createOpportunityFields);

                bool isUpdated = false;
                if (opportunityId != null)
                {
                    isUpdated = await UpdateOpportunityAsync(salesForceResponse, opp, opportunityId, "4"); //Creating New opp based on loanstatus code = 4
                }
            }
            catch (Exception ex)
            {
                LoggerService.Error("", "SalesForceBL->CreateOpportunityAsync(): " + "\r\nError Message: " + ex.Message + "\r\nStackTrace: " + ex.StackTrace);
            }

            return(opportunityId);
        }
Пример #2
0
        private async Task <string> CreateOpportunityAsync(SalesForceResponse salesForceResponse, CreateOpportunityFields createOpportunityFields)
        {
            string opportunityId        = string.Empty;
            string createOpportunityUrl = salesForceResponse.instance_url + "/services/data/v26.0/sobjects/Opportunity/";

            LoggerService.Debug("Entered CreateOpportunityAsync()", "INFO");
            try
            {
                LoggerService.Debug("Inside CreateOpportunityAsync() 2", "");
                using (HttpClient httpClient = new HttpClient())
                {
                    httpClient.DefaultRequestHeaders.Add("Authorization", "OAuth " + salesForceResponse.access_token);

                    httpResponseMessage = await httpClient.PostAsJsonAsync(createOpportunityUrl, createOpportunityFields);

                    LoggerService.Debug("CreateOpportunityAsync()- Response for httpResponseMessage:", httpResponseMessage);

                    var opportunityUserResult = await httpResponseMessage.Content.ReadAsStringAsync();

                    LoggerService.Debug("CreateOpportunityAsync() - Response for opportunityUserResult :", opportunityUserResult);

                    if (httpResponseMessage != null && httpResponseMessage.IsSuccessStatusCode)
                    {
                        LoggerService.Debug("httpResponseMessage = SuccessStatusCode ", "");
                        var opportunityUserResultObject = (IDictionary <string, object>)javaScriptSerializer.DeserializeObject(opportunityUserResult);
                        opportunityId = Convert.ToString(opportunityUserResultObject["id"]);
                        LoggerService.Debug("opportunityId:", opportunityId);
                    }
                    else
                    {
                        LoggerService.Debug("httpResponseMessage = Error ", httpResponseMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerService.Error("", "SalesForceBL->CreateOpportunityAsync() 2: " + "\r\nError Message: " + ex.Message + "\r\nStackTrace: " + ex.StackTrace);
            }

            return(opportunityId);
        }