Skip to content

Commit 44e6565

Browse files
author
Frank Odoom
committed
initial commit
0 parents  commit 44e6565

29 files changed

Lines changed: 38361 additions & 0 deletions

Country.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using CountryData.Standard;
2+
using System;
3+
using System.Collections.Generic;
4+
5+
namespace CountryData.Standard
6+
{
7+
public class Country
8+
{
9+
public string CountryName { get; set; }
10+
public string CountryShortCode { get; set; }
11+
public List<Regions> Regions { get; set; }
12+
}
13+
}

CountryData.Standard.csproj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<None Remove="data.json" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<Content Include="data.json">
13+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
14+
</Content>
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
19+
</ItemGroup>
20+
21+
</Project>

CountryHelper.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Reflection;
7+
using System.Text;
8+
9+
namespace CountryData.Standard
10+
{
11+
public class CountryHelper
12+
{
13+
private readonly IEnumerable<Country> _Countries;
14+
public CountryHelper()
15+
{
16+
var path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"data.json");
17+
var json = File.ReadAllText(path);
18+
_Countries = JsonConvert.DeserializeObject<List<Country>>(json);
19+
}
20+
21+
22+
public IEnumerable<Country> GetCountryData()
23+
{
24+
return _Countries;
25+
}
26+
27+
28+
/// <summary>
29+
/// Returns A particular Country and its Regions by Its ShortCoded
30+
/// </summary>
31+
/// <param name="ShortCode"></param>
32+
/// <returns>IEnumerable<Country></returns>
33+
public IEnumerable<Country> GetCountry(string ShortCode)
34+
{
35+
return _Countries.Where(x => x.CountryShortCode == ShortCode);
36+
}
37+
38+
39+
/// <summary>
40+
/// Select Regions in a Particular Country
41+
/// </summary>
42+
/// <param name="ShortCode"></param>
43+
/// <returns>List<Regions> a list of regions</returns>
44+
public List<Regions> GetRegionByCountryCode(string ShortCode)
45+
{
46+
return _Countries.Where(x => x.CountryShortCode == ShortCode)
47+
.Select(r=>r.Regions).FirstOrDefault()
48+
.ToList();
49+
}
50+
51+
52+
}
53+
}

Regions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace CountryData.Standard
6+
{
7+
public class Regions
8+
{
9+
public String Name { get; set; }
10+
public String ShortCode { get; set; }
11+
}
12+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"runtimeTarget": {
3+
"name": ".NETStandard,Version=v2.0/",
4+
"signature": ""
5+
},
6+
"compilationOptions": {},
7+
"targets": {
8+
".NETStandard,Version=v2.0": {},
9+
".NETStandard,Version=v2.0/": {
10+
"CountryData.Standard/1.0.0": {
11+
"dependencies": {
12+
"NETStandard.Library": "2.0.3",
13+
"Newtonsoft.Json": "12.0.3"
14+
},
15+
"runtime": {
16+
"CountryData.Standard.dll": {}
17+
}
18+
},
19+
"Microsoft.NETCore.Platforms/1.1.0": {},
20+
"NETStandard.Library/2.0.3": {
21+
"dependencies": {
22+
"Microsoft.NETCore.Platforms": "1.1.0"
23+
}
24+
},
25+
"Newtonsoft.Json/12.0.3": {
26+
"runtime": {
27+
"lib/netstandard2.0/Newtonsoft.Json.dll": {
28+
"assemblyVersion": "12.0.0.0",
29+
"fileVersion": "12.0.3.23909"
30+
}
31+
}
32+
}
33+
}
34+
},
35+
"libraries": {
36+
"CountryData.Standard/1.0.0": {
37+
"type": "project",
38+
"serviceable": false,
39+
"sha512": ""
40+
},
41+
"Microsoft.NETCore.Platforms/1.1.0": {
42+
"type": "package",
43+
"serviceable": true,
44+
"sha512": "sha512-kz0PEW2lhqygehI/d6XsPCQzD7ff7gUJaVGPVETX611eadGsA3A877GdSlU0LRVMCTH/+P3o2iDTak+S08V2+A==",
45+
"path": "microsoft.netcore.platforms/1.1.0",
46+
"hashPath": "microsoft.netcore.platforms.1.1.0.nupkg.sha512"
47+
},
48+
"NETStandard.Library/2.0.3": {
49+
"type": "package",
50+
"serviceable": true,
51+
"sha512": "sha512-st47PosZSHrjECdjeIzZQbzivYBJFv6P2nv4cj2ypdI204DO+vZ7l5raGMiX4eXMJ53RfOIg+/s4DHVZ54Nu2A==",
52+
"path": "netstandard.library/2.0.3",
53+
"hashPath": "netstandard.library.2.0.3.nupkg.sha512"
54+
},
55+
"Newtonsoft.Json/12.0.3": {
56+
"type": "package",
57+
"serviceable": true,
58+
"sha512": "sha512-6mgjfnRB4jKMlzHSl+VD+oUc1IebOZabkbyWj2RiTgWwYPPuaK1H97G1sHqGwPlS5npiF5Q0OrxN1wni2n5QWg==",
59+
"path": "newtonsoft.json/12.0.3",
60+
"hashPath": "newtonsoft.json.12.0.3.nupkg.sha512"
61+
}
62+
}
63+
}
6.5 KB
Binary file not shown.
1.38 KB
Binary file not shown.

0 commit comments

Comments
 (0)