diff --git a/SessionCompanion/SessionCompanion.Database/ApplicationDbContext.cs b/SessionCompanion/SessionCompanion.Database/ApplicationDbContext.cs new file mode 100644 index 0000000..a081725 --- /dev/null +++ b/SessionCompanion/SessionCompanion.Database/ApplicationDbContext.cs @@ -0,0 +1,30 @@ +using Microsoft.EntityFrameworkCore; +using SessionCompanion.Database.Tables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SessionCompanion.Database +{ + public class ApplicationDbContext : DbContext + { + public virtual DbSet Alignments { get; set; } + public virtual DbSet Backgrounds { get; set; } + public virtual DbSet Biographies { get; set; } + public virtual DbSet Characters { get; set; } + public virtual DbSet Classes { get; set; } + public virtual DbSet Races { get; set; } + public virtual DbSet Statistics { get; set; } + public virtual DbSet Users { get; set; } + + public ApplicationDbContext(DbContextOptions options) : base(options) { } + + protected override void OnModelCreating(ModelBuilder builder) + { + base.OnModelCreating(builder); + builder.Entity().HasData(SeedData.SeedUsers()); + } + } +} diff --git a/SessionCompanion/SessionCompanion.Database/Migrations/20201203161115_Base-Tables.Designer.cs b/SessionCompanion/SessionCompanion.Database/Migrations/20201203161115_Base-Tables.Designer.cs new file mode 100644 index 0000000..8f35a07 --- /dev/null +++ b/SessionCompanion/SessionCompanion.Database/Migrations/20201203161115_Base-Tables.Designer.cs @@ -0,0 +1,317 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using SessionCompanion.Database; + +namespace SessionCompanion.Database.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20201203161115_Base-Tables")] + partial class BaseTables + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .UseIdentityColumns() + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("ProductVersion", "5.0.0"); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Alignment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .UseIdentityColumn(); + + b.HasKey("Id"); + + b.ToTable("Alignments"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Background", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .UseIdentityColumn(); + + b.HasKey("Id"); + + b.ToTable("Backgrounds"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Biography", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .UseIdentityColumn(); + + b.Property("AlignmentId") + .HasColumnType("int"); + + b.Property("BackgroundId") + .HasColumnType("int"); + + b.Property("CharacterId") + .HasColumnType("int"); + + b.Property("ClassId") + .HasColumnType("int"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("RaceId") + .HasColumnType("int"); + + b.Property("Sex") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("AlignmentId"); + + b.HasIndex("BackgroundId"); + + b.HasIndex("CharacterId") + .IsUnique(); + + b.HasIndex("ClassId"); + + b.HasIndex("RaceId"); + + b.ToTable("Biographies"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Character", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .UseIdentityColumn(); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Characters"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Class", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .UseIdentityColumn(); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Classes"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Race", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .UseIdentityColumn(); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Races"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Statistics", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .UseIdentityColumn(); + + b.Property("ArmorClass") + .HasColumnType("int"); + + b.Property("CharacterId") + .HasColumnType("int"); + + b.Property("CurrentHealthPoints") + .HasColumnType("int"); + + b.Property("ExperiencePoints") + .HasColumnType("int"); + + b.Property("HealthPoints") + .HasColumnType("int"); + + b.Property("Initiative") + .HasColumnType("int"); + + b.Property("Level") + .HasColumnType("int"); + + b.Property("Proficiency") + .HasColumnType("int"); + + b.Property("Speed") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CharacterId") + .IsUnique(); + + b.ToTable("Statistics"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .UseIdentityColumn(); + + b.Property("Nickname") + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Users"); + + b.HasData( + new + { + Id = 1, + Nickname = "Morwiec", + Password = "123" + }, + new + { + Id = 2, + Nickname = "Cichoklepiec", + Password = "123" + }, + new + { + Id = 3, + Nickname = "Ruletka", + Password = "123" + }); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Biography", b => + { + b.HasOne("SessionCompanion.Database.Tables.Alignment", "Alignment") + .WithMany("Biography") + .HasForeignKey("AlignmentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SessionCompanion.Database.Tables.Background", "Background") + .WithMany("Biography") + .HasForeignKey("BackgroundId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SessionCompanion.Database.Tables.Character", "Character") + .WithOne("Biography") + .HasForeignKey("SessionCompanion.Database.Tables.Biography", "CharacterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SessionCompanion.Database.Tables.Class", "Class") + .WithMany("Biography") + .HasForeignKey("ClassId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SessionCompanion.Database.Tables.Race", "Race") + .WithMany("Biography") + .HasForeignKey("RaceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Alignment"); + + b.Navigation("Background"); + + b.Navigation("Character"); + + b.Navigation("Class"); + + b.Navigation("Race"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Character", b => + { + b.HasOne("SessionCompanion.Database.Tables.User", "User") + .WithMany("Character") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Statistics", b => + { + b.HasOne("SessionCompanion.Database.Tables.Character", "Character") + .WithOne("Statistics") + .HasForeignKey("SessionCompanion.Database.Tables.Statistics", "CharacterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Character"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Alignment", b => + { + b.Navigation("Biography"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Background", b => + { + b.Navigation("Biography"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Character", b => + { + b.Navigation("Biography"); + + b.Navigation("Statistics"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Class", b => + { + b.Navigation("Biography"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Race", b => + { + b.Navigation("Biography"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.User", b => + { + b.Navigation("Character"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SessionCompanion/SessionCompanion.Database/Migrations/20201203161115_Base-Tables.cs b/SessionCompanion/SessionCompanion.Database/Migrations/20201203161115_Base-Tables.cs new file mode 100644 index 0000000..966a889 --- /dev/null +++ b/SessionCompanion/SessionCompanion.Database/Migrations/20201203161115_Base-Tables.cs @@ -0,0 +1,248 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace SessionCompanion.Database.Migrations +{ + public partial class BaseTables : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Alignments", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1") + }, + constraints: table => + { + table.PrimaryKey("PK_Alignments", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Backgrounds", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1") + }, + constraints: table => + { + table.PrimaryKey("PK_Backgrounds", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Classes", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Classes", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Races", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Races", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Nickname = table.Column(type: "nvarchar(max)", nullable: true), + Password = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Characters", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Characters", x => x.Id); + table.ForeignKey( + name: "FK_Characters_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Biographies", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + CharacterId = table.Column(type: "int", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: true), + ClassId = table.Column(type: "int", nullable: false), + RaceId = table.Column(type: "int", nullable: false), + AlignmentId = table.Column(type: "int", nullable: false), + BackgroundId = table.Column(type: "int", nullable: false), + Sex = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Biographies", x => x.Id); + table.ForeignKey( + name: "FK_Biographies_Alignments_AlignmentId", + column: x => x.AlignmentId, + principalTable: "Alignments", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Biographies_Backgrounds_BackgroundId", + column: x => x.BackgroundId, + principalTable: "Backgrounds", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Biographies_Characters_CharacterId", + column: x => x.CharacterId, + principalTable: "Characters", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Biographies_Classes_ClassId", + column: x => x.ClassId, + principalTable: "Classes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Biographies_Races_RaceId", + column: x => x.RaceId, + principalTable: "Races", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Statistics", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + CharacterId = table.Column(type: "int", nullable: false), + ExperiencePoints = table.Column(type: "int", nullable: false), + Level = table.Column(type: "int", nullable: false), + Speed = table.Column(type: "int", nullable: false), + Initiative = table.Column(type: "int", nullable: false), + HealthPoints = table.Column(type: "int", nullable: false), + CurrentHealthPoints = table.Column(type: "int", nullable: false), + ArmorClass = table.Column(type: "int", nullable: false), + Proficiency = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Statistics", x => x.Id); + table.ForeignKey( + name: "FK_Statistics_Characters_CharacterId", + column: x => x.CharacterId, + principalTable: "Characters", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.InsertData( + table: "Users", + columns: new[] { "Id", "Nickname", "Password" }, + values: new object[] { 1, "Morwiec", "123" }); + + migrationBuilder.InsertData( + table: "Users", + columns: new[] { "Id", "Nickname", "Password" }, + values: new object[] { 2, "Cichoklepiec", "123" }); + + migrationBuilder.InsertData( + table: "Users", + columns: new[] { "Id", "Nickname", "Password" }, + values: new object[] { 3, "Ruletka", "123" }); + + migrationBuilder.CreateIndex( + name: "IX_Biographies_AlignmentId", + table: "Biographies", + column: "AlignmentId"); + + migrationBuilder.CreateIndex( + name: "IX_Biographies_BackgroundId", + table: "Biographies", + column: "BackgroundId"); + + migrationBuilder.CreateIndex( + name: "IX_Biographies_CharacterId", + table: "Biographies", + column: "CharacterId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Biographies_ClassId", + table: "Biographies", + column: "ClassId"); + + migrationBuilder.CreateIndex( + name: "IX_Biographies_RaceId", + table: "Biographies", + column: "RaceId"); + + migrationBuilder.CreateIndex( + name: "IX_Characters_UserId", + table: "Characters", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_Statistics_CharacterId", + table: "Statistics", + column: "CharacterId", + unique: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Biographies"); + + migrationBuilder.DropTable( + name: "Statistics"); + + migrationBuilder.DropTable( + name: "Alignments"); + + migrationBuilder.DropTable( + name: "Backgrounds"); + + migrationBuilder.DropTable( + name: "Classes"); + + migrationBuilder.DropTable( + name: "Races"); + + migrationBuilder.DropTable( + name: "Characters"); + + migrationBuilder.DropTable( + name: "Users"); + } + } +} diff --git a/SessionCompanion/SessionCompanion.Database/Migrations/ApplicationDbContextModelSnapshot.cs b/SessionCompanion/SessionCompanion.Database/Migrations/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 0000000..0b86cba --- /dev/null +++ b/SessionCompanion/SessionCompanion.Database/Migrations/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,315 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using SessionCompanion.Database; + +namespace SessionCompanion.Database.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .UseIdentityColumns() + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("ProductVersion", "5.0.0"); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Alignment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .UseIdentityColumn(); + + b.HasKey("Id"); + + b.ToTable("Alignments"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Background", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .UseIdentityColumn(); + + b.HasKey("Id"); + + b.ToTable("Backgrounds"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Biography", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .UseIdentityColumn(); + + b.Property("AlignmentId") + .HasColumnType("int"); + + b.Property("BackgroundId") + .HasColumnType("int"); + + b.Property("CharacterId") + .HasColumnType("int"); + + b.Property("ClassId") + .HasColumnType("int"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("RaceId") + .HasColumnType("int"); + + b.Property("Sex") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("AlignmentId"); + + b.HasIndex("BackgroundId"); + + b.HasIndex("CharacterId") + .IsUnique(); + + b.HasIndex("ClassId"); + + b.HasIndex("RaceId"); + + b.ToTable("Biographies"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Character", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .UseIdentityColumn(); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Characters"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Class", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .UseIdentityColumn(); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Classes"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Race", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .UseIdentityColumn(); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Races"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Statistics", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .UseIdentityColumn(); + + b.Property("ArmorClass") + .HasColumnType("int"); + + b.Property("CharacterId") + .HasColumnType("int"); + + b.Property("CurrentHealthPoints") + .HasColumnType("int"); + + b.Property("ExperiencePoints") + .HasColumnType("int"); + + b.Property("HealthPoints") + .HasColumnType("int"); + + b.Property("Initiative") + .HasColumnType("int"); + + b.Property("Level") + .HasColumnType("int"); + + b.Property("Proficiency") + .HasColumnType("int"); + + b.Property("Speed") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CharacterId") + .IsUnique(); + + b.ToTable("Statistics"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .UseIdentityColumn(); + + b.Property("Nickname") + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Users"); + + b.HasData( + new + { + Id = 1, + Nickname = "Morwiec", + Password = "123" + }, + new + { + Id = 2, + Nickname = "Cichoklepiec", + Password = "123" + }, + new + { + Id = 3, + Nickname = "Ruletka", + Password = "123" + }); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Biography", b => + { + b.HasOne("SessionCompanion.Database.Tables.Alignment", "Alignment") + .WithMany("Biography") + .HasForeignKey("AlignmentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SessionCompanion.Database.Tables.Background", "Background") + .WithMany("Biography") + .HasForeignKey("BackgroundId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SessionCompanion.Database.Tables.Character", "Character") + .WithOne("Biography") + .HasForeignKey("SessionCompanion.Database.Tables.Biography", "CharacterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SessionCompanion.Database.Tables.Class", "Class") + .WithMany("Biography") + .HasForeignKey("ClassId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SessionCompanion.Database.Tables.Race", "Race") + .WithMany("Biography") + .HasForeignKey("RaceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Alignment"); + + b.Navigation("Background"); + + b.Navigation("Character"); + + b.Navigation("Class"); + + b.Navigation("Race"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Character", b => + { + b.HasOne("SessionCompanion.Database.Tables.User", "User") + .WithMany("Character") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Statistics", b => + { + b.HasOne("SessionCompanion.Database.Tables.Character", "Character") + .WithOne("Statistics") + .HasForeignKey("SessionCompanion.Database.Tables.Statistics", "CharacterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Character"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Alignment", b => + { + b.Navigation("Biography"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Background", b => + { + b.Navigation("Biography"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Character", b => + { + b.Navigation("Biography"); + + b.Navigation("Statistics"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Class", b => + { + b.Navigation("Biography"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.Race", b => + { + b.Navigation("Biography"); + }); + + modelBuilder.Entity("SessionCompanion.Database.Tables.User", b => + { + b.Navigation("Character"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SessionCompanion/SessionCompanion.Database/SeedData.cs b/SessionCompanion/SessionCompanion.Database/SeedData.cs new file mode 100644 index 0000000..40edfc4 --- /dev/null +++ b/SessionCompanion/SessionCompanion.Database/SeedData.cs @@ -0,0 +1,39 @@ +using Microsoft.EntityFrameworkCore; +using SessionCompanion.Database.Tables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SessionCompanion.Database +{ + public class SeedData + { + static public List SeedUsers() + { + List users = new List + { + new User + { + Id = 1, + Nickname = "Morwiec", + Password = "123" + }, + new User + { + Id = 2, + Nickname = "Cichoklepiec", + Password = "123" + }, + new User + { + Id = 3, + Nickname = "Ruletka", + Password = "123" + } + }; + return users; + } + } +} diff --git a/SessionCompanion/SessionCompanion.Database/SessionCompanion.Database.csproj b/SessionCompanion/SessionCompanion.Database/SessionCompanion.Database.csproj new file mode 100644 index 0000000..6858ae5 --- /dev/null +++ b/SessionCompanion/SessionCompanion.Database/SessionCompanion.Database.csproj @@ -0,0 +1,24 @@ + + + + net5.0 + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/SessionCompanion/SessionCompanion.Database/Tables/Alignment.cs b/SessionCompanion/SessionCompanion.Database/Tables/Alignment.cs new file mode 100644 index 0000000..a5e5d2c --- /dev/null +++ b/SessionCompanion/SessionCompanion.Database/Tables/Alignment.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SessionCompanion.Database.Tables +{ + public class Alignment : BaseEntity + { + public virtual ICollection Biography { get; set; } + } +} diff --git a/SessionCompanion/SessionCompanion.Database/Tables/Background.cs b/SessionCompanion/SessionCompanion.Database/Tables/Background.cs new file mode 100644 index 0000000..7bedfae --- /dev/null +++ b/SessionCompanion/SessionCompanion.Database/Tables/Background.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SessionCompanion.Database.Tables +{ + public class Background : BaseEntity + { + public virtual ICollection Biography { get; set; } + } +} diff --git a/SessionCompanion/SessionCompanion.Database/Tables/BaseEntity.cs b/SessionCompanion/SessionCompanion.Database/Tables/BaseEntity.cs new file mode 100644 index 0000000..4761d98 --- /dev/null +++ b/SessionCompanion/SessionCompanion.Database/Tables/BaseEntity.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SessionCompanion.Database.Tables +{ + public class BaseEntity + { + [Key] + public int Id { get; set; } + } +} diff --git a/SessionCompanion/SessionCompanion.Database/Tables/Biography.cs b/SessionCompanion/SessionCompanion.Database/Tables/Biography.cs new file mode 100644 index 0000000..512a813 --- /dev/null +++ b/SessionCompanion/SessionCompanion.Database/Tables/Biography.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Text; + +namespace SessionCompanion.Database.Tables +{ + public class Biography : BaseEntity + { + [ForeignKey(nameof(Character))] + public int CharacterId { get; set; } + public virtual Character Character { get; set; } + + public string Name { get; set; } + + [ForeignKey(nameof(Class))] + public int ClassId { get; set; } + public virtual Class Class { get; set; } + + [ForeignKey(nameof(Race))] + public int RaceId { get; set; } + public virtual Race Race { get; set; } + + [ForeignKey(nameof(Alignment))] + public int AlignmentId { get; set; } + public virtual Alignment Alignment { get; set; } + + [ForeignKey(nameof(Background))] + public int BackgroundId { get; set; } + public virtual Background Background { get; set; } + + public string Sex { get; set; } + } +} diff --git a/SessionCompanion/SessionCompanion.Database/Tables/Character.cs b/SessionCompanion/SessionCompanion.Database/Tables/Character.cs new file mode 100644 index 0000000..0c2cff7 --- /dev/null +++ b/SessionCompanion/SessionCompanion.Database/Tables/Character.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Text; + +namespace SessionCompanion.Database.Tables +{ + public class Character : BaseEntity + { + [ForeignKey(nameof(User))] + public int UserId { get; set; } + public virtual User User { get; set; } + public virtual Biography Biography { get; set; } + public virtual Statistics Statistics { get; set; } + } +} diff --git a/SessionCompanion/SessionCompanion.Database/Tables/Class.cs b/SessionCompanion/SessionCompanion.Database/Tables/Class.cs new file mode 100644 index 0000000..ce73e7c --- /dev/null +++ b/SessionCompanion/SessionCompanion.Database/Tables/Class.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SessionCompanion.Database.Tables +{ + public class Class : BaseEntity + { + public string Name { get; set; } + //public int HitDie { get; set; } + + public virtual ICollection Biography { get; set; } + } +} diff --git a/SessionCompanion/SessionCompanion.Database/Tables/Race.cs b/SessionCompanion/SessionCompanion.Database/Tables/Race.cs new file mode 100644 index 0000000..07b04a1 --- /dev/null +++ b/SessionCompanion/SessionCompanion.Database/Tables/Race.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SessionCompanion.Database.Tables +{ + public class Race : BaseEntity + { + public string Name { get; set; } + public virtual ICollection Biography { get; set; } + } +} diff --git a/SessionCompanion/SessionCompanion.Database/Tables/Statistics.cs b/SessionCompanion/SessionCompanion.Database/Tables/Statistics.cs new file mode 100644 index 0000000..a5c36e5 --- /dev/null +++ b/SessionCompanion/SessionCompanion.Database/Tables/Statistics.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Text; + +namespace SessionCompanion.Database.Tables +{ + public class Statistics : BaseEntity + { + [ForeignKey(nameof(Character))] + public int CharacterId { get; set; } + public virtual Character Character { get; set; } + + public int ExperiencePoints { get; set; } + public int Level { get; set; } + public int Speed { get; set; } + public int Initiative { get; set; } + public int HealthPoints { get; set; } + public int CurrentHealthPoints { get; set; } + public int ArmorClass { get; set; } + public int Proficiency { get; set; } + } +} diff --git a/SessionCompanion/SessionCompanion.Database/Tables/User.cs b/SessionCompanion/SessionCompanion.Database/Tables/User.cs new file mode 100644 index 0000000..bbebdeb --- /dev/null +++ b/SessionCompanion/SessionCompanion.Database/Tables/User.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SessionCompanion.Database.Tables +{ + public class User : BaseEntity + { + public string Nickname { get; set; } + public string Password { get; set; } + public ICollection Character { get; set; } + } +} diff --git a/SessionCompanion/SessionCompanion.sln b/SessionCompanion/SessionCompanion.sln index d6d9420..0b42c62 100644 --- a/SessionCompanion/SessionCompanion.sln +++ b/SessionCompanion/SessionCompanion.sln @@ -1,25 +1,31 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30717.126 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SessionCompanion", "SessionCompanion\SessionCompanion.csproj", "{C646135F-16CE-4B16-B041-252D343D4E01}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C646135F-16CE-4B16-B041-252D343D4E01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C646135F-16CE-4B16-B041-252D343D4E01}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C646135F-16CE-4B16-B041-252D343D4E01}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C646135F-16CE-4B16-B041-252D343D4E01}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {121AE434-C579-4495-9318-0D7D7DBE0FD8} - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30717.126 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SessionCompanion", "SessionCompanion\SessionCompanion.csproj", "{C646135F-16CE-4B16-B041-252D343D4E01}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SessionCompanion.Database", "SessionCompanion.Database\SessionCompanion.Database.csproj", "{CA05189B-A4AB-4946-80DC-EFA075A10F09}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C646135F-16CE-4B16-B041-252D343D4E01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C646135F-16CE-4B16-B041-252D343D4E01}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C646135F-16CE-4B16-B041-252D343D4E01}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C646135F-16CE-4B16-B041-252D343D4E01}.Release|Any CPU.Build.0 = Release|Any CPU + {CA05189B-A4AB-4946-80DC-EFA075A10F09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CA05189B-A4AB-4946-80DC-EFA075A10F09}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CA05189B-A4AB-4946-80DC-EFA075A10F09}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CA05189B-A4AB-4946-80DC-EFA075A10F09}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {121AE434-C579-4495-9318-0D7D7DBE0FD8} + EndGlobalSection +EndGlobal diff --git a/SessionCompanion/SessionCompanion/SessionCompanion.csproj b/SessionCompanion/SessionCompanion/SessionCompanion.csproj index 83b3adc..07210e5 100644 --- a/SessionCompanion/SessionCompanion/SessionCompanion.csproj +++ b/SessionCompanion/SessionCompanion/SessionCompanion.csproj @@ -14,6 +14,11 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + @@ -27,6 +32,10 @@ + + + + diff --git a/SessionCompanion/SessionCompanion/Startup.cs b/SessionCompanion/SessionCompanion/Startup.cs index 22af514..74d6b69 100644 --- a/SessionCompanion/SessionCompanion/Startup.cs +++ b/SessionCompanion/SessionCompanion/Startup.cs @@ -2,10 +2,12 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.SpaServices.AngularCli; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; - +using SessionCompanion.Database; + namespace SessionCompanion { public class Startup @@ -22,16 +24,24 @@ namespace SessionCompanion public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); + services.AddDbContext(options => + options.UseSqlServer( + Configuration.GetConnectionString("DefaultConnection"))); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); + } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { + using (var serviceScope = app.ApplicationServices.GetRequiredService().CreateScope()) + { + serviceScope.ServiceProvider.GetService().Database.Migrate(); + } if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); diff --git a/SessionCompanion/SessionCompanion/appsettings.json b/SessionCompanion/SessionCompanion/appsettings.json index ad75fee..cb23b68 100644 --- a/SessionCompanion/SessionCompanion/appsettings.json +++ b/SessionCompanion/SessionCompanion/appsettings.json @@ -1,10 +1,13 @@ { + "ConnectionStrings": { + "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=SessionCompanion;Trusted_Connection=True;MultipleActiveResultSets=true" + }, "Logging": { - "LogLevel": { + "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" - } - }, -"AllowedHosts": "*" + } + }, + "AllowedHosts": "*" }