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));
        }
Example #3
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));
        }
        public async Task <JsonResult> Delete(string opportunityId)
        {
            var sfdcResponse = new SalesForceModels.SalesForceResponseModel();

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

                sfdcResponse = await _dbConnector.DeleteOpportunity(client, opportunityId);
            }
            catch (Exception ex)
            {
                sfdcResponse.Details = ex.Message;
            }

            return(Json(new
            {
                IsDeleted = sfdcResponse.IsSuccess,
                Details = sfdcResponse.Details
            }, JsonRequestBehavior.DenyGet));
        }
Example #5
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));
        }