Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tech Test Submission #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C7E15594-7D8F-4C18-9DD7-14F3FBB1572D}</ProjectGuid>
<ProjectGuid>{ACF38111-C769-4BEA-B9B8-AB3B71A14731}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AnyCompany</RootNamespace>
<AssemblyName>AnyCompany</AssemblyName>
<RootNamespace>AnyCompany.Models</RootNamespace>
<AssemblyName>AnyCompany.Models</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -41,10 +42,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Customer.cs" />
<Compile Include="CustomerRepository.cs" />
<Compile Include="Order.cs" />
<Compile Include="OrderRepository.cs" />
<Compile Include="OrderService.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
using System;
using System.Collections.Generic;

namespace AnyCompany
namespace AnyCompany.Models
{
public class Customer
{
public string Country { get; set; }
public int CustomerId { get; set; }

public string Name { get; set; }

public DateTime DateOfBirth { get; set; }

public string Name { get; set; }
public string Country { get; set; }

public List<Order> Orders { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
namespace AnyCompany
namespace AnyCompany.Models
{
public class Order
{
public int OrderId { get; set; }
public int CustomerId { get; set; }
public double Amount { get; set; }
public double VAT { get; set; }
}
Expand Down
36 changes: 36 additions & 0 deletions TechTest/AnyCompany.Models/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("AnyCompany.Models")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AnyCompany.Models")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("acf38111-c769-4bea-b9b8-ab3b71a14731")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
60 changes: 60 additions & 0 deletions TechTest/AnyCompany.Repository/AnyCompany.Repository.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{4C883089-3973-43FD-B6B0-337968CBD1EE}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AnyCompany.Repository</RootNamespace>
<AssemblyName>AnyCompany.Repository</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CustomerRepository.cs" />
<Compile Include="OrderRepository.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AnyCompany.Models\AnyCompany.Models.csproj">
<Project>{acf38111-c769-4bea-b9b8-ab3b71a14731}</Project>
<Name>AnyCompany.Models</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
6 changes: 6 additions & 0 deletions TechTest/AnyCompany.Repository/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="AnyCompany" connectionString="Data Source=(local);Database=Orders;User Id=admin;Password=password" />
</connectionStrings>
</configuration>
92 changes: 92 additions & 0 deletions TechTest/AnyCompany.Repository/CustomerRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using AnyCompany.Models;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

namespace AnyCompany.Repository
{
public static class CustomerRepository
{
private static string _connectionString = ConfigurationManager.ConnectionStrings["AnyCompany"].ConnectionString;

public static Customer Save(Customer customer)
{
using (SqlConnection connection = new SqlConnection(_connectionString))
{

SqlCommand command = new SqlCommand("INSERT INTO Customer (Name, DateOfBirth, Country) OUTPUT INSERTED.CustomerId VALUES (@Name, @DateOfBirth, @Country) ", connection);

command.Parameters.AddWithValue("@Name", customer.Name);
command.Parameters.AddWithValue("@DateOfBirth", customer.DateOfBirth);
command.Parameters.AddWithValue("@Country", customer.Country);

connection.Open();

customer.CustomerId = (int)command.ExecuteScalar();

}

return customer;
}

public static Customer Load(int customerId)
{
Customer customer = new Customer();

using (SqlConnection connection = new SqlConnection(_connectionString))
{
SqlCommand command = new SqlCommand("SELECT * FROM Customer WHERE CustomerId = " + customerId, connection);

connection.Open();

var reader = command.ExecuteReader();

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

reader.Close();

}

return customer;
}

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

using (SqlConnection connection = new SqlConnection(_connectionString))
{
SqlCommand command = new SqlCommand("SELECT * FROM Customer", connection);

connection.Open();

var reader = command.ExecuteReader();

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

customers.Add(customer);
}

reader.Close();
}

return customers;
}
}
}
58 changes: 58 additions & 0 deletions TechTest/AnyCompany.Repository/OrderRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using AnyCompany.Models;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;

namespace AnyCompany.Repository
{
public static class OrderRepository
{
private static string _connectionString = ConfigurationManager.ConnectionStrings["AnyCompany"].ConnectionString;

public static Order Save(Order order)
{
using (SqlConnection connection = new SqlConnection(_connectionString))
{
SqlCommand command = new SqlCommand("INSERT INTO Orders (CustomerId, Amount, VAT) OUTPUT INSERTED.OrderId VALUES (@CustomerId, @Amount, @VAT)", connection);

command.Parameters.AddWithValue("@CustomerId", order.CustomerId);
command.Parameters.AddWithValue("@Amount", order.Amount);
command.Parameters.AddWithValue("@VAT", order.VAT);

connection.Open();

order.OrderId = (int)command.ExecuteScalar();
}

return order;
}

public static List<Order> LoadCollection(int customerId)
{
List<Order> orders = new List<Order>();

using (SqlConnection connection = new SqlConnection(_connectionString))
{
SqlCommand command = new SqlCommand("SELECT * FROM Orders WHERE CustomerId = " + customerId, connection);

connection.Open();

var reader = command.ExecuteReader();

while (reader.Read())
{
Order order = new Order()
{
CustomerId = Int32.Parse(reader["CustomerId"].ToString()),
Amount = double.Parse(reader["Amount"].ToString()),
VAT = double.Parse(reader["VAT"].ToString())
};

orders.Add(order);
}
}
return orders;
}
}
}
36 changes: 36 additions & 0 deletions TechTest/AnyCompany.Repository/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("AnyCompany.Repository")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AnyCompany.Repository")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("4c883089-3973-43fd-b6b0-337968cbd1ee")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading