public ElectoralDistrict(string name, ElectoralDistrict higherDistrict) { Name = name; HigherDistrict = higherDistrict; HierarchyPath = higherDistrict == null ? null : higherDistrict.HierarchyPath == null ? higherDistrict.Id.ToString() : higherDistrict.HierarchyPath + "\\" + higherDistrict.Id; }
public static IQueryable <ElectionResult> ByHigherDistrict( this IQueryable <ElectionResult> items, ElectoralDistrict district) { if (items == null) { throw new ArgumentNullException("items"); } var hierarchyPath = district.HierarchyPath + "\\" + district.Id; return(items .Where(electionResult => electionResult.ElectoralDistrict.HierarchyPath.StartsWith(hierarchyPath))); }
public Election GetOrAdd(string name, ElectoralDistrict district, DateTime date, string dataSourceUrl) { var election = Cache.SingleOrDefault(e => e.Name == name && e.Date == date) ?? this.SingleOrDefault(e => e.Name == name && e.Date == date); if (election == null) { election = new Election { Name = name, ElectoralDistrict = district, Date = date, DataSourceUrl = dataSourceUrl }; Context.Elections.Add(election); } return(election); }
public ElectoralDistrictElection GetOrAdd(Election election, ElectoralDistrict district, string dataSourceUrl) { var districtElection = this.SingleOrDefault( subRegionElection => subRegionElection.ElectionId == election.Id && subRegionElection.ElectoralDistrictId == district.Id); if (districtElection == null) { districtElection = new ElectoralDistrictElection { Election = election, ElectoralDistrict = district, DataSourceUrl = dataSourceUrl }; Context.ElectoralDistrictElection.Add(districtElection); } return(districtElection); }