Exemple #1
0
        /// <summary>
        /// Deletes the quotes.
        /// </summary>
        /// <param name="quoteIdList">The quote identifier list.</param>
        /// <returns></returns>
        public int DeleteQuotes(string quoteIdList)
        {
            List <int?> opportunityIdList = new List <int?>();

            var quoteDl = new QuoteDL();
            int result  = quoteDl.DeleteQuotes(quoteIdList, ref opportunityIdList);

            var opportunityDl = new OpportunityDL();

            foreach (int opportunityID in opportunityIdList)
            {
                try
                {
                    result += opportunityDl.CalculateOpportunityRollups(opportunityID);
                }
                catch (Exception e)
                {
                    _applicationLogDL.AddErrorMessage(0, "Calculate rollup returned error for oppId:" + opportunityID, e.Message);
                }
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Updates the opportunity.
        /// </summary>
        /// <param name="quoteDto">The quote dto.</param>
        /// <returns></returns>
        public int UpdateQuote(QuoteDto quoteDto)
        {
            int        result;
            string     quoteID           = quoteDto.QuoteID.ToString(CultureInfo.InvariantCulture);
            List <int> opportunityIDList = new List <int>();

            using (var sdaCloudEntities = new SDACloudEntities())
            {
                using (sdaCloudEntities)
                {
                    using (var transactionScope = new TransactionScope())
                    {
                        var existingQuote = sdaCloudEntities.Quotes.FirstOrDefault(i => i.ClientID == quoteDto.ClientID && i.QuoteID == quoteID);

                        if (existingQuote != null)
                        {
                            DateTime resultDate;
                            DateTime.TryParse(quoteDto.SDALastUpdDT, out resultDate);
                            if (resultDate > existingQuote.SDALastUpdDT)
                            {
                                // Add the opp to calculate rollups for the old value
                                opportunityIDList.Add(existingQuote.OppID);
                                //if (quoteDto.OppID>0)
                                //    existingQuote.OppID = quoteDto.OppID;
                                if (!string.IsNullOrEmpty(quoteDto.CRMOppID))
                                {
                                    existingQuote.CRMOppID = quoteDto.CRMOppID;
                                }
                                if (!string.IsNullOrEmpty(quoteDto.QuoteSiteDesc))
                                {
                                    existingQuote.QuoteSiteDesc = quoteDto.QuoteSiteDesc;
                                }
                                if (quoteDto.QuotedAmount != null)
                                {
                                    existingQuote.QuotedAmount = quoteDto.QuotedAmount ?? 0;
                                }
                                if (quoteDto.QuotedCost != null)
                                {
                                    existingQuote.QuotedCost = quoteDto.QuotedCost ?? 0;
                                }
                                if (quoteDto.QuoteMargin != null)
                                {
                                    existingQuote.QuoteMargin = quoteDto.QuoteMargin ?? 0;
                                }
                                if (!string.IsNullOrEmpty(quoteDto.Rollup))
                                {
                                    existingQuote.Rollup = quoteDto.Rollup;
                                }
                                existingQuote.FilePlatformFileID = quoteDto.FilePlatformFileID;
                                existingQuote.DeleteInd          = "N";

                                if (!string.IsNullOrEmpty(quoteDto.LastFileSavedLocation))
                                {
                                    existingQuote.LastFileSavedLocation = quoteDto.LastFileSavedLocation;
                                }

                                existingQuote.SDALastUpdBy = quoteDto.SDALastUpdBy;
                                existingQuote.SDALastUpdDT = resultDate;

                                existingQuote.CloudLastUpdBy = quoteDto.CloudLastUpdById;
                                existingQuote.CloudLastUpdDT = DateTime.UtcNow;

                                existingQuote.CreateDT = DateTime.TryParse(quoteDto.CreateDT,
                                                                           out resultDate)
                                    ? resultDate
                                    : DateTime.MinValue;
                                existingQuote.CreateBy = quoteDto.CreateBy;

                                existingQuote.ClientDefinedText1 = quoteDto.ClientDefinedText1;
                                existingQuote.ClientDefinedText2 = quoteDto.ClientDefinedText2;
                                existingQuote.ClientDefinedText3 = quoteDto.ClientDefinedText3;
                                existingQuote.ClientDefinedText4 = quoteDto.ClientDefinedText4;
                                existingQuote.ClientDefinedText5 = quoteDto.ClientDefinedText5;


                                if (quoteDto.ClientDefinedTotal1 != null)
                                {
                                    existingQuote.ClientDefinedTotal1 = quoteDto.ClientDefinedTotal1 ?? 0;
                                }
                                if (quoteDto.ClientDefinedTotal2 != null)
                                {
                                    existingQuote.ClientDefinedTotal2 = quoteDto.ClientDefinedTotal2 ?? 0;
                                }
                                if (quoteDto.ClientDefinedTotal3 != null)
                                {
                                    existingQuote.ClientDefinedTotal3 = quoteDto.ClientDefinedTotal3 ?? 0;
                                }
                                if (quoteDto.ClientDefinedTotal4 != null)
                                {
                                    existingQuote.ClientDefinedTotal4 = quoteDto.ClientDefinedTotal4 ?? 0;
                                }
                                if (quoteDto.ClientDefinedTotal5 != null)
                                {
                                    existingQuote.ClientDefinedTotal5 = quoteDto.ClientDefinedTotal5 ?? 0;
                                }
                                if (quoteDto.ClientDefinedTotal6 != null)
                                {
                                    existingQuote.ClientDefinedTotal6 = quoteDto.ClientDefinedTotal6 ?? 0;
                                }
                                if (quoteDto.ClientDefinedTotal7 != null)
                                {
                                    existingQuote.ClientDefinedTotal7 = quoteDto.ClientDefinedTotal7 ?? 0;
                                }
                                if (quoteDto.ClientDefinedTotal8 != null)
                                {
                                    existingQuote.ClientDefinedTotal8 = quoteDto.ClientDefinedTotal8 ?? 0;
                                }
                                if (quoteDto.ClientDefinedTotal9 != null)
                                {
                                    existingQuote.ClientDefinedTotal9 = quoteDto.ClientDefinedTotal9 ?? 0;
                                }
                                if (quoteDto.ClientDefinedTotal10 != null)
                                {
                                    existingQuote.ClientDefinedTotal10 = quoteDto.ClientDefinedTotal10 ?? 0;
                                }

                                Opportunity existingOpportunity;

                                if (quoteDto.CRMOppID != null)
                                {
                                    quoteDto.CRMOppID = quoteDto.CRMOppID.Trim();
                                }

                                if (!string.IsNullOrEmpty(quoteDto.CRMOppID))
                                {
                                    existingOpportunity = sdaCloudEntities.Opportunities.FirstOrDefault(i => i.ClientID == quoteDto.ClientID && i.CRMOppID == quoteDto.CRMOppID);

                                    //Update the opp ID
                                    //It could be different than the old and new value
                                    if (existingOpportunity != null)
                                    {
                                        existingQuote.OppID           = existingOpportunity.OppID;
                                        existingOpportunity.DeleteInd = "N";

                                        // Add the opp to calculate rollups for the updated
                                        opportunityIDList.Add(existingOpportunity.OppID);
                                    }
                                    else
                                    {
                                        var newOpportunity = new Opportunity
                                        {
                                            CRMOppID       = quoteDto.CRMOppID,
                                            ClientID       = quoteDto.ClientID,
                                            OppStatus      = 1,
                                            NumofQuotes    = 0,
                                            DeleteInd      = "N",
                                            CloudLastUpdBy = quoteDto.CloudLastUpdById,
                                            CloudLastUpdDT = DateTime.UtcNow
                                        };

                                        sdaCloudEntities.Opportunities.AddObject(newOpportunity);
                                        sdaCloudEntities.SaveChanges();

                                        existingQuote.OppID = newOpportunity.OppID;
                                        // Add the opp to calculate rollups for the new
                                        opportunityIDList.Add(newOpportunity.OppID);
                                    }
                                }
                                else
                                {
                                    if (quoteDto.QuoteIDMainSite != null)
                                    {
                                        quoteDto.QuoteIDMainSite = quoteDto.QuoteIDMainSite.Trim();
                                    }

                                    if (!string.IsNullOrEmpty(quoteDto.QuoteIDMainSite))
                                    {
                                        existingOpportunity =
                                            sdaCloudEntities.Opportunities.FirstOrDefault(
                                                i => i.ClientID == quoteDto.ClientID && i.QuoteIDMainSite == quoteDto.QuoteIDMainSite);

                                        if (existingOpportunity != null)
                                        {
                                            existingQuote.OppID           = existingOpportunity.OppID;
                                            existingQuote.CRMOppID        = existingOpportunity.CRMOppID;
                                            existingOpportunity.DeleteInd = "N";

                                            // Add the opp to calculate rollups for the dummy
                                            opportunityIDList.Add(existingOpportunity.OppID);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                string message = "Cannot update Quote with Quote Id:" + quoteDto.QuoteID + ", because the UserLastUpdDT was earlier than the existing value.";

                                throw new OutdatedQuoteException(message);
                            }
                        }

                        result = sdaCloudEntities.SaveChanges();

                        transactionScope.Complete();
                    }
                }
            }

            foreach (int opportunityID in opportunityIDList)
            {
                try
                {
                    _opportunityDl.CalculateOpportunityRollups(opportunityID);
                }
                catch (Exception e)
                {
                    _applicationLogDL.AddErrorMessage(0, "Calculate rollup returned error", e.Message);
                }
            }

            return(result);
        }