private void PopulateDataFromJustGiving(CharityProfile charityProfile, CharitySearchResult thisCharity) { charityProfile.JgCharityData = JGCharitySearch.GetCharityDetails(Convert.ToInt32(thisCharity.CharityId)); charityProfile.CharityImage = "http://v3-sandbox.justgiving.com" + thisCharity.LogoFileName; var charityNewsOnGuardian = _guardianApiAdapter.SearchContentByCharityNameAndKeywords(charityProfile.JgCharityData); charityProfile.NewsItems = charityNewsOnGuardian.Response.Results ?? new List<Item>(); }
public CharityProfile LoadByRegNo(string regNo) { var generalDataUri = CharityComissionUriForRegistrationNumber(regNo); var generalDataDoc = new HtmlDocument(); var generalDataRaw = _httpGet.Get(generalDataUri); if (generalDataRaw.Contains("The page you have requested does not exist")) { generalDataRaw = _httpGet.Get(generalDataUri.Replace("CharityWithPartB", "CharityWithoutPartB")); } generalDataDoc.LoadHtml(generalDataRaw); var trusteeUri = CharityComissionUriForTrustees(regNo); var trusteeDataDoc = new HtmlDocument(); var trusteeRaw = _httpGet.Get(trusteeUri); trusteeRaw = trusteeRaw.Replace("class=\"ScrollingSelectionLeftColumn\"", "id=\"trusteeDataDoc\" class=\"ScrollingSelectionLeftColumn\""); trusteeDataDoc.LoadHtml(trusteeRaw); var incomeTable = GetById(generalDataDoc, "TablesIncome"); var spendingTable = GetById(generalDataDoc, "TablesSpending"); var assetsLiabilitiesAndPeople = GetById(generalDataDoc, "TablesAssetsLiabilitiesAndPeople"); var charitableSpending = GetById(generalDataDoc, "TablesCharitableSpending"); var trusteeNodes = trusteeDataDoc.DocumentNode.Descendants().Where( x => x.Name == "a" && x.Id.Contains("ctl00_MainContent_") && !x.InnerText.Contains("#") && !x.InnerText.Contains("www.")) .ToList(); var trusteeNames = trusteeNodes.Select(trustee => GetAndProcessString(()=>trustee.InnerText)).Where(x=>!string.IsNullOrWhiteSpace(x)).ToList(); var prof = new CharityProfile { CharityName = GetAndProcessString(() => generalDataDoc.GetElementbyId("ctl00_charityStatus_spnCharityName").InnerText), CharityRegistrationNumber = GetAndProcessString(() => generalDataDoc.GetElementbyId("ctl00_charityStatus_spnCharityNo").InnerText).FixRegistrationNumber(), MissionStatement = GetAndProcessString(() => generalDataDoc.GetElementbyId("ctl00_MainContent_ucDisplay_ucActivities_ucTextAreaInput_txtTextEntry").InnerText), TrusteeNames = trusteeNames, Income = new Income { Total = GetAndProcessDecimal(() => incomeTable.TableValue("Total")), Voluntary = GetAndProcessDecimal(() => incomeTable.TableValue("Voluntary")), TradingToRaiseFunds = GetAndProcessDecimal(() => incomeTable.TableValue("Trading to raise funds")), Investment = GetAndProcessDecimal(() => incomeTable.TableValue("Investment")), CharitableActivities = GetAndProcessDecimal(() => incomeTable.TableValue("Charitable activities")), Other = GetAndProcessDecimal(() => incomeTable.TableValue("Other")), InvestmentGains = GetAndProcessDecimal(() => incomeTable.TableValue("Investment gains")), }, Expenditure = new Expenditure { GeneratingVoluntaryIncome = GetAndProcessDecimal(() => spendingTable.TableValue("Generating voluntary income")), Governance = GetAndProcessDecimal(() => spendingTable.TableValue("Governance")), TradingToRaiseFunds = GetAndProcessDecimal(() => spendingTable.TableValue("Trading to raise funds")), InvestmentManagement = GetAndProcessDecimal(() => spendingTable.TableValue("Investment management")), CharitableActivities = GetAndProcessDecimal(() => spendingTable.TableValue("Charitable activities")), Other = GetAndProcessDecimal(() => spendingTable.TableValue("Other")), Total = GetAndProcessDecimal(() => spendingTable.TableValue("Total")), }, AssetsLiabilitiesAndPeople = new AssetsLiabilitiesAndPeople { OwnUseAssets = GetAndProcessDecimal(() => assetsLiabilitiesAndPeople.TableValue("Own use assets")), LongTermInvestments = GetAndProcessDecimal(() => assetsLiabilitiesAndPeople.TableValue("Long term investments")), OtherAssets = GetAndProcessDecimal(() => assetsLiabilitiesAndPeople.TableValue("Other assets")), TotalLiabilities = GetAndProcessDecimal(() => assetsLiabilitiesAndPeople.TableValue("Total liabilities")), Employees = GetAndProcessDecimal(() => assetsLiabilitiesAndPeople.TableValue("Employees")), Volunteers = GetAndProcessDecimal(() => assetsLiabilitiesAndPeople.TableValue("Volunteers")), }, CharitableSpending = new CharitableSpending { IncomeGenerationAndGovernance = GetAndProcessDecimal(() => charitableSpending.TableValue("Income generation and governance")), CharitableSpendingTotal = GetAndProcessDecimal(() => charitableSpending.TableValue("Charitable spending")), } }; return prof; }
private void SetupDefaultDataForCharity(CharityProfile charityProfile) { charityProfile.JgCharityData = new CharityEntity {Description = charityProfile.CharityName}; var charityNewsOnGuardian = _guardianApiAdapter.SearchContentByCharityName(charityProfile.CharityName); charityProfile.NewsItems = charityNewsOnGuardian.Response.Results ?? new List<Item>(); }