Example #1
0
        /// <summary>
        /// Get quote info by client id and quote id
        /// </summary>
        /// <param name="clientID">The client id</param>
        /// <param name="quoteID">The quote id</param>
        /// <returns></returns>
        public Response GetQuoteByClientIdUserIdAndQuoteId(int clientId, int userId, string quoteID)
        {
            var response = new Response();
            var quoteBL  = new QuoteBL();
            var userBL   = new UserBL();

            // Get the opportunity data
            QuoteDto quote = quoteBL.GetQuoteByClientIDAndQuoteID(clientId, quoteID);

            if (quote != null)
            {
                var client = userBL.GetByUserIdAndClientId(clientId, userId);
                if (client != null)
                {
                    if (client.DeleteInd.ToString().ToUpper().Equals("N"))
                    {
                        response.Results.Add("Success");
                        // Serialize the object
                        //string userSerialize = JsonConvert.SerializeObject(quote);
                        string FilePlatformFileIDSerialize = quote.FilePlatformFileID;
                        response.Results.Add(FilePlatformFileIDSerialize);
                        return(response);
                    }
                    else
                    {
                        response.Results.Add("Error");
                        response.Errors.Add("User inactive.");
                    }
                }
                else
                {
                    response.Results.Add("Error");
                    response.Errors.Add("The user does not exist");
                }
            }
            else
            {
                response.Results.Add("Error");
                response.Errors.Add("Invalid opportunity data.");
            }
            return(response);
        }
Example #2
0
        /// <summary>
        /// Get quote info by client id and quote id
        /// </summary>
        /// <param name="clientID">The client id</param>
        /// <param name="quoteID">The quote id</param>
        /// <returns></returns>
        public Response GetQuoteByClientIDAndQuoteID(int clientID, string quoteID)
        {
            var response = new Response();
            var quoteBL  = new QuoteBL();

            // Get the opportunity data
            QuoteDto quote = quoteBL.GetQuoteByClientIDAndQuoteID(clientID, quoteID);

            if (quote != null)
            {
                response.Results.Add("Success");
                // Serialize the object
                //string userSerialize = JsonConvert.SerializeObject(quote);
                string userSerialize = quote.Rollup;
                response.Results.Add(userSerialize);
            }
            else
            {
                response.Results.Add("Error");
                response.Errors.Add("Invalid opportunity data.");
            }
            return(response);
        }
Example #3
0
        /// <summary>
        /// Runs the update CRM quotes.
        /// </summary>
        /// <param name="quoteDto">The quote dto.</param>
        /// <returns></returns>
        public Response RunUpdateCRMQuotes(QuoteDto quoteDto)
        {
            // Initialise variables
            Response response = Authenticate(quoteDto.LoginInfo);

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

            var quotesToUpdate = quoteDto.QuoteTable;
            var xRefDef        = quoteDto.CRMXrefDefinition;

            CreateSqlAndMapper(xRefDef);

            try
            {
                var quoteBl   = new QuoteBL();
                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 <QuoteDto>();
                var recordsSdaAdd    = new List <QuoteDto>();
                int crmClientId      = -1;

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

                    var strQuoteId = string.Empty;
                    if (row["QuoteID"] != DBNull.Value)
                    {
                        strQuoteId = row["QuoteID"].ToString();
                    }
                    else
                    {
                        response.Errors.Add("Invalid QuoteId.");
                    }

                    var quote = quoteBl.GetQuoteByClientIDAndQuoteID(clientID, strQuoteId);

                    bool isNewQuote;
                    if (quote == null)
                    {
                        // Create a new opportunity
                        quote      = new QuoteDto();
                        isNewQuote = true;
                    }
                    else
                    {
                        isNewQuote = false;
                    }

                    // Copy the fields to the opportunity
                    var type = quote.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(quote, propertyInfo,
                                                      row[mappingObject.SdaField]);
                            }
                        }
                    }

                    if (isNewQuote)
                    {
                        recordsSdaAdd.Add(quote);
                    }
                    else
                    {
                        recordsSdaUpdate.Add(quote);
                    }
                }

                // Update the list of opportunities on Salesforce
                response = new Response();
                Response responseUpdate = quoteBl.UpdateSdaCloudQuote(recordsSdaUpdate);
                Response responseAdd    = quoteBl.AddSdaCloudQuote(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);
            }

            return(response);
        }