Flesh out domain and start student commands

This commit is contained in:
2019-04-24 17:50:37 +00:00
parent a51306af55
commit a30e9a5b1c
18 changed files with 648 additions and 197 deletions

View File

@@ -14,12 +14,23 @@ namespace BrightGlimmer.Data
{
}
// dotnet ef migrations add NAME --project ./BrightGlimmer.Data --startup-project ./BrightGlimmer.Api
// dotnet ef migrations update --project ./BrightGlimmer.Data --startup-project ./BrightGlimmer.Api
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Student>()
.HasMany(x => x.Phones);
modelBuilder.Entity<Student>()
.HasOne(x => x.Address);
modelBuilder.Entity<Student>()
.HasMany(x => x.AssignedCourses);
modelBuilder.Entity<AssignedCourse>()
.HasOne(x => x.Course);
}
public DbSet<Student> Students { get; set; }
public DbSet<Course> Courses { get; set; }
public DbSet<AssignedCourse> AssignedCourses { get; set; }
}
}

View File

@@ -1,68 +0,0 @@
// <auto-generated />
using System;
using BrightGlimmer.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace BrightGlimmer.Data.Migrations
{
[DbContext(typeof(BgContext))]
[Migration("20190420001348_CreateDatabase")]
partial class CreateDatabase
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.4-servicing-10062");
modelBuilder.Entity("BrightGlimmer.Data.Domain.Phone", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("AreaCode");
b.Property<int>("Number");
b.Property<Guid?>("StudentId");
b.Property<int>("Type");
b.HasKey("Id");
b.HasIndex("StudentId");
b.ToTable("Phone");
});
modelBuilder.Entity("BrightGlimmer.Data.Domain.Student", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Email");
b.Property<string>("FirstName");
b.Property<string>("LastName");
b.Property<string>("MiddleName");
b.HasKey("Id");
b.ToTable("Students");
});
modelBuilder.Entity("BrightGlimmer.Data.Domain.Phone", b =>
{
b.HasOne("BrightGlimmer.Data.Domain.Student")
.WithMany("Phones")
.HasForeignKey("StudentId");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,61 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace BrightGlimmer.Data.Migrations
{
public partial class CreateDatabase : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Students",
columns: table => new
{
Id = table.Column<Guid>(nullable: false),
FirstName = table.Column<string>(nullable: true),
MiddleName = table.Column<string>(nullable: true),
LastName = table.Column<string>(nullable: true),
Email = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Students", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Phone",
columns: table => new
{
Id = table.Column<Guid>(nullable: false),
Type = table.Column<int>(nullable: false),
AreaCode = table.Column<int>(nullable: false),
Number = table.Column<int>(nullable: false),
StudentId = table.Column<Guid>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Phone", x => x.Id);
table.ForeignKey(
name: "FK_Phone_Students_StudentId",
column: x => x.StudentId,
principalTable: "Students",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_Phone_StudentId",
table: "Phone",
column: "StudentId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Phone");
migrationBuilder.DropTable(
name: "Students");
}
}
}

View File

@@ -0,0 +1,190 @@
// <auto-generated />
using System;
using BrightGlimmer.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace BrightGlimmer.Data.Migrations
{
[DbContext(typeof(BgContext))]
[Migration("20190424174147_CreateDatabase")]
partial class CreateDatabase
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.4-servicing-10062");
modelBuilder.Entity("BrightGlimmer.Domain.Address", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("City");
b.Property<string>("County");
b.Property<DateTime>("CreatedDate");
b.Property<bool>("IsDeleted");
b.Property<decimal>("Latitude");
b.Property<decimal>("Longitude");
b.Property<DateTime>("ModifiedDate");
b.Property<string>("StateCode");
b.Property<string>("StreetAddress1");
b.Property<string>("StreetAddress2");
b.Property<string>("ZipCode");
b.HasKey("Id");
b.ToTable("Addresses");
});
modelBuilder.Entity("BrightGlimmer.Domain.AssignedCourse", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<Guid?>("CourseId");
b.Property<DateTime>("CreatedDate");
b.Property<decimal>("Grade");
b.Property<bool>("IsActive");
b.Property<bool>("IsDeleted");
b.Property<DateTime>("ModifiedDate");
b.Property<Guid?>("StudentId");
b.Property<string>("Term");
b.HasKey("Id");
b.HasIndex("CourseId");
b.HasIndex("StudentId");
b.ToTable("AssignedCourses");
});
modelBuilder.Entity("BrightGlimmer.Domain.Course", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Code");
b.Property<DateTime>("CreatedDate");
b.Property<string>("Description");
b.Property<bool>("IsDeleted");
b.Property<DateTime>("ModifiedDate");
b.Property<string>("Name");
b.HasKey("Id");
b.ToTable("Courses");
});
modelBuilder.Entity("BrightGlimmer.Domain.Phone", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("AreaCode");
b.Property<DateTime>("CreatedDate");
b.Property<bool>("IsDeleted");
b.Property<DateTime>("ModifiedDate");
b.Property<int>("Number");
b.Property<Guid?>("StudentId");
b.Property<int>("Type");
b.HasKey("Id");
b.HasIndex("StudentId");
b.ToTable("Phones");
});
modelBuilder.Entity("BrightGlimmer.Domain.Student", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<Guid?>("AddressId");
b.Property<DateTime>("CreatedDate");
b.Property<string>("Email");
b.Property<string>("FirstName");
b.Property<bool>("IsDeleted");
b.Property<string>("LastName");
b.Property<string>("MiddleName");
b.Property<DateTime>("ModifiedDate");
b.Property<string>("ProfilePictureUrl");
b.Property<int>("StudentNumber");
b.HasKey("Id");
b.HasIndex("AddressId");
b.ToTable("Students");
});
modelBuilder.Entity("BrightGlimmer.Domain.AssignedCourse", b =>
{
b.HasOne("BrightGlimmer.Domain.Course", "Course")
.WithMany()
.HasForeignKey("CourseId");
b.HasOne("BrightGlimmer.Domain.Student", "Student")
.WithMany("AssignedCourses")
.HasForeignKey("StudentId");
});
modelBuilder.Entity("BrightGlimmer.Domain.Phone", b =>
{
b.HasOne("BrightGlimmer.Domain.Student")
.WithMany("Phones")
.HasForeignKey("StudentId");
});
modelBuilder.Entity("BrightGlimmer.Domain.Student", b =>
{
b.HasOne("BrightGlimmer.Domain.Address", "Address")
.WithMany()
.HasForeignKey("AddressId");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,170 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace BrightGlimmer.Data.Migrations
{
public partial class CreateDatabase : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Addresses",
columns: table => new
{
Id = table.Column<Guid>(nullable: false),
IsDeleted = table.Column<bool>(nullable: false),
CreatedDate = table.Column<DateTime>(nullable: false),
ModifiedDate = table.Column<DateTime>(nullable: false),
StreetAddress1 = table.Column<string>(nullable: true),
StreetAddress2 = table.Column<string>(nullable: true),
City = table.Column<string>(nullable: true),
StateCode = table.Column<string>(nullable: true),
County = table.Column<string>(nullable: true),
ZipCode = table.Column<string>(nullable: true),
Latitude = table.Column<decimal>(nullable: false),
Longitude = table.Column<decimal>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Addresses", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Courses",
columns: table => new
{
Id = table.Column<Guid>(nullable: false),
IsDeleted = table.Column<bool>(nullable: false),
CreatedDate = table.Column<DateTime>(nullable: false),
ModifiedDate = table.Column<DateTime>(nullable: false),
Name = table.Column<string>(nullable: true),
Description = table.Column<string>(nullable: true),
Code = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Courses", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Students",
columns: table => new
{
Id = table.Column<Guid>(nullable: false),
IsDeleted = table.Column<bool>(nullable: false),
CreatedDate = table.Column<DateTime>(nullable: false),
ModifiedDate = table.Column<DateTime>(nullable: false),
StudentNumber = table.Column<int>(nullable: false),
FirstName = table.Column<string>(nullable: true),
MiddleName = table.Column<string>(nullable: true),
LastName = table.Column<string>(nullable: true),
Email = table.Column<string>(nullable: true),
AddressId = table.Column<Guid>(nullable: true),
ProfilePictureUrl = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Students", x => x.Id);
table.ForeignKey(
name: "FK_Students_Addresses_AddressId",
column: x => x.AddressId,
principalTable: "Addresses",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "AssignedCourses",
columns: table => new
{
Id = table.Column<Guid>(nullable: false),
IsDeleted = table.Column<bool>(nullable: false),
CreatedDate = table.Column<DateTime>(nullable: false),
ModifiedDate = table.Column<DateTime>(nullable: false),
Grade = table.Column<decimal>(nullable: false),
IsActive = table.Column<bool>(nullable: false),
Term = table.Column<string>(nullable: true),
StudentId = table.Column<Guid>(nullable: true),
CourseId = table.Column<Guid>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AssignedCourses", x => x.Id);
table.ForeignKey(
name: "FK_AssignedCourses_Courses_CourseId",
column: x => x.CourseId,
principalTable: "Courses",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_AssignedCourses_Students_StudentId",
column: x => x.StudentId,
principalTable: "Students",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Phones",
columns: table => new
{
Id = table.Column<Guid>(nullable: false),
IsDeleted = table.Column<bool>(nullable: false),
CreatedDate = table.Column<DateTime>(nullable: false),
ModifiedDate = table.Column<DateTime>(nullable: false),
Type = table.Column<int>(nullable: false),
AreaCode = table.Column<int>(nullable: false),
Number = table.Column<int>(nullable: false),
StudentId = table.Column<Guid>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Phones", x => x.Id);
table.ForeignKey(
name: "FK_Phones_Students_StudentId",
column: x => x.StudentId,
principalTable: "Students",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_AssignedCourses_CourseId",
table: "AssignedCourses",
column: "CourseId");
migrationBuilder.CreateIndex(
name: "IX_AssignedCourses_StudentId",
table: "AssignedCourses",
column: "StudentId");
migrationBuilder.CreateIndex(
name: "IX_Phones_StudentId",
table: "Phones",
column: "StudentId");
migrationBuilder.CreateIndex(
name: "IX_Students_AddressId",
table: "Students",
column: "AddressId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AssignedCourses");
migrationBuilder.DropTable(
name: "Phones");
migrationBuilder.DropTable(
name: "Courses");
migrationBuilder.DropTable(
name: "Students");
migrationBuilder.DropTable(
name: "Addresses");
}
}
}

View File

@@ -0,0 +1,188 @@
// <auto-generated />
using System;
using BrightGlimmer.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace BrightGlimmer.Data.Migrations
{
[DbContext(typeof(BgContext))]
partial class BgContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.4-servicing-10062");
modelBuilder.Entity("BrightGlimmer.Domain.Address", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("City");
b.Property<string>("County");
b.Property<DateTime>("CreatedDate");
b.Property<bool>("IsDeleted");
b.Property<decimal>("Latitude");
b.Property<decimal>("Longitude");
b.Property<DateTime>("ModifiedDate");
b.Property<string>("StateCode");
b.Property<string>("StreetAddress1");
b.Property<string>("StreetAddress2");
b.Property<string>("ZipCode");
b.HasKey("Id");
b.ToTable("Addresses");
});
modelBuilder.Entity("BrightGlimmer.Domain.AssignedCourse", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<Guid?>("CourseId");
b.Property<DateTime>("CreatedDate");
b.Property<decimal>("Grade");
b.Property<bool>("IsActive");
b.Property<bool>("IsDeleted");
b.Property<DateTime>("ModifiedDate");
b.Property<Guid?>("StudentId");
b.Property<string>("Term");
b.HasKey("Id");
b.HasIndex("CourseId");
b.HasIndex("StudentId");
b.ToTable("AssignedCourses");
});
modelBuilder.Entity("BrightGlimmer.Domain.Course", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Code");
b.Property<DateTime>("CreatedDate");
b.Property<string>("Description");
b.Property<bool>("IsDeleted");
b.Property<DateTime>("ModifiedDate");
b.Property<string>("Name");
b.HasKey("Id");
b.ToTable("Courses");
});
modelBuilder.Entity("BrightGlimmer.Domain.Phone", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("AreaCode");
b.Property<DateTime>("CreatedDate");
b.Property<bool>("IsDeleted");
b.Property<DateTime>("ModifiedDate");
b.Property<int>("Number");
b.Property<Guid?>("StudentId");
b.Property<int>("Type");
b.HasKey("Id");
b.HasIndex("StudentId");
b.ToTable("Phones");
});
modelBuilder.Entity("BrightGlimmer.Domain.Student", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<Guid?>("AddressId");
b.Property<DateTime>("CreatedDate");
b.Property<string>("Email");
b.Property<string>("FirstName");
b.Property<bool>("IsDeleted");
b.Property<string>("LastName");
b.Property<string>("MiddleName");
b.Property<DateTime>("ModifiedDate");
b.Property<string>("ProfilePictureUrl");
b.Property<int>("StudentNumber");
b.HasKey("Id");
b.HasIndex("AddressId");
b.ToTable("Students");
});
modelBuilder.Entity("BrightGlimmer.Domain.AssignedCourse", b =>
{
b.HasOne("BrightGlimmer.Domain.Course", "Course")
.WithMany()
.HasForeignKey("CourseId");
b.HasOne("BrightGlimmer.Domain.Student", "Student")
.WithMany("AssignedCourses")
.HasForeignKey("StudentId");
});
modelBuilder.Entity("BrightGlimmer.Domain.Phone", b =>
{
b.HasOne("BrightGlimmer.Domain.Student")
.WithMany("Phones")
.HasForeignKey("StudentId");
});
modelBuilder.Entity("BrightGlimmer.Domain.Student", b =>
{
b.HasOne("BrightGlimmer.Domain.Address", "Address")
.WithMany()
.HasForeignKey("AddressId");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -1,66 +0,0 @@
// <auto-generated />
using System;
using BrightGlimmer.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace BrightGlimmer.Data.Migrations
{
[DbContext(typeof(BgContext))]
partial class SqliteDatabaseContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.4-servicing-10062");
modelBuilder.Entity("BrightGlimmer.Data.Domain.Phone", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("AreaCode");
b.Property<int>("Number");
b.Property<Guid?>("StudentId");
b.Property<int>("Type");
b.HasKey("Id");
b.HasIndex("StudentId");
b.ToTable("Phone");
});
modelBuilder.Entity("BrightGlimmer.Data.Domain.Student", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Email");
b.Property<string>("FirstName");
b.Property<string>("LastName");
b.Property<string>("MiddleName");
b.HasKey("Id");
b.ToTable("Students");
});
modelBuilder.Entity("BrightGlimmer.Data.Domain.Phone", b =>
{
b.HasOne("BrightGlimmer.Data.Domain.Student")
.WithMany("Phones")
.HasForeignKey("StudentId");
});
#pragma warning restore 612, 618
}
}
}

Binary file not shown.