Exemple #1
0
        /// <summary>
        /// Get the opportunities for client
        /// </summary>
        /// <param name="clientID">The Client ID</param>
        /// <param name="opportunityName">The opportunity name</param>
        /// <param name="companyName">The company name</param>
        /// <param name="owner">The owner</param>
        /// <param name="opportunityStatus">The opportunity status</param>
        /// <returns></returns>
        public Response GetOpportunities(int clientID, string oppId, string opportunityName, string companyName, string owner, string opportunityStatus)
        {
            var response      = new Response();
            var opportunityBL = new OpportunityBL();

            List <OpportunityDto> opportunities = opportunityBL.GetOpportunities(clientID, oppId, opportunityName, companyName, owner, opportunityStatus);

            response.Results.Add("Success");

            List <SearchOpportunityDto> searchOpportunities = opportunities.Select(opp => new SearchOpportunityDto
            {
                OppID          = opp.OppID,
                CRMOppID       = opp.CRMOppID,
                OppName        = opp.OppName,
                CompanyName    = opp.CompanyName,
                OppStatus      = opp.OppStatus.HasValue ? opp.OppStatus.Value.ToString() : string.Empty,
                OppStatusName  = opp.OppStatusName,
                OppProbability = opp.OppProbability.HasValue ? opp.OppProbability.Value.ToString() : string.Empty,
                OppCloseDate   = opp.OppCloseDate,
                OppOwner       = opp.OppOwner,
                OppOwnerName   = opp.OppOwnerName
            }).ToList();

            string userSerialize = JsonConvert.SerializeObject(searchOpportunities);

            response.Results.Add(userSerialize);

            return(response);
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HomeController"/> class.
 /// </summary>
 public HomeController()
 {
     _userBl               = new UserBL();
     _opportunityBl        = new OpportunityBL();
     _quoteBl              = new QuoteBL();
     _clientLoginBL        = new ClientLoginBL();
     _clientDefinedFieldBL = new ClientDefinedFieldBL();
     _utilityBL            = new UtilityBL();
 }
Exemple #3
0
        /// <summary>
        /// Get an opportunity by CRMOppID
        /// </summary>
        /// <param name="clientID">The ClientID</param>
        /// <param name="value">The value.</param>
        /// <param name="searchType">Type of the search.</param>
        /// <returns></returns>
        public Response GetOpportunityByClientIDAndSearchType(int clientID, string value, string searchType)
        {
            var            response      = new Response();
            var            opportunityBL = new OpportunityBL();
            OpportunityDto opportunity   = null;

            // Get the opportunity data
            switch (searchType.ToUpper())
            {
            case "CRMOPPID":
                opportunity = opportunityBL.GetNonDeletedOpportunityByClientIDAndCRMOppID(clientID, value);
                break;

            case "QUOTEID":
                opportunity = opportunityBL.GetNonDeletedOpportunityByClientIDAndQuoteID(clientID, value);
                break;

            case "OPPID":
                int oppId;
                if (int.TryParse(value, out oppId))
                {
                    opportunity = opportunityBL.GetNonDeletedOpportunityByClientIDAndOppID(clientID, oppId);
                }
                break;
            }

            if (opportunity != null)
            {
                response.Results.Add("Success");
                // Serialize the object
                string userSerialize = JsonConvert.SerializeObject(opportunity);
                response.Results.Add(userSerialize);
            }
            else
            {
                response.Results.Add("Error");
                response.Errors.Add("Invalid opportunity data.");
            }
            return(response);
        }
Exemple #4
0
        public Response RunUpdateCRMOpportunities(OpportunityDto opportunityDto)
        {
            // Initialise variables
            Response response = Authenticate(opportunityDto.LoginInfo);

            if (response.Errors.Count > 0)
            {
                return(response);
            }

            var opportunitiesToUpdate = opportunityDto.OpportunityTable;

            var xRefDef = opportunityDto.CRMXrefDefinition;

            CreateSqlAndMapper(xRefDef);

            try
            {
                var opportunityBL = new OpportunityBL();
                var utilityBl     = new UtilityBL();

                // Create a list of opportunities
                // mapping the values of the opportunity table with the ones on the Salesforce Opportunity object
                var recordsSdaUpdate = new List <OpportunityDto>();
                var recordsSdaAdd    = new List <OpportunityDto>();

                int crmClientId = -1;

                foreach (DataRow row in opportunitiesToUpdate.Rows)
                {
                    int clientID = -1;
                    if (row.Table.Columns.Contains("ClientID") && row["ClientID"] != DBNull.Value)
                    {
                        int.TryParse(row["ClientID"].ToString(), out clientID);
                        crmClientId = clientID;
                    }
                    else
                    {
                        response.Errors.Add("Invalid Client Id.");
                    }

                    var strCRMOppId = string.Empty;
                    if (row.Table.Columns.Contains("CRMOppID") && row["CRMOppID"] != DBNull.Value)
                    {
                        strCRMOppId = row["CRMOppID"].ToString();
                    }

                    List <OppStatusDto> lstat = utilityBl.GetStatuses(clientID);
                    bool hasStatus            = false;
                    if (row.Table.Columns.Contains("OppStatus") && row["OppStatus"] != DBNull.Value)
                    {
                        var strStatus = row["OppStatus"].ToString();
                        int statValue = 0;
                        foreach (var stat in lstat)
                        {
                            if (stat.OppStatus.ToLower().Trim().Equals(strStatus.ToLower().Trim()))
                            {
                                statValue = stat.ID;
                                break;
                            }
                        }

                        if (statValue > 0)
                        {
                            row["OppStatus"] = statValue;
                            hasStatus        = true;
                        }
                    }

                    if (!hasStatus)
                    {
                        if (lstat.Count > 0)
                        {
                            var defaultStatus = lstat.Where(s => s.Default.Equals("Y")).FirstOrDefault();
                            if (defaultStatus != null)
                            {
                                row["OppStatus"] = defaultStatus.ID;
                                hasStatus        = true;
                            }
                        }

                        if (!hasStatus)
                        {
                            response.Errors.Add("Invalid Opp Status.");
                        }
                    }


                    OpportunityDto opportunity = null;
                    if (!string.IsNullOrEmpty(strCRMOppId))
                    {
                        opportunity = opportunityBL.GetOpportunityByClientIDAndCRMOppID(clientID, strCRMOppId);
                    }

                    bool isNewOpportunity;
                    if (opportunity == null)
                    {
                        // Create a new opportunity
                        opportunity      = new OpportunityDto();
                        isNewOpportunity = true;
                    }
                    else
                    {
                        isNewOpportunity = false;
                    }

                    // Copy the fields to the opportunity
                    var type = opportunity.GetType();
                    //loop over the rows mapping the database field with the corresponding field on the CRM
                    foreach (var mappingObject in DatabaseToCRMMap)
                    {
                        var propertyInfo = type.GetProperty(mappingObject.CRMField);
                        if (propertyInfo != null)
                        {
                            if (row[mappingObject.SdaField] != DBNull.Value)
                            {
                                utilityBl.SetProperty(opportunity, propertyInfo,
                                                      row[mappingObject.SdaField]);
                            }
                        }
                    }

                    if (isNewOpportunity)
                    {
                        recordsSdaAdd.Add(opportunity);
                    }
                    else
                    {
                        recordsSdaUpdate.Add(opportunity);
                    }
                }

                // Update the list of opportunities on Salesforce
                response = new Response();
                Response responseUpdate = opportunityBL.UpdateSdaCloudOpportunity(recordsSdaUpdate);
                Response responseAdd    = opportunityBL.AddSdaCloudOpportunity(recordsSdaAdd);

                // Merge both results
                foreach (string result in responseUpdate.Results)
                {
                    response.Results.Add(result);
                }
                foreach (string result in responseAdd.Results)
                {
                    response.Results.Add(result);
                }
                //Merge both errors
                foreach (string error in responseUpdate.Errors)
                {
                    response.Errors.Add(error);
                }
                foreach (string error in responseAdd.Errors)
                {
                    response.Errors.Add(error);
                }
            }
            catch (Exception ex)
            {
                response.Errors.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.Errors.Add(ex.InnerException.Message);
                }
            }
            return(response);
        }