From 1083cfa3ffe8d7d53507615e97a1d65e0d4d3558 Mon Sep 17 00:00:00 2001 From: eee4 <41441600+eee4@users.noreply.github.com> Date: Mon, 28 Apr 2025 02:34:03 +0200 Subject: [PATCH] feat: use the new, revised database model --- WebApp/DTOs/EventsDto.cs | 16 +- .../20250428003000_ESUOrev2.Designer.cs | 526 ++++++++++++++++++ WebApp/Migrations/20250428003000_ESUOrev2.cs | 22 + WebApp/Program.cs | 3 +- WebApp/Views/Events/Create.cshtml | 5 + WebApp/Views/Home/Index.cshtml | 2 + WebApp/Views/Shared/_LoginPartial.cshtml | 5 +- 7 files changed, 570 insertions(+), 9 deletions(-) create mode 100644 WebApp/Migrations/20250428003000_ESUOrev2.Designer.cs create mode 100644 WebApp/Migrations/20250428003000_ESUOrev2.cs diff --git a/WebApp/DTOs/EventsDto.cs b/WebApp/DTOs/EventsDto.cs index e7110d6..e2dcec3 100644 --- a/WebApp/DTOs/EventsDto.cs +++ b/WebApp/DTOs/EventsDto.cs @@ -1,11 +1,15 @@ using System.ComponentModel.DataAnnotations; +using WebApp.Entities; namespace WebApp.DTOs; public record class EventsDto( - int Id, - int IdOrganisation, //foreign key - string Place, - [StringLength(200)] string Description, - DateTime Date + int EventId, + int OrganisationId, //foreign key + [StringLength(200)] string Title, + [StringLength(800)] string Description, + [StringLength(100)] string Location, + DateTime EventDate, + Organisation? Organisation, + ICollection EventSkills, + ICollection EventRegistrations ); - diff --git a/WebApp/Migrations/20250428003000_ESUOrev2.Designer.cs b/WebApp/Migrations/20250428003000_ESUOrev2.Designer.cs new file mode 100644 index 0000000..2bdb893 --- /dev/null +++ b/WebApp/Migrations/20250428003000_ESUOrev2.Designer.cs @@ -0,0 +1,526 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using WebApp.Data; + +#nullable disable + +namespace WebApp.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20250428003000_ESUOrev2")] + partial class ESUOrev2 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("ProviderKey") + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("text"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("LoginProvider") + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("Name") + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("WebApp.Entities.Event", b => + { + b.Property("EventId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("EventId")); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("EventDate") + .HasColumnType("timestamp with time zone"); + + b.Property("Location") + .IsRequired() + .HasColumnType("text"); + + b.Property("OrganisationId") + .HasColumnType("integer"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("EventId"); + + b.HasIndex("OrganisationId"); + + b.ToTable("Events"); + }); + + modelBuilder.Entity("WebApp.Entities.EventRegistration", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("EventId") + .HasColumnType("integer"); + + b.Property("RegisteredAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("UserId", "EventId"); + + b.HasIndex("EventId"); + + b.ToTable("EventRegistrations"); + }); + + modelBuilder.Entity("WebApp.Entities.EventSkill", b => + { + b.Property("EventId") + .HasColumnType("integer"); + + b.Property("SkillId") + .HasColumnType("integer"); + + b.HasKey("EventId", "SkillId"); + + b.HasIndex("SkillId"); + + b.ToTable("EventSkills"); + }); + + modelBuilder.Entity("WebApp.Entities.Organisation", b => + { + b.Property("OrganisationId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("OrganisationId")); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Website") + .HasColumnType("text"); + + b.HasKey("OrganisationId"); + + b.HasIndex("UserId"); + + b.ToTable("Organisations"); + }); + + modelBuilder.Entity("WebApp.Entities.Skill", b => + { + b.Property("SkillId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("SkillId")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("SkillId"); + + b.ToTable("Skills"); + }); + + modelBuilder.Entity("WebApp.Entities.User", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("IsOrganisation") + .HasColumnType("boolean"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("WebApp.Entities.VolunteerSkill", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("SkillId") + .HasColumnType("integer"); + + b.HasKey("UserId", "SkillId"); + + b.HasIndex("SkillId"); + + b.ToTable("VolunteerSkills"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("WebApp.Entities.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("WebApp.Entities.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("WebApp.Entities.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("WebApp.Entities.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("WebApp.Entities.Event", b => + { + b.HasOne("WebApp.Entities.Organisation", "Organisation") + .WithMany("Events") + .HasForeignKey("OrganisationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Organisation"); + }); + + modelBuilder.Entity("WebApp.Entities.EventRegistration", b => + { + b.HasOne("WebApp.Entities.Event", "Event") + .WithMany("EventRegistrations") + .HasForeignKey("EventId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("WebApp.Entities.User", "User") + .WithMany("EventRegistrations") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Event"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("WebApp.Entities.EventSkill", b => + { + b.HasOne("WebApp.Entities.Event", "Event") + .WithMany("EventSkills") + .HasForeignKey("EventId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("WebApp.Entities.Skill", "Skill") + .WithMany("EventSkills") + .HasForeignKey("SkillId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Event"); + + b.Navigation("Skill"); + }); + + modelBuilder.Entity("WebApp.Entities.Organisation", b => + { + b.HasOne("WebApp.Entities.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("WebApp.Entities.VolunteerSkill", b => + { + b.HasOne("WebApp.Entities.Skill", "Skill") + .WithMany("VolunteerSkills") + .HasForeignKey("SkillId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("WebApp.Entities.User", "User") + .WithMany("VolunteerSkills") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Skill"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("WebApp.Entities.Event", b => + { + b.Navigation("EventRegistrations"); + + b.Navigation("EventSkills"); + }); + + modelBuilder.Entity("WebApp.Entities.Organisation", b => + { + b.Navigation("Events"); + }); + + modelBuilder.Entity("WebApp.Entities.Skill", b => + { + b.Navigation("EventSkills"); + + b.Navigation("VolunteerSkills"); + }); + + modelBuilder.Entity("WebApp.Entities.User", b => + { + b.Navigation("EventRegistrations"); + + b.Navigation("VolunteerSkills"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WebApp/Migrations/20250428003000_ESUOrev2.cs b/WebApp/Migrations/20250428003000_ESUOrev2.cs new file mode 100644 index 0000000..6d6d278 --- /dev/null +++ b/WebApp/Migrations/20250428003000_ESUOrev2.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace WebApp.Migrations +{ + /// + public partial class ESUOrev2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/WebApp/Program.cs b/WebApp/Program.cs index acdb487..b02fc6c 100644 --- a/WebApp/Program.cs +++ b/WebApp/Program.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using WebApp.Data; +using WebApp.Entities; var builder = WebApplication.CreateBuilder(args); @@ -10,7 +11,7 @@ builder.Services.AddDbContext(options => options.UseNpgsql(connectionString)); builder.Services.AddDatabaseDeveloperPageExceptionFilter(); -builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) +builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) .AddEntityFrameworkStores(); builder.Services.AddControllersWithViews(); diff --git a/WebApp/Views/Events/Create.cshtml b/WebApp/Views/Events/Create.cshtml index 1798596..cc034d3 100644 --- a/WebApp/Views/Events/Create.cshtml +++ b/WebApp/Views/Events/Create.cshtml @@ -26,6 +26,11 @@ +
+ + + +
diff --git a/WebApp/Views/Home/Index.cshtml b/WebApp/Views/Home/Index.cshtml index 3ec7be4..5083205 100644 --- a/WebApp/Views/Home/Index.cshtml +++ b/WebApp/Views/Home/Index.cshtml @@ -22,6 +22,7 @@ Nazwa Miejsce Data + Organizacja Akcje @@ -32,6 +33,7 @@ @item.Title @item.Location @item.EventDate.ToString("yyyy-MM-dd HH:mm") + @item.OrganisationId
diff --git a/WebApp/Views/Shared/_LoginPartial.cshtml b/WebApp/Views/Shared/_LoginPartial.cshtml index 921dbe1..b7c731c 100644 --- a/WebApp/Views/Shared/_LoginPartial.cshtml +++ b/WebApp/Views/Shared/_LoginPartial.cshtml @@ -1,6 +1,7 @@ @using Microsoft.AspNetCore.Identity -@inject SignInManager SignInManager -@inject UserManager UserManager +@using WebApp.Entities +@inject SignInManager SignInManager +@inject UserManager UserManager