diff --git a/BlazorApp/SharedData/Models/Book.cs b/BlazorApp/SharedData/Models/Book.cs new file mode 100644 index 0000000..72907e2 --- /dev/null +++ b/BlazorApp/SharedData/Models/Book.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharedData.Models +{ + public class Book + { + public int BookId { get; set; } + public string Title { get; set; } + public string ISBN { get; set; } + public ICollection Reviews { get; set; } + } +} diff --git a/BlazorApp/SharedData/Models/Review.cs b/BlazorApp/SharedData/Models/Review.cs new file mode 100644 index 0000000..c671983 --- /dev/null +++ b/BlazorApp/SharedData/Models/Review.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharedData.Models +{ + public class Review + { + public int ReviewId { get; set; } + //[ForeignKey("Book")] + public int BookId { get; set; } + public string Context { get; set; } + } +} diff --git a/BlazorApp/WebAPI/Data/ApplicationDbContext.cs b/BlazorApp/WebAPI/Data/ApplicationDbContext.cs index 2e9ce35..b33ee1c 100644 --- a/BlazorApp/WebAPI/Data/ApplicationDbContext.cs +++ b/BlazorApp/WebAPI/Data/ApplicationDbContext.cs @@ -6,6 +6,8 @@ namespace WebAPI.Data public class ApplicationDbContext : DbContext { public DbSet GameResults { get; set; } + public DbSet Books { get; set; } + public DbSet Reviews { get; set; } public ApplicationDbContext(DbContextOptions options) : base(options) diff --git a/BlazorApp/WebAPI/Migrations/20230828042927_book-review.Designer.cs b/BlazorApp/WebAPI/Migrations/20230828042927_book-review.Designer.cs new file mode 100644 index 0000000..ed9d6c2 --- /dev/null +++ b/BlazorApp/WebAPI/Migrations/20230828042927_book-review.Designer.cs @@ -0,0 +1,111 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using WebAPI.Data; + +#nullable disable + +namespace WebAPI.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20230828042927_book-review")] + partial class bookreview + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("SharedData.Models.Book", b => + { + b.Property("BookId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("BookId")); + + b.Property("ISBN") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("BookId"); + + b.ToTable("Books"); + }); + + modelBuilder.Entity("SharedData.Models.GameResult", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("datetime2"); + + b.Property("Score") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("GameResults"); + }); + + modelBuilder.Entity("SharedData.Models.Review", b => + { + b.Property("ReviewId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ReviewId")); + + b.Property("BookId") + .HasColumnType("int"); + + b.Property("Context") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("ReviewId"); + + b.HasIndex("BookId"); + + b.ToTable("Reviews"); + }); + + modelBuilder.Entity("SharedData.Models.Review", b => + { + b.HasOne("SharedData.Models.Book", null) + .WithMany("Reviews") + .HasForeignKey("BookId"); + }); + + modelBuilder.Entity("SharedData.Models.Book", b => + { + b.Navigation("Reviews"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BlazorApp/WebAPI/Migrations/20230828042927_book-review.cs b/BlazorApp/WebAPI/Migrations/20230828042927_book-review.cs new file mode 100644 index 0000000..41e6e65 --- /dev/null +++ b/BlazorApp/WebAPI/Migrations/20230828042927_book-review.cs @@ -0,0 +1,62 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace WebAPI.Migrations +{ + /// + public partial class bookreview : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Books", + columns: table => new + { + BookId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Title = table.Column(type: "nvarchar(max)", nullable: false), + ISBN = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Books", x => x.BookId); + }); + + migrationBuilder.CreateTable( + name: "Reviews", + columns: table => new + { + ReviewId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Context = table.Column(type: "nvarchar(max)", nullable: false), + BookId = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Reviews", x => x.ReviewId); + table.ForeignKey( + name: "FK_Reviews_Books_BookId", + column: x => x.BookId, + principalTable: "Books", + principalColumn: "BookId"); + }); + + migrationBuilder.CreateIndex( + name: "IX_Reviews_BookId", + table: "Reviews", + column: "BookId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Reviews"); + + migrationBuilder.DropTable( + name: "Books"); + } + } +} diff --git a/BlazorApp/WebAPI/Migrations/20230828043008_book-review2.Designer.cs b/BlazorApp/WebAPI/Migrations/20230828043008_book-review2.Designer.cs new file mode 100644 index 0000000..cad49d6 --- /dev/null +++ b/BlazorApp/WebAPI/Migrations/20230828043008_book-review2.Designer.cs @@ -0,0 +1,113 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using WebAPI.Data; + +#nullable disable + +namespace WebAPI.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20230828043008_book-review2")] + partial class bookreview2 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("SharedData.Models.Book", b => + { + b.Property("BookId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("BookId")); + + b.Property("ISBN") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("BookId"); + + b.ToTable("Books"); + }); + + modelBuilder.Entity("SharedData.Models.GameResult", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("datetime2"); + + b.Property("Score") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("GameResults"); + }); + + modelBuilder.Entity("SharedData.Models.Review", b => + { + b.Property("ReviewId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ReviewId")); + + b.Property("BookId") + .HasColumnType("int"); + + b.Property("Context") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("ReviewId"); + + b.HasIndex("BookId"); + + b.ToTable("Reviews"); + }); + + modelBuilder.Entity("SharedData.Models.Review", b => + { + b.HasOne("SharedData.Models.Book", null) + .WithMany("Reviews") + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("SharedData.Models.Book", b => + { + b.Navigation("Reviews"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BlazorApp/WebAPI/Migrations/20230828043008_book-review2.cs b/BlazorApp/WebAPI/Migrations/20230828043008_book-review2.cs new file mode 100644 index 0000000..17166d1 --- /dev/null +++ b/BlazorApp/WebAPI/Migrations/20230828043008_book-review2.cs @@ -0,0 +1,59 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace WebAPI.Migrations +{ + /// + public partial class bookreview2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Reviews_Books_BookId", + table: "Reviews"); + + migrationBuilder.AlterColumn( + name: "BookId", + table: "Reviews", + type: "int", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_Reviews_Books_BookId", + table: "Reviews", + column: "BookId", + principalTable: "Books", + principalColumn: "BookId", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Reviews_Books_BookId", + table: "Reviews"); + + migrationBuilder.AlterColumn( + name: "BookId", + table: "Reviews", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "int"); + + migrationBuilder.AddForeignKey( + name: "FK_Reviews_Books_BookId", + table: "Reviews", + column: "BookId", + principalTable: "Books", + principalColumn: "BookId"); + } + } +} diff --git a/BlazorApp/WebAPI/Migrations/ApplicationDbContextModelSnapshot.cs b/BlazorApp/WebAPI/Migrations/ApplicationDbContextModelSnapshot.cs index 65ae33e..1594605 100644 --- a/BlazorApp/WebAPI/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/BlazorApp/WebAPI/Migrations/ApplicationDbContextModelSnapshot.cs @@ -22,6 +22,27 @@ namespace WebAPI.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + modelBuilder.Entity("SharedData.Models.Book", b => + { + b.Property("BookId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("BookId")); + + b.Property("ISBN") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("BookId"); + + b.ToTable("Books"); + }); + modelBuilder.Entity("SharedData.Models.GameResult", b => { b.Property("Id") @@ -47,6 +68,42 @@ namespace WebAPI.Migrations b.ToTable("GameResults"); }); + + modelBuilder.Entity("SharedData.Models.Review", b => + { + b.Property("ReviewId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ReviewId")); + + b.Property("BookId") + .HasColumnType("int"); + + b.Property("Context") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("ReviewId"); + + b.HasIndex("BookId"); + + b.ToTable("Reviews"); + }); + + modelBuilder.Entity("SharedData.Models.Review", b => + { + b.HasOne("SharedData.Models.Book", null) + .WithMany("Reviews") + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("SharedData.Models.Book", b => + { + b.Navigation("Reviews"); + }); #pragma warning restore 612, 618 } }