Beispiel #1
0
        public async Task <ActionResult> Add(SalesForceModels.LeadModel input)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var sfdcResponse = new SalesForceModels.SalesForceResponseModel();
                    var client       = await _salesForceService.CreateForceClient();

                    input.LastEditedBy__c = "Aleksandar [from api]";
                    input.LastEditedOn__c = DateTime.UtcNow;
                    input.Status          = GlobalHelper.GetStatus(Convert.ToInt32(input.Status));

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

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

                    TempData["Notification"] = sfdcResponse.Details;
                    return(RedirectToAction("Index", "Leads"));
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            TempData["NotificationType"] = NotificationType.Error.ToString();
            TempData["Notification"]     = GlobalHelper.GetErrorListFromModelState(ModelState);
            return(View(input));
        }
Beispiel #2
0
        public async Task <ActionResult> Update(string leadId)
        {
            var model = new SalesForceModels.LeadModel();

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

                model = await _dbConnector.GetLeadById(client, leadId);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(View(model));
        }
        public async Task <SalesForceModels.LeadModel> GetLeadById(ForceClient client, string leadId)
        {
            var leadModel = new SalesForceModels.LeadModel();
            var lead      = await client.QueryByIdAsync <SalesForceModels.LeadModel>("Lead", leadId);

            if (lead != null)
            {
                leadModel.Id              = lead.Id;
                leadModel.FirstName       = lead.FirstName;
                leadModel.LastName        = lead.LastName;
                leadModel.Company         = lead.Company;
                leadModel.Email           = lead.Email;
                leadModel.Status          = lead.Status;
                leadModel.Phone           = lead.Phone;
                leadModel.LastEditedBy__c = lead.LastEditedBy__c ?? string.Empty;
                leadModel.LastEditedOn__c = lead.LastEditedOn__c;
            }
            ;
            return(leadModel);
        }
Beispiel #4
0
        public async Task <ActionResult> Update(SalesForceModels.LeadModel input)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var sfdcResponse = new SalesForceModels.SalesForceResponseModel();
                    var client       = await _salesForceService.CreateForceClient();

                    input.LastEditedBy__c = "Aleksandar [from web app]";
                    input.LastEditedOn__c = DateTime.UtcNow;
                    input.Status          = GlobalHelper.GetStatus(Convert.ToInt32(input.Status));

                    // 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.UpdateLead(client, sfId, input);

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

                    TempData["Notification"] = sfdcResponse.Details;
                    return(RedirectToAction("Index", "Leads"));
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            TempData["NotificationType"] = NotificationType.Error.ToString();
            TempData["Notification"]     = GlobalHelper.GetErrorListFromModelState(ModelState);
            return(View(input));
        }
        public async Task <SalesForceModels.SalesForceResponseModel> CreateLead(ForceClient client, SalesForceModels.LeadModel lead)
        {
            var result = await client.CreateAsync("Lead", lead);

            // by accessing result.Id you can obtain the unique SalesForce ID for the lead you just created
            return(new SalesForceModels.SalesForceResponseModel
            {
                IsSuccess = result.Success,
                Details = result.Success ? "Lead successfully created." : "Problem while creating lead into SFDC.Please refresh the page and try again."
            });
        }
        public async Task <SalesForceModels.SalesForceResponseModel> UpdateLead(ForceClient client, string sfId, SalesForceModels.LeadModel lead)
        {
            var result = await client.UpdateAsync("Lead", sfId, lead);

            return(new SalesForceModels.SalesForceResponseModel
            {
                IsSuccess = result.Success,
                Details = result.Success ? "Lead successfully updated." : "Problem while updating lead into SFDC. Please refresh the page and try again."
            });
        }