This commit is contained in:
2017-06-12 12:16:58 +03:00
parent 75f29241c0
commit 897e456e42
13 changed files with 268 additions and 17 deletions

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>

62
DAL/DAL.csproj Normal file
View File

@@ -0,0 +1,62 @@
<?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>{B783887A-E5BB-4066-9B9B-ABD7B4C1E269}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DAL</RootNamespace>
<AssemblyName>DAL</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="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
</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>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<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="FoorumDbContext.cs" />
<Compile Include="Interfaces\IFoorumDbContext.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Repositories\" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

22
DAL/Domain/Foorum.cs Normal file
View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace DAL.Domain
{
public class Foorum
{
[Key]
public int FoorumId { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Body { get; set; }
public DateTime CreationTime { get; set; }
public string Author { get; set; }
public bool Visible { get; set; } = true;
public virtual List<Post> Posts {get; set;} = new List<Post>();
}
}

16
DAL/Domain/Post.cs Normal file
View File

@@ -0,0 +1,16 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace DAL.Domain
{
public class Post
{
[Key]
public int PostId { get; set; }
public string Title { get; set; }
public string Body { get; set; }
public DateTime CreationTime { get; set; }
public string Author { get; set; }
}
}

21
DAL/FoorumDbContext.cs Normal file
View File

@@ -0,0 +1,21 @@
using System.Data.Entity;
using DAL.Domain;
namespace DAL
{
public class FoorumDbContext : DbContext, Interfaces.IFoorumDbContext
{
public DbSet<Foorum> Foorums { get; set; }
public DbSet<Post> Posts { get; set; }
public FoorumDbContext() : base("name=FoorumDb")
{
Database.SetInitializer(
new Helpers.DbInitializer()
);
}
}
}

View File

@@ -0,0 +1,43 @@
using System;
using System.Data.Entity;
using DAL.Domain;
namespace DAL.Helpers
{
public class DbInitializer : DropCreateDatabaseAlways<FoorumDbContext>
{
protected override void Seed(FoorumDbContext ctx)
{
var foorum = new Foorum()
{
Title = "Test Foorum",
Author = "Kala",
Description = "Lühi kirjeldus",
Body = "Siia kirjutame pika teksti",
CreationTime = DateTime.Now,
Visible = true
};
ctx.Foorums.Add(foorum);
for (int i = 0; i < 3; i++)
{
var post = new Post()
{
Title = $"Post {i}",
Author = "Karu",
Body = $"Pikk sisu {i}",
CreationTime = DateTime.Now
};
ctx.Posts.Add(post);
foorum.Posts.Add(post);
}
ctx.SaveChanges();
}
}
}

View File

@@ -0,0 +1,7 @@
namespace DAL.Interfaces
{
interface IFoorumDbContext
{
}
}

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("DAL")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DAL")]
[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("b783887a-e5bb-4066-9b9b-abd7b4c1e269")]
// 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")]

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>