Interfaces

This commit is contained in:
Arti Zirk 2017-03-08 15:47:46 +02:00
parent 9ede003205
commit fc14b4d3a5
20 changed files with 339 additions and 22 deletions

View File

@ -1,11 +1,11 @@
<?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>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
<connectionStrings>
<add name="AppDbConnectionString" connectionString="Data Source=(localdb)\mssqllocaldb;Initial Catalog=EFDemo2017;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient"/>
<add name="AppDbConnectionString" connectionString="Data Source=(localdb)\mssqllocaldb;Initial Catalog=EFDemo2017;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />

17
DAL/App.config Normal file
View File

@ -0,0 +1,17 @@
<?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>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>

View File

@ -31,6 +31,9 @@ namespace DAL
}
public DbSet<Person> People { get; set; }
public DbSet<Cource> Cources { get; set; }
public DbSet<Person> Persons { get; set; }
public DbSet<PersonCources> PersonCources { get; set; }
}
}

View File

@ -30,10 +30,16 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="EntityFramework">
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.1.3\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.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
@ -45,13 +51,23 @@
<ItemGroup>
<Compile Include="AppDbContext.cs" />
<Compile Include="Helpers\DbInit.cs" />
<Compile Include="Repositories\PersonRepository.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Repositories\EFRepository.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Domain\Domain.csproj">
<Project>{C3E21315-C897-46BE-B9F7-8B6A2201C6D5}</Project>
<Name>Domain</Name>
</ProjectReference>
<ProjectReference Include="..\Interfaces\Interfaces.csproj">
<Project>{88F63C3D-8C2B-4C31-A2C0-51DC04D1F18B}</Project>
<Name>Interfaces</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@ -1,5 +1,6 @@
using System.Data.Entity;
using Domain;
using Domain.Enums;
namespace DAL.Helpers
{
@ -9,16 +10,33 @@ namespace DAL.Helpers
{
// base.Seed doesn't really do anything
base.Seed(context);
//context.People.Add(new Person()
//{
// FirstName = "Arti",
// LastName = "Zirk"
//});
//context.People.Add(new Person()
//{
// FirstName = "Sala",
// LastName = "Kala"
//});
var p1 = new Person()
{
FirstName = "Arti",
LastName = "Zirk",
PersonType = PersonType.Student
};
var p2 = new Person()
{
FirstName = "Sala",
LastName = "Kala",
PersonType = PersonType.Teacher
};
var sub1 = new Subject()
{
SubjectName = "Best Cource"
};
var sub2 = new Subject()
{
SubjectName = "Worst Cource"
};
var cource = new Cource()
{
};
}
}
}

View File

@ -0,0 +1,74 @@
using Interfaces;
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DAL.Repositories
{
public class EFRepository<TEntity> : IRespository<TEntity>
where TEntity : class
{
protected DbContext RepositoryDbContext;
protected DbSet<TEntity> RepositoryDbSet;
public EFRepository(DbContext dbContext)
{
if (dbContext == null)
{
throw new ArgumentNullException(nameof(dbContext));
}
RepositoryDbContext = dbContext;
RepositoryDbSet = dbContext.Set<TEntity>();
if (RepositoryDbSet == null)
{
throw new NullReferenceException(nameof(RepositoryDbSet));
}
}
public List<TEntity> All
{
get
{
var resCount = RepositoryDbSet.Count();
if (resCount < 10)
{
return RepositoryDbSet.ToList();
}
throw new Exception("To many records in result set. Custom data access method needed");
}
}
public TEntity Find(int id)
{
RepositoryDbSet.Find(id);
}
public void Remove(int id)
{
Remove(Find(id));
}
public void Remove(TEntity entity)
{
RepositoryDbSet.Remove(entity);
}
public TEntity Add(TEntity entity)
{
return RepositoryDbSet.Add(entity);
}
public void Update(TEntity entity)
{
RepositoryDbSet.Attach(entity);
}
public int SaveChanges()
{
return RepositoryDbContext.SaveChanges();
}
}
}

View File

@ -0,0 +1,14 @@
using System.Data.Entity;
using Domain;
using Interfaces;
namespace DAL.Repositories
{
public class PersonRepository : EFRepository<Person>, IPersonRepository
{
public PersonRepository(DbContext dbContext) : base(dbContext)
{
}
}
}

4
DAL/packages.config Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.1.3" targetFramework="net452" />
</packages>

17
Domain/App.config Normal file
View File

@ -0,0 +1,17 @@
<?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>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>

View File

@ -17,6 +17,6 @@ namespace Domain
public int SubjectId { get; set; }
public Subject Subject { get; set; }
public virtual List<Person> Persons { get; set; } = new List<Person>();
public virtual List<PersonCources> Persons { get; set; } = new List<PersonCources>();
}
}

View File

@ -30,6 +30,14 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.1.3\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.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
@ -48,6 +56,10 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Subject.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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.

View File

@ -6,11 +6,9 @@ using System.Threading.Tasks;
namespace Domain.Enums
{
class PersonType
public enum PersonType
{
public enum PersonTypeEnum {
Student,
Teacher
}
Student,
Teacher
}
}

View File

@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Domain.Enums;
namespace Domain
{
@ -20,7 +21,9 @@ namespace Domain
[Required]
public string LastName { get; set; }
public virtual List<Cource> Courses { get; set; }
public PersonType PersonType { get; set; }
public virtual List<PersonCources> Courses { get; set; } = new List<PersonCources>();
#region NotMaped
public string FirstLastName => $"{FirstName} {LastName}";

View File

@ -8,7 +8,7 @@ using System.ComponentModel.DataAnnotations;
namespace Domain
{
class Subject
public class Subject
{
public int SubjectId { get; set; }

4
Domain/packages.config Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.1.3" targetFramework="net452" />
</packages>

View File

@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain", "Domain\Domain.csp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DAL", "DAL\DAL.csproj", "{FE4F718E-854F-4899-9F4C-C385AC704477}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Interfaces", "Interfaces\Interfaces.csproj", "{88F63C3D-8C2B-4C31-A2C0-51DC04D1F18B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -27,6 +29,10 @@ Global
{FE4F718E-854F-4899-9F4C-C385AC704477}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FE4F718E-854F-4899-9F4C-C385AC704477}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FE4F718E-854F-4899-9F4C-C385AC704477}.Release|Any CPU.Build.0 = Release|Any CPU
{88F63C3D-8C2B-4C31-A2C0-51DC04D1F18B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88F63C3D-8C2B-4C31-A2C0-51DC04D1F18B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88F63C3D-8C2B-4C31-A2C0-51DC04D1F18B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{88F63C3D-8C2B-4C31-A2C0-51DC04D1F18B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,13 @@
using Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Interfaces
{
public interface IPersonRepository : IRespository<Person>
{
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Interfaces
{
public interface IRespository<TEntry>
{
// suht halb, väljastab poolikuid sql päringuid
// IQueryable<TEntry> All { get; }
List<TEntry> All { get; }
TEntry Find(int id);
void Remove(int id);
void Remove(TEntry entity);
TEntry Add(TEntry entity);
void Update(TEntry entity);
int SaveChanges();
}
}

View File

@ -0,0 +1,61 @@
<?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>{88F63C3D-8C2B-4C31-A2C0-51DC04D1F18B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Interfaces</RootNamespace>
<AssemblyName>Interfaces</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</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.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="IPersonRepository.cs" />
<Compile Include="IRespository.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Domain\Domain.csproj">
<Project>{C3E21315-C897-46BE-B9F7-8B6A2201C6D5}</Project>
<Name>Domain</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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>

View File

@ -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("Interfaces")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Interfaces")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[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("88f63c3d-8c2b-4c31-a2c0-51dc04d1f18b")]
// 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")]