public async Task <ActionResult> Update(SalesForceModels.OpportunityModel input)
        {
            if (ModelState.IsValid)
            {
                var sfdcResponse = new SalesForceModels.SalesForceResponseModel();
                var client       = await _salesForceService.CreateForceClient();

                input.StageName  = GlobalHelper.GetStageName(Convert.ToInt32(input.StageName));
                input.Type       = GlobalHelper.GetType(Convert.ToInt32(input.Type));
                input.LeadSource = GlobalHelper.GetLeadSource(Convert.ToInt32(input.LeadSource));

                // Do not specify Id or an external ID field in the request body or an error is generated.
                // https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_sobject_upsert.htm
                var sfId = input.Id;
                input.Id = null;

                sfdcResponse = await _dbConnector.UpdateOpportunity(client, sfId, input);

                TempData["NotificationType"] = sfdcResponse.IsSuccess
                    ? NotificationType.Success.ToString()
                    : NotificationType.Error.ToString();

                TempData["Notification"] = sfdcResponse.Details;
                return(RedirectToAction("Index", "Opportunities"));
            }
            TempData["NotificationType"] = NotificationType.Error.ToString();
            TempData["Notification"]     = GlobalHelper.GetErrorListFromModelState(ModelState);
            return(View(input));
        }
        public async Task <ActionResult> Add(SalesForceModels.OpportunityModel input)
        {
            if (ModelState.IsValid)
            {
                var sfdcResponse = new SalesForceModels.SalesForceResponseModel();
                var client       = await _salesForceService.CreateForceClient();

                input.StageName  = GlobalHelper.GetStageName(Convert.ToInt32(input.StageName));
                input.Type       = GlobalHelper.GetType(Convert.ToInt32(input.Type));
                input.LeadSource = GlobalHelper.GetLeadSource(Convert.ToInt32(input.LeadSource));

                sfdcResponse = await _dbConnector.CreateOpportunity(client, input);

                TempData["NotificationType"] = sfdcResponse.IsSuccess
                    ? NotificationType.Success.ToString()
                    : NotificationType.Error.ToString();

                TempData["Notification"] = sfdcResponse.Details;
                return(RedirectToAction("Index", "Opportunities"));
            }

            TempData["NotificationType"] = NotificationType.Error.ToString();
            TempData["Notification"]     = GlobalHelper.GetErrorListFromModelState(ModelState);
            return(View(input));
        }
        public async Task <ActionResult> Update(string opportunity)
        {
            var model = new SalesForceModels.OpportunityModel();

            try
            {
                var client = await _salesForceService.CreateForceClient();

                model = await _dbConnector.GetOpportunityById(client, opportunity);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(View(model));
        }
        public async Task <SalesForceModels.OpportunityModel> GetOpportunityById(ForceClient client, string opportunityId)
        {
            var opportunityModel = new SalesForceModels.OpportunityModel();
            var opportunity      = await client.QueryByIdAsync <SalesForceModels.OpportunityModel>("Opportunity", opportunityId);

            if (opportunity != null)
            {
                opportunityModel.Id          = opportunity.Id;
                opportunityModel.LeadSource  = opportunity.LeadSource;
                opportunityModel.StageName   = opportunity.StageName;
                opportunityModel.Type        = opportunity.Type;
                opportunityModel.Amount      = opportunity.Amount;
                opportunityModel.Name        = opportunity.Name;
                opportunityModel.Probability = opportunity.Probability;
                opportunityModel.CloseDate   = opportunity.CloseDate;
            }
            return(opportunityModel);
        }
        public async Task <SalesForceModels.SalesForceResponseModel> CreateOpportunity(ForceClient client, SalesForceModels.OpportunityModel opportunity)
        {
            var result = await client.CreateAsync("Opportunity", opportunity);

            return(new SalesForceModels.SalesForceResponseModel
            {
                IsSuccess = result.Success,
                Details = result.Success ? "Opportunity successfully created." : "Problem while creating opportunity into SFDC.Please refresh the page and try again."
            });
        }