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
114 changes: 114 additions & 0 deletions AgeRanger.Service/AgeRanger.Service.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" 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>{CF336E17-7415-4E1E-A73E-6CFF5C8DA23C}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AgeRanger.Service</RootNamespace>
<AssemblyName>AgeRanger.Service</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</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="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Practices.EnterpriseLibrary.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\EnterpriseLibrary.Common.6.0.1304.0\lib\NET45\Microsoft.Practices.EnterpriseLibrary.Common.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\EnterpriseLibrary.Logging.6.0.1304.0\lib\NET45\Microsoft.Practices.EnterpriseLibrary.Logging.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Data.SQLite, Version=1.0.102.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.Core.1.0.102.0\lib\net451\System.Data.SQLite.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Data.SQLite.EF6, Version=1.0.102.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.EF6.1.0.102.0\lib\net451\System.Data.SQLite.EF6.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Data.SQLite.Linq, Version=1.0.102.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.Linq.1.0.102.0\lib\net451\System.Data.SQLite.Linq.dll</HintPath>
<Private>True</Private>
</Reference>
<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="DataBaseCreationFactory.cs" />
<Compile Include="PersonRepository.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SqlightRepository.cs" />
<Compile Include="SqlServerRepository.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AgeRanger.logic\AgeRanger.Logic.csproj">
<Project>{6b0a8884-a7e5-43db-bcb7-4765b9736da7}</Project>
<Name>AgeRanger.Logic</Name>
</ProjectReference>
<ProjectReference Include="..\Common.IoC\Common.IoC.csproj">
<Project>{9D7F2153-E2E8-4FB0-89F6-161F25243E6B}</Project>
<Name>Common.IoC</Name>
</ProjectReference>
<ProjectReference Include="..\Entities\Entities.csproj">
<Project>{ec955f04-8663-4759-abc8-432c1dc2e892}</Project>
<Name>Entities</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\System.Data.SQLite.Core.1.0.102.0\build\net451\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.102.0\build\net451\System.Data.SQLite.Core.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\System.Data.SQLite.Core.1.0.102.0\build\net451\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.102.0\build\net451\System.Data.SQLite.Core.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
27 changes: 27 additions & 0 deletions AgeRanger.Service/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="DataBaseType" value="Sqllite"/>
</appSettings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite.EF6" />
<add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
<remove invariant="System.Data.SQLite" /><add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" /></DbProviderFactories>
</system.data>
</configuration>
26 changes: 26 additions & 0 deletions AgeRanger.Service/DataBaseCreationFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using AgeRanger.Logic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AgeRanger.Service
{
public class DataBaseCreationFactory
{
public IDataBaseCommonFactory GetInstance(string DatabaseType)
{
switch (DatabaseType)
{
case "SQL":
return new SqlServerRepository();
case "SQLIGHT":
return new SqlightRepository();
default:
return new SqlightRepository();
}
}
}
}

38 changes: 38 additions & 0 deletions AgeRanger.Service/PersonRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using AgeRanger.Logic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Entities;
using System.Configuration;
using Common.IoC;

namespace AgeRanger.Service
{
public class PersonRepository : IPersonRepository
{
private IDataBaseCommonFactory _dbRepositoryInstance
= new DataBaseCreationFactory().GetInstance(ConfigurationManager.AppSettings["DataBaseType"]);

public List<AgeGroup> GetAllAgeGroups()
{
return _dbRepositoryInstance.GetAllAgeGroups();
}

public List<Person> GetAllPersons()
{
return _dbRepositoryInstance.GetAllPersons();
}

public Person GetPersonById(int id)
{
throw new NotImplementedException();
}

public void SavePerson(Person person)
{
_dbRepositoryInstance.SavePerson(person);
}
}
}
36 changes: 36 additions & 0 deletions AgeRanger.Service/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("AgeRanger.Service")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AgeRanger.Service")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[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("cf336e17-7415-4e1e-a73e-6cff5c8da23c")]

// 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")]
138 changes: 138 additions & 0 deletions AgeRanger.Service/SqlServerRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using AgeRanger.Logic;
using Entities;



namespace AgeRanger.Service
{
public class SqlServerRepository : IDataBaseCommonFactory
{
//TODO: This can be taken from the config
private string _conn = @"SQLCONN_String";

public List<AgeGroup> GetAllAgeGroups()
{
List<AgeGroup> ageGroupList = new List<AgeGroup>();
try
{
using (var conn = new SqlConnection(_conn))
using (var cmd = new SqlCommand("dbo.GetAllAgeGroups", conn))
{
conn.Open();
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
ageGroupList.Add(new AgeGroup()
{
MinAge = (int)reader["MinAge"],
MaxAge = (int)reader["MaxAge"],
AgeGroupDescription = (string)reader["Description"]
});
}
}
}
return ageGroupList;
}
catch (Exception ex)
{
//TODO: Can be logged
throw new Exception(ex.Message);
}
}

public List<Person> GetAllPersons()
{
List<Person> PersonList = new List<Person>();
try
{
using (var conn = new SqlConnection(_conn))
using (var cmd = new SqlCommand("dbo.GetAllPersons", conn))
{
conn.Open();
{
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
PersonList.Add(new Person()
{
Id = (int)reader["Id"],
FirstName = (string)reader["FirstName"],
LastName = (string)reader["LastName"],
Age = (int)reader["Age"]
});
}
}
}
}
return PersonList;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}

public Person GetPersonById(int id)
{
try
{
using (var conn = new SqlConnection(_conn))
using (var cmd = new SqlCommand("dbo.GetPersonById", conn))
{
conn.Open();

cmd.Parameters.AddWithValue("@Id", id);

using (var reader = cmd.ExecuteReader())
{
if (reader.HasRows)
{
return new Person()
{
Id = id,
FirstName = (string)reader["FirstName"],
LastName = (string)reader["LastName"],
Age = (int)reader["Age"]
};
}
}
}
return null;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}

public void SavePerson(Person person)
{
try
{
//This stored proc can be written to handle both insert and update with MERGE INTO...
using (var conn = new SqlConnection(_conn))
using (var cmd = new SqlCommand("dbo.InsertUpdatePerson", conn))
{
conn.Open();

cmd.Parameters.AddWithValue("@Id", person.Id);
cmd.Parameters.AddWithValue("@FirstName", person.FirstName);
cmd.Parameters.AddWithValue("@LastName", person.LastName);
cmd.Parameters.AddWithValue("@Age", person.Age);

cmd.ExecuteNonQuery();
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
}
Loading