diff --git a/ProjectManager/DataAccess/DataAccess.csproj b/ProjectManager/DataAccess/DataAccess.csproj new file mode 100644 index 0000000..91c5d38 --- /dev/null +++ b/ProjectManager/DataAccess/DataAccess.csproj @@ -0,0 +1,21 @@ + + + + Exe + net7.0 + enable + enable + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/ProjectManager/DataAccess/Migrations/20231101124242_Initial.Designer.cs b/ProjectManager/DataAccess/Migrations/20231101124242_Initial.Designer.cs new file mode 100644 index 0000000..13572c5 --- /dev/null +++ b/ProjectManager/DataAccess/Migrations/20231101124242_Initial.Designer.cs @@ -0,0 +1,84 @@ +// +using DataAccess; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DataAccess.Migrations +{ + [DbContext(typeof(ProjectContext))] + [Migration("20231101124242_Initial")] + partial class Initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.13") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DataAccess.Project", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Projects"); + }); + + modelBuilder.Entity("DataAccess.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ProjectId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ProjectId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("DataAccess.User", b => + { + b.HasOne("DataAccess.Project", "Project") + .WithMany("Users") + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Project"); + }); + + modelBuilder.Entity("DataAccess.Project", b => + { + b.Navigation("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ProjectManager/DataAccess/Migrations/20231101124242_Initial.cs b/ProjectManager/DataAccess/Migrations/20231101124242_Initial.cs new file mode 100644 index 0000000..471e46c --- /dev/null +++ b/ProjectManager/DataAccess/Migrations/20231101124242_Initial.cs @@ -0,0 +1,62 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DataAccess.Migrations +{ + /// + public partial class Initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Projects", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Projects", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + ProjectId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + table.ForeignKey( + name: "FK_Users_Projects_ProjectId", + column: x => x.ProjectId, + principalTable: "Projects", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Users_ProjectId", + table: "Users", + column: "ProjectId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Users"); + + migrationBuilder.DropTable( + name: "Projects"); + } + } +} diff --git a/ProjectManager/DataAccess/Migrations/ProjectContextModelSnapshot.cs b/ProjectManager/DataAccess/Migrations/ProjectContextModelSnapshot.cs new file mode 100644 index 0000000..8baf5ed --- /dev/null +++ b/ProjectManager/DataAccess/Migrations/ProjectContextModelSnapshot.cs @@ -0,0 +1,81 @@ +// +using DataAccess; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DataAccess.Migrations +{ + [DbContext(typeof(ProjectContext))] + partial class ProjectContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.13") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DataAccess.Project", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Projects"); + }); + + modelBuilder.Entity("DataAccess.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ProjectId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ProjectId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("DataAccess.User", b => + { + b.HasOne("DataAccess.Project", "Project") + .WithMany("Users") + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Project"); + }); + + modelBuilder.Entity("DataAccess.Project", b => + { + b.Navigation("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ProjectManager/DataAccess/Program.cs b/ProjectManager/DataAccess/Program.cs new file mode 100644 index 0000000..3751555 --- /dev/null +++ b/ProjectManager/DataAccess/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/ProjectManager/DataAccess/Project.cs b/ProjectManager/DataAccess/Project.cs new file mode 100644 index 0000000..2f2b6a8 --- /dev/null +++ b/ProjectManager/DataAccess/Project.cs @@ -0,0 +1,12 @@ +namespace DataAccess +{ + public class Project + { + public int Id { get; set; } + + public string Name { get; set; } = null!; + + public List Users { get; set; } = null!; + + } +} \ No newline at end of file diff --git a/ProjectManager/DataAccess/ProjectContext.cs b/ProjectManager/DataAccess/ProjectContext.cs new file mode 100644 index 0000000..f9a4452 --- /dev/null +++ b/ProjectManager/DataAccess/ProjectContext.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Data.Common; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; + +namespace DataAccess +{ + public class ProjectContext : DbContext + { + public ProjectContext() { + } + + public ProjectContext(DbContextOptions options) : base(options) + { + } + + public DbSet Users { get; set; } = null!; + + public DbSet Projects { get; set; } = null!; + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseSqlServer(@"Server=.\SQLEXPRESS;Database=ProjectManagerDb;Trusted_Connection=True; Encrypt=False"); + } + + + } +} diff --git a/ProjectManager/DataAccess/User.cs b/ProjectManager/DataAccess/User.cs new file mode 100644 index 0000000..7010525 --- /dev/null +++ b/ProjectManager/DataAccess/User.cs @@ -0,0 +1,11 @@ +namespace DataAccess; + +public class User +{ + public int Id { get; set; } + + public string Name { get; set; } = null!; + + public Project Project { get; set; } = null!; + +} \ No newline at end of file diff --git a/ProjectManager/ProjectManager.sln b/ProjectManager/ProjectManager.sln new file mode 100644 index 0000000..dddd9fe --- /dev/null +++ b/ProjectManager/ProjectManager.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34031.279 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataAccess", "DataAccess\DataAccess.csproj", "{F9CACECC-803B-4703-93C4-D0AF78A97756}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F9CACECC-803B-4703-93C4-D0AF78A97756}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F9CACECC-803B-4703-93C4-D0AF78A97756}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F9CACECC-803B-4703-93C4-D0AF78A97756}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F9CACECC-803B-4703-93C4-D0AF78A97756}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {54456466-88A5-45F3-87CA-F9BEF5667958} + EndGlobalSection +EndGlobal