Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions TechTest/AnyCompany/AnyCompany.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,25 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Customer.cs" />
<Compile Include="CustomerRepository.cs" />
<Compile Include="Order.cs" />
<Compile Include="OrderRepository.cs" />
<Compile Include="OrderService.cs" />
<Compile Include="Helpers\VatHelper.cs" />
<Compile Include="Models\Customer.cs" />
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
<Compile Include="Repositories\CustomerRepository.cs" />
<Compile Include="Models\Order.cs" />
<Compile Include="Repositories\OrderRepository.cs" />
<Compile Include="Services\OrderService.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
13 changes: 0 additions & 13 deletions TechTest/AnyCompany/Customer.cs

This file was deleted.

33 changes: 0 additions & 33 deletions TechTest/AnyCompany/CustomerRepository.cs

This file was deleted.

42 changes: 42 additions & 0 deletions TechTest/AnyCompany/Helpers/VatHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Specialized;

namespace AnyCompany.Helpers
{
/// <summary>
/// This class contains VAT helper functions.
/// </summary>
public static class VatHelper
{

/// <summary>
/// Finds the correct VAT rate in settings based on the given country.
/// </summary>
/// <param name="countryCode">The country code to use for the VAT lookup.</param>
public static double GetVatRateByCountry(string countryCode)
{
StringCollection vatSettings = Properties.Settings.Default.VatSettings;

foreach (string setting in vatSettings)
{
// Confirm that this settings matches the 'CountryCode:Rate' pattern, split into an array, and confirm the second array element is indeed double compatible.
if (setting.Contains(":"))
{
string[] settingsPart = setting.Split(':');

if (settingsPart.Length == 2 && settingsPart[0].Equals(countryCode, StringComparison.OrdinalIgnoreCase))
{
double testVal = 0;

if (double.TryParse(settingsPart[1], out testVal))
{
return testVal;
}
}
}
}

return 0;
}
}
}
26 changes: 26 additions & 0 deletions TechTest/AnyCompany/Models/Customer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;

namespace AnyCompany.Models
{
/// <summary>
/// This is the Customer Model
/// </summary>
public class Customer
{
public int CustomerId { get; set; }

public string Country { get; set; }

public DateTime DateOfBirth { get; set; }

public string Name { get; set; }

public List<Order> Orders { get; set; }

public Customer()
{
Orders = new List<Order>();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
namespace AnyCompany
namespace AnyCompany.Models
{
/// <summary>
/// This is the Order Model
/// </summary>
public class Order
{
public int OrderId { get; set; }
public double Amount { get; set; }
public double VAT { get; set; }

public int CustomerId { get; set; }
}
}
25 changes: 0 additions & 25 deletions TechTest/AnyCompany/OrderRepository.cs

This file was deleted.

24 changes: 0 additions & 24 deletions TechTest/AnyCompany/OrderService.cs

This file was deleted.

55 changes: 55 additions & 0 deletions TechTest/AnyCompany/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions TechTest/AnyCompany/Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="AnyCompany.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="OrderConnectionString" Type="System.String" Scope="Application">
<Value Profile="(Default)">Data Source=(local);Database=Orders;User Id=admin;Password=password;</Value>
</Setting>
<Setting Name="CustomerConnectionString" Type="System.String" Scope="Application">
<Value Profile="(Default)">Data Source=(local);Database=Customers;User Id=admin;Password=password;</Value>
</Setting>
<Setting Name="VatSettings" Type="System.Collections.Specialized.StringCollection" Scope="Application">
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;string&gt;UK:0.2&lt;/string&gt;
&lt;/ArrayOfString&gt;</Value>
</Setting>
</Settings>
</SettingsFile>
70 changes: 70 additions & 0 deletions TechTest/AnyCompany/Repositories/CustomerRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using AnyCompany.Models;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;

namespace AnyCompany.Repositories
{
/// <summary>
/// This is the Customer Repository, responsible for managing customer persistance and retrieval.
/// </summary>
public static class CustomerRepository
{
/// <summary>
/// This loads a Customer object.
/// </summary>
/// <param name="customerId">The Id of the customer this order is placed agains.</param>
public static Customer Load(int customerId)
{
Customer customer = new Customer();

SqlConnection connection = new SqlConnection(Properties.Settings.Default.CustomerConnectionString);
connection.Open();

SqlCommand command = new SqlCommand("SELECT * FROM Customer WHERE CustomerId = @CustomerId", connection);

command.Parameters.AddWithValue("@CustomerId", customerId);

var reader = command.ExecuteReader();

while (reader.Read())
{
customer.CustomerId = int.Parse(reader["CustomerId"].ToString());
customer.Name = reader["Name"].ToString();
customer.DateOfBirth = DateTime.Parse(reader["DateOfBirth"].ToString());
customer.Country = reader["Country"].ToString();
}

connection.Close();

return customer;
}

public static List<Customer> GetAll()
{
List<Customer> customers = new List<Customer>();

SqlConnection connection = new SqlConnection(Properties.Settings.Default.CustomerConnectionString);
connection.Open();

SqlCommand command = new SqlCommand("SELECT * FROM Customer", connection);

var reader = command.ExecuteReader();

while (reader.Read())
{
customers.Add(new Customer()
{
CustomerId = int.Parse(reader["CustomerId"].ToString()),
Name = reader["Name"].ToString(),
DateOfBirth = DateTime.Parse(reader["DateOfBirth"].ToString()),
Country = reader["Country"].ToString()
});
}

connection.Close();

return customers;
}
}
}
Loading