/// <summary> /// Formats the email body. /// </summary> /// <param name="opportunity">The opportunity.</param> /// <returns></returns> private string FormatEmailBody(IOpportunity opportunity) { IContextService context = ApplicationContext.Current.Services.Get <IContextService>(true); TimeZone timeZone = (TimeZone)context.GetContext("TimeZone"); string datePattern = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern; string oppProducts = String.Empty; bool oppWon = opportunity.Status.Equals(GetLocalResourceObject("Status_ClosedWon").ToString()); bool oppLost = opportunity.Status.Equals(GetLocalResourceObject("Status_ClosedLost").ToString()); string emailBody = String.Format("{0} \x0D\x0A", GetLocalResourceObject("lblEmailInfo.Caption")); emailBody += String.Format("{0} {1} \x0D\x0A", GetLocalResourceObject("lblEmailOppDesc.Caption"), CheckForNullValue(opportunity.Description)); emailBody += String.Format("{0} {1} \x0D\x0A", GetLocalResourceObject("lblEmailOppAccount.Caption"), CheckForNullValue(opportunity.Account != null ? opportunity.Account.AccountName : String.Empty)); emailBody += String.Format("{0} {1} \x0D\x0A", GetLocalResourceObject("EmailOppAcctMgr.Caption"), CheckForNullValue(opportunity.AccountManager)); emailBody += String.Format("{0} {1} \x0D\x0A", GetLocalResourceObject("EmailOppReseller.Caption"), CheckForNullValue(opportunity.Reseller)); emailBody += String.Format("{0} {1} \x0D\x0A", GetLocalResourceObject("EmailOppEstClose.Caption"), opportunity.EstimatedClose.HasValue ? timeZone.UTCDateTimeToLocalTime((DateTime)opportunity.EstimatedClose).ToString (datePattern) : String.Empty); emailBody += String.Format("{0} {1} \x0D\x0A", GetLocalResourceObject("EmailOppCloseProb.Caption"), CheckForNullValue(opportunity.CloseProbability)); emailBody += String.Format("{0} {1} \x0D\x0A\x0D\x0A", GetLocalResourceObject("EmailOppComments.Caption"), CheckForNullValue(opportunity.Notes)); emailBody += String.Format("{0} \x0D\x0A", GetLocalResourceObject("EmailOppValue.Caption")); //emailBody += BusinessRuleHelper.AccountingSystemHandlesSO() // ? String.Format("{0} {1} \x0D\x0A", GetLocalResourceObject("EmailOppPotential.Caption"), // curERPOpenBaseSalesPotential.FormattedText) // : String.Format("{0} {1} \x0D\x0A", GetLocalResourceObject("EmailOppPotential.Caption"), // curOpenBaseSalesPotential.FormattedText); emailBody += String.Format("{0} {1} \x0D\x0A\x0D\x0A", GetLocalResourceObject("EmailOppWeighted.Caption"), curBaseWeighted.FormattedText); emailBody += String.Format("{0} \x0D\x0A", GetLocalResourceObject("EmailOppSummary.Caption")); if (oppWon || oppLost) { emailBody += String.Format("{0} \x0D\x0A", String.Format( GetLocalResourceObject("EmailOppWonLostSummary.Caption").ToString(), dtpClosedWonSummary.Text, Convert.ToString(opportunity.DaysOpen))); emailBody += oppWon ? String.Format("{0} \x0D\x0A", String.Format( GetLocalResourceObject("EmailOppReasonWon.Caption").ToString(), CheckForNullValue(opportunity.Reason))) : String.Format("{0} \x0D\x0A", String.Format( GetLocalResourceObject("EmailOppReasonLost.Caption").ToString(), CheckForNullValue(opportunity.Reason))); } else { emailBody += String.Format("{0} \x0D\x0A", String.Format(GetLocalResourceObject("EmailOppStageSummary.Caption").ToString(), CheckForNullValue(opportunity.Stage))); } emailBody += String.Format("{0} \x0D\x0A\x0D\x0A", String.Format(GetLocalResourceObject("lblEmailOppType.Caption").ToString(), CheckForNullValue(opportunity.Type))); emailBody += String.Format("{0} \x0D\x0A", GetLocalResourceObject("EmailOppProducts.Caption")); oppProducts = Enumerable.Aggregate(opportunity.Products, oppProducts, (current, oppProduct) => current + String.Format("{0} ({1}); ", oppProduct.Product, oppProduct.Quantity)); if (!string.IsNullOrEmpty(oppProducts)) { emailBody += String.Format("{0} \x0D\x0A\x0D\x0A", CheckForNullValue(oppProducts.Substring(0, oppProducts.Length - 2))); } if (oppWon || oppLost) { emailBody += String.Format("{0} \x0D\x0A{1} \x0D\x0A\x0D\x0A", GetLocalResourceObject("EmailOppCompetitors.Caption"), GetOpportunityCompetitors()); } emailBody += String.Format("{0} \x0D\x0A", GetLocalResourceObject("EmailOppContacts.Caption")); emailBody = Enumerable.Aggregate(opportunity.Contacts, emailBody, (current, oppContact) => current + String.Format("{0} \x0D\x0A", String.Format("{0}, {1}; {2}", oppContact.Contact.Name, oppContact.Contact.Title, oppContact.SalesRole))); return(PortalUtil.JsonEncode(emailBody)); }