Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add controller UI #20

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,23 @@ namespace TodoApp.DataAccess.DataModels
public class Todo
{
public long Id { get; set; }

[Required]
public string Name { get; set; }

public string? Description { get; set; }

public bool IsCompleted { get; set; }

[Required]
public DateTime CreatedTime { get; set; }

public DateTime? CompletedTime { get; set; }

[Required]
[ForeignKey("User")]
public long CreatedUser { get; set; }

public virtual User? User { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System.Reflection.Metadata;

namespace TodoApp.DataAccess.DataModels
{
Expand All @@ -13,5 +14,12 @@ public TodoContext(DbContextOptions<TodoContext> options) : base(options) { }
public string Name => nameof(TodoContext);
public string Provider => nameof(Microsoft.EntityFrameworkCore);

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>()
.HasData(
new User { Id = 1, FirstName = "Admin", LastName = "Admin", Email = "[email protected]" });
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ namespace TodoApp.DataAccess.DataModels
public class User
{
public long Id { get; set; }

[Required]
public string Email { get; set; }

[Required]
public string FirstName { get; set; }

[Required]
public string LastName { get; set; }

public ICollection<Todo> ToDos { get; set; }


}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace TodoApp.DataAccess.Migrations
{
public partial class InitialMigration : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "User",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
FirstName = table.Column<string>(type: "nvarchar(max)", nullable: false),
LastName = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_User", x => x.Id);
});

migrationBuilder.CreateTable(
name: "Todo",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: true),
IsCompleted = table.Column<bool>(type: "bit", nullable: false),
CreatedTime = table.Column<DateTime>(type: "datetime2", nullable: false),
CompletedTime = table.Column<DateTime>(type: "datetime2", nullable: true),
CreatedUser = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Todo", x => x.Id);
table.ForeignKey(
name: "FK_Todo_User_CreatedUser",
column: x => x.CreatedUser,
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});

migrationBuilder.InsertData(
table: "User",
columns: new[] { "Id", "Email", "FirstName", "LastName" },
values: new object[] { 1L, "[email protected]", "Admin", "Admin" });

migrationBuilder.CreateIndex(
name: "IX_Todo_CreatedUser",
table: "Todo",
column: "CreatedUser");
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Todo");

migrationBuilder.DropTable(
name: "User");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.9")
.HasAnnotation("ProductVersion", "6.0.10")
.HasAnnotation("Relational:MaxIdentifierLength", 128);

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
Expand Down Expand Up @@ -51,6 +51,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("Id");

b.HasIndex("CreatedUser");

b.ToTable("Todo");
});

Expand All @@ -77,6 +79,31 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasKey("Id");

b.ToTable("User");

b.HasData(
new
{
Id = 1L,
Email = "[email protected]",
FirstName = "Admin",
LastName = "Admin"
});
});

modelBuilder.Entity("TodoApp.DataAccess.DataModels.Todo", b =>
{
b.HasOne("TodoApp.DataAccess.DataModels.User", "User")
.WithMany("ToDos")
.HasForeignKey("CreatedUser")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

b.Navigation("User");
});

modelBuilder.Entity("TodoApp.DataAccess.DataModels.User", b =>
{
b.Navigation("ToDos");
});
#pragma warning restore 612, 618
}
Expand Down
Loading