Przygotowanie kontekstu bazy

This commit is contained in:
Bartosz Chyzy 2018-12-01 22:41:14 +01:00
parent aabfa3b501
commit 46cf963c4a
9 changed files with 284 additions and 3 deletions

View File

@ -6,7 +6,16 @@ using System.Threading.Tasks;
namespace Forum.DataAccessLayer.Models
{
class Answer
public class Answer
{
public int Id { get; set; }
public DateTime Date { get; set; }
public string Content { get; set; }
public string Nick { get; set; }
public ProfessionalUser Professional { get; set; }
public Question Question { get; set; }
}
}

View File

@ -6,7 +6,12 @@ using System.Threading.Tasks;
namespace Forum.DataAccessLayer.Models
{
class Category
public class Category
{
public int Id { get; set; }
public string CategoryName { get; set; }
public virtual ICollection<Question> Questions { get; set; }
}
}

View File

@ -11,6 +11,8 @@ namespace Forum.DataAccessLayer.Models
{
public class ProfessionalUser : IdentityUser
{
public string FullName { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ProfessionalUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType

View File

@ -6,7 +6,22 @@ using System.Threading.Tasks;
namespace Forum.DataAccessLayer.Models
{
class Question
public class Question
{
public int Id { get; set; }
public string Nick { get; set; }
public DateTime PostDate { get; set; }
public string Content { get; set; }
public bool IsClosed { get; set; }
public string ReportersEmail { get; set; }
public Category Category { get; set; }
public virtual ICollection<Answer> Answers { get; set; }
}
}

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -19,5 +20,23 @@ namespace Forum.DataAccessLayer
{
return new ApplicationDbContext();
}
public DbSet<Answer> Answers { get; set; }
public DbSet<Question> Questions { get; set; }
public DbSet<Category> Categories { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Question>().HasMany(a => a.Answers).WithOptional(q => q.Question);
modelBuilder.Entity<Answer>().HasOptional(p => p.Professional);
modelBuilder.Entity<Category>().HasMany(q => q.Questions).WithRequired(c => c.Category);
}
}
}

View File

@ -82,6 +82,10 @@
<Compile Include="Migrations\201812012107132_Db init.Designer.cs">
<DependentUpon>201812012107132_Db init.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\201812012140435_Configure Db Tables.cs" />
<Compile Include="Migrations\201812012140435_Configure Db Tables.Designer.cs">
<DependentUpon>201812012140435_Configure Db Tables.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\Configuration.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\MailService.cs" />
@ -104,6 +108,9 @@
<EmbeddedResource Include="Migrations\201812012107132_Db init.resx">
<DependentUpon>201812012107132_Db init.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Migrations\201812012140435_Configure Db Tables.resx">
<DependentUpon>201812012140435_Configure Db Tables.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,29 @@
// <auto-generated />
namespace Forum.DataAccessLayer.Migrations
{
using System.CodeDom.Compiler;
using System.Data.Entity.Migrations;
using System.Data.Entity.Migrations.Infrastructure;
using System.Resources;
[GeneratedCode("EntityFramework.Migrations", "6.2.0-61023")]
public sealed partial class ConfigureDbTables : IMigrationMetadata
{
private readonly ResourceManager Resources = new ResourceManager(typeof(ConfigureDbTables));
string IMigrationMetadata.Id
{
get { return "201812012140435_Configure Db Tables"; }
}
string IMigrationMetadata.Source
{
get { return null; }
}
string IMigrationMetadata.Target
{
get { return Resources.GetString("Target"); }
}
}
}

View File

@ -0,0 +1,69 @@
namespace Forum.DataAccessLayer.Migrations
{
using System;
using System.Data.Entity.Migrations;
public partial class ConfigureDbTables : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.Answers",
c => new
{
Id = c.Int(nullable: false, identity: true),
Date = c.DateTime(nullable: false),
Content = c.String(),
Nick = c.String(),
Professional_Id = c.String(maxLength: 128),
Question_Id = c.Int(),
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.AspNetUsers", t => t.Professional_Id)
.ForeignKey("dbo.Questions", t => t.Question_Id)
.Index(t => t.Professional_Id)
.Index(t => t.Question_Id);
CreateTable(
"dbo.Questions",
c => new
{
Id = c.Int(nullable: false, identity: true),
Nick = c.String(),
PostDate = c.DateTime(nullable: false),
Content = c.String(),
IsClosed = c.Boolean(nullable: false),
ReportersEmail = c.String(),
Category_Id = c.Int(nullable: false),
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.Categories", t => t.Category_Id, cascadeDelete: true)
.Index(t => t.Category_Id);
CreateTable(
"dbo.Categories",
c => new
{
Id = c.Int(nullable: false, identity: true),
CategoryName = c.String(),
})
.PrimaryKey(t => t.Id);
AddColumn("dbo.AspNetUsers", "FullName", c => c.String());
}
public override void Down()
{
DropForeignKey("dbo.Questions", "Category_Id", "dbo.Categories");
DropForeignKey("dbo.Answers", "Question_Id", "dbo.Questions");
DropForeignKey("dbo.Answers", "Professional_Id", "dbo.AspNetUsers");
DropIndex("dbo.Questions", new[] { "Category_Id" });
DropIndex("dbo.Answers", new[] { "Question_Id" });
DropIndex("dbo.Answers", new[] { "Professional_Id" });
DropColumn("dbo.AspNetUsers", "FullName");
DropTable("dbo.Categories");
DropTable("dbo.Questions");
DropTable("dbo.Answers");
}
}
}

View File

@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Target" xml:space="preserve">
<value>H4sIAAAAAAAEAO1d227kuBF9D5B/EPSUBN5uXzKDidG9C2/b3hgZXzLtWeTNoCW6LYwuvRI1YyPYL8tDPim/EFJXXiVSUqvlTTAvbZGsKhYPi6wiWfOff/178cNL4FtfYZx4Ubi0j2aHtgVDJ3K9cLO0U/T03Qf7h+9//7vFhRu8WD+X9U5IPdwyTJb2M0Lb0/k8cZ5hAJJZ4DlxlERPaOZEwRy40fz48PAv86OjOcQkbEzLshaf0hB5Acz+wH+uotCBW5QC/zpyoZ8U33HJOqNq3YAAJlvgwKV9GcVpMDsHCJw5DkyS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