/// <summary>
        /// The get content.
        /// </summary>
        /// <param name="emailCargo">
        /// The email Job.
        /// </param>
        /// <returns>
        /// The <see cref="EmailContent"/>.
        /// </returns>
        /// <exception cref="TemplateRenderException">
        /// error while rendering the template
        /// </exception>
        public EmailData GetContent(object emailCargo)
        {
            EmailData          emailData          = null;
            CampaignEmailCargo campaignEmailCargo = emailCargo as CampaignEmailCargo;

            if (campaignEmailCargo != null)
            {
                string locationId = campaignEmailCargo.LocationId;
                CampaignTemplateData campaignTemplateData = new CampaignTemplateData
                {
                    EmailAddress         = campaignEmailCargo.EmailAddress,
                    UnsubscribeUrl       = campaignEmailCargo.UnsubscribeUrl,
                    LocationId           = locationId,
                    Content              = campaignEmailCargo.Content,
                    IncludeBusinessNames = campaignEmailCargo.IncludeBusinessNames
                };

                var model = this._templateModelCreator.GenerateModel(campaignTemplateData);
                if (model != null)
                {
                    EmailRenderingClient <CampaignDataContract> emailRenderingClient = new EmailRenderingClient
                                                                                       <CampaignDataContract>
                    {
                        EmailRenderingServiceUrl = campaignEmailCargo.EmailRenderingServiceAddress
                    };
                    emailData = new EmailData
                    {
                        Subject  = campaignEmailCargo.Subject,
                        HtmlBody = emailRenderingClient.RenderHtml(model)
                    };
                }
            }

            return(emailData);
        }
        /// <summary>
        /// Generate Email Model method
        /// </summary>
        /// <returns> The <see cref="CampaignDataContract"/>. </returns>
        public CampaignDataContract GenerateModel(EmailTemplateData modelData)
        {
            CampaignDataContract campaignDataContract = null;
            CampaignTemplateData campaignTemplateData = modelData as CampaignTemplateData;

            if (campaignTemplateData != null)
            {
                var          location    = Users.Dal.DataModel.Location.Parse(campaignTemplateData.LocationId);
                const string locationStr = "Bellevue"; //Having a constant value here and commenting the below code since
                                                       //this code doesn't make sense anymore in Earn program. Also sending of emails
                                                       //will now be moved to Epiphany service and this code won't be used anymore
                //if (location.Type == Users.Dal.DataModel.LocationType.Postal || location.Type == Users.Dal.DataModel.LocationType.City)
                //{
                //    Log.Info("Getting Location for user: {0}, locationId: {1}", campaignTemplateData.EmailAddress, campaignTemplateData.LocationId);
                //    var geoCodePoint = GeoSpatial.GetGeoData(WebUtility.HtmlEncode(string.Format("{0} {1} {2}", location.CountryCode, location.AdminDistrict, location.Value)), GeoSpatial.GeoSource.VirtualEarth);
                //    if (geoCodePoint != null && geoCodePoint.Location != null)
                //    {
                //        locationStr = geoCodePoint.Location.Locality;
                //        Log.Info("Retrieved Location info : {0} for user: {1}, locationId: {2}", locationStr, campaignTemplateData.EmailAddress, campaignTemplateData.LocationId);
                //    }
                //    else
                //    {
                //        Log.Warn("Couldn't fetch location data for user: {0}, locationId: {1}", campaignTemplateData.EmailAddress, location);
                //    }
                //}


                var refinements = new Refinements
                {
                    ResultsPerBusiness = 1,
                    Market             = string.Format("en-{0}", location.CountryCode),
                    Flights            = string.Format("{0},{1}", CloFlight, campaignTemplateData.Campaign)
                };

                if (campaignTemplateData.IncludeBusinessNames)
                {
                    string regionCode = string.Format("{0} {1} {2}", location.CountryCode, location.AdminDistrict, location.Value);
                    Task <IEnumerable <Deal> > getDealsTask = this._dealsClient.GetDealsByRegion(regionCode, null, null, DealsCount, refinements);
                    var           returnedDeals             = getDealsTask.Result.ToList();
                    List <string> businesses = new List <string>();
                    foreach (var deal in returnedDeals)
                    {
                        if (!businesses.Contains(deal.Business.Name) && businesses.Count < 20)
                        {
                            businesses.Add(deal.Business.Name);
                        }
                    }
                    campaignDataContract = new CampaignDataContract {
                        UnsubscribeUrl = campaignTemplateData.UnsubscribeUrl, Content = campaignTemplateData.Content, Location = locationStr, PostalCode = location.Value, Businesses = businesses
                    };
                }
                else
                {
                    campaignDataContract = new CampaignDataContract {
                        UnsubscribeUrl = campaignTemplateData.UnsubscribeUrl, Content = campaignTemplateData.Content, Location = locationStr, PostalCode = location.Value
                    };
                }
            }

            return(campaignDataContract);
        }