From b4b81355c1daf2fa2ef7166c2b2baa68bcf01b1a Mon Sep 17 00:00:00 2001 From: AleksDw Date: Sun, 27 Apr 2025 00:40:34 +0200 Subject: [PATCH] CreateDatabase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nic nie działa bo wszystko jest inne XDD --- WebApp/Controllers/EventsController.cs | 2 +- WebApp/Data/ApplicationDbContext.cs | 24 +- WebApp/Entities/Event.cs | 12 +- WebApp/Entities/EventRegistration.cs | 11 + WebApp/Entities/EventSkill.cs | 11 + WebApp/Entities/Organisation.cs | 14 + WebApp/Entities/Skill.cs | 11 + WebApp/Entities/User.cs | 15 + WebApp/Entities/VolunteerSkill.cs | 11 + ..._EventSkillsUsersOrganisations.Designer.cs | 526 ++++++++++++++++++ ...426222859_EventSkillsUsersOrganisations.cs | 279 ++++++++++ .../ApplicationDbContextModelSnapshot.cs | 370 +++++++++--- WebApp/Views/Events/Create.cshtml | 18 +- WebApp/Views/Home/Index.cshtml | 8 +- WebApp/WebApp.csproj | 2 + 15 files changed, 1218 insertions(+), 96 deletions(-) create mode 100644 WebApp/Entities/EventRegistration.cs create mode 100644 WebApp/Entities/EventSkill.cs create mode 100644 WebApp/Entities/Organisation.cs create mode 100644 WebApp/Entities/Skill.cs create mode 100644 WebApp/Entities/User.cs create mode 100644 WebApp/Entities/VolunteerSkill.cs create mode 100644 WebApp/Migrations/20250426222859_EventSkillsUsersOrganisations.Designer.cs create mode 100644 WebApp/Migrations/20250426222859_EventSkillsUsersOrganisations.cs diff --git a/WebApp/Controllers/EventsController.cs b/WebApp/Controllers/EventsController.cs index fac7ce6..1672365 100644 --- a/WebApp/Controllers/EventsController.cs +++ b/WebApp/Controllers/EventsController.cs @@ -24,7 +24,7 @@ namespace WebApp.Controllers { if (ModelState.IsValid) { - ev.Date = DateTime.SpecifyKind(ev.Date, DateTimeKind.Utc); + ev.EventDate = DateTime.SpecifyKind(ev.EventDate, DateTimeKind.Utc); _context.Events.Add(ev); await _context.SaveChangesAsync(); diff --git a/WebApp/Data/ApplicationDbContext.cs b/WebApp/Data/ApplicationDbContext.cs index e9c3dd9..f1da3ab 100644 --- a/WebApp/Data/ApplicationDbContext.cs +++ b/WebApp/Data/ApplicationDbContext.cs @@ -1,17 +1,37 @@ -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using WebApp.Entities; namespace WebApp.Data { - public class ApplicationDbContext : IdentityDbContext + public class ApplicationDbContext : IdentityDbContext, string> { public ApplicationDbContext(DbContextOptions options) : base(options) { } + public DbSet Organisations => Set(); public DbSet Events => Set(); + public DbSet Skills => Set(); + public DbSet VolunteerSkills => Set(); + public DbSet EventSkills => Set(); + public DbSet EventRegistrations => Set(); + protected override void OnModelCreating(ModelBuilder builder) + { + base.OnModelCreating(builder); + + // Compose keys + builder.Entity() + .HasKey(vs => new { vs.UserId, vs.SkillId }); + + builder.Entity() + .HasKey(es => new { es.EventId, es.SkillId }); + + builder.Entity() + .HasKey(er => new { er.UserId, er.EventId }); + } } } diff --git a/WebApp/Entities/Event.cs b/WebApp/Entities/Event.cs index dd69b0a..402d0f3 100644 --- a/WebApp/Entities/Event.cs +++ b/WebApp/Entities/Event.cs @@ -2,11 +2,15 @@ { public class Event { - public int Id { get; set; } - public required string Name { get; set; } - public required string Place { get; set; } + public int EventId { get; set; } + public int OrganisationId { get; set; } + public required string Title { get; set; } public string? Description { get; set; } - public required DateTime Date { get; set; } + public required string Location { get; set; } + public required DateTime EventDate { get; set; } + public Organisation? Organisation { get; set; } + public ICollection EventSkills { get; set; } = new List(); + public ICollection EventRegistrations { get; set; } = new List(); } } diff --git a/WebApp/Entities/EventRegistration.cs b/WebApp/Entities/EventRegistration.cs new file mode 100644 index 0000000..6ade633 --- /dev/null +++ b/WebApp/Entities/EventRegistration.cs @@ -0,0 +1,11 @@ +namespace WebApp.Entities +{ + public class EventRegistration + { + public int EventId { get; set; } + public required string UserId { get; set; } + public DateTime RegisteredAt { get; set; } = DateTime.UtcNow; + public Event? Event { get; set; } + public User? User { get; set; } + } +} diff --git a/WebApp/Entities/EventSkill.cs b/WebApp/Entities/EventSkill.cs new file mode 100644 index 0000000..ffdf722 --- /dev/null +++ b/WebApp/Entities/EventSkill.cs @@ -0,0 +1,11 @@ +namespace WebApp.Entities +{ + public class EventSkill + { + public int EventId { get; set; } + public int SkillId { get; set; } + + public Event? Event { get; set; } + public Skill? Skill { get; set; } + } +} diff --git a/WebApp/Entities/Organisation.cs b/WebApp/Entities/Organisation.cs new file mode 100644 index 0000000..36804a0 --- /dev/null +++ b/WebApp/Entities/Organisation.cs @@ -0,0 +1,14 @@ +namespace WebApp.Entities +{ + public class Organisation + { + public int OrganisationId { get; set; } + public required string UserId { get; set; } + public required string Name { get; set; } + public string? Description { get; set; } + public string? Website { get; set; } + + public User? User { get; set; } + public ICollection Events { get; set; } = new List(); + } +} diff --git a/WebApp/Entities/Skill.cs b/WebApp/Entities/Skill.cs new file mode 100644 index 0000000..4827119 --- /dev/null +++ b/WebApp/Entities/Skill.cs @@ -0,0 +1,11 @@ +namespace WebApp.Entities +{ + public class Skill + { + public int SkillId { get; set; } + public required string Name { get; set; } + + public ICollection VolunteerSkills { get; set; } = new List(); + public ICollection EventSkills { get; set; } = new List(); + } +} diff --git a/WebApp/Entities/User.cs b/WebApp/Entities/User.cs new file mode 100644 index 0000000..75b84dd --- /dev/null +++ b/WebApp/Entities/User.cs @@ -0,0 +1,15 @@ +using Microsoft.AspNetCore.Identity; + +namespace WebApp.Entities +{ + public class User : IdentityUser + { + public required string FirstName { get; set; } + public required string LastName { get; set; } + public bool IsOrganisation { get; set; } = false; + public DateTime CreatedAt { get; set; } = DateTime.UtcNow; + + public ICollection VolunteerSkills { get; set; } = new List(); + public ICollection EventRegistrations { get; set; } = new List(); + } +} diff --git a/WebApp/Entities/VolunteerSkill.cs b/WebApp/Entities/VolunteerSkill.cs new file mode 100644 index 0000000..5e05366 --- /dev/null +++ b/WebApp/Entities/VolunteerSkill.cs @@ -0,0 +1,11 @@ +namespace WebApp.Entities +{ + public class VolunteerSkill + { + public required string UserId { get; set; } + public int SkillId { get; set; } + + public User? User { get; set; } + public Skill? Skill { get; set; } + } +} diff --git a/WebApp/Migrations/20250426222859_EventSkillsUsersOrganisations.Designer.cs b/WebApp/Migrations/20250426222859_EventSkillsUsersOrganisations.Designer.cs new file mode 100644 index 0000000..8e69632 --- /dev/null +++ b/WebApp/Migrations/20250426222859_EventSkillsUsersOrganisations.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("20250426222859_EventSkillsUsersOrganisations")] + partial class EventSkillsUsersOrganisations + { + /// + 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/20250426222859_EventSkillsUsersOrganisations.cs b/WebApp/Migrations/20250426222859_EventSkillsUsersOrganisations.cs new file mode 100644 index 0000000..de4de70 --- /dev/null +++ b/WebApp/Migrations/20250426222859_EventSkillsUsersOrganisations.cs @@ -0,0 +1,279 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace WebApp.Migrations +{ + /// + public partial class EventSkillsUsersOrganisations : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "Place", + table: "Events", + newName: "Location"); + + migrationBuilder.RenameColumn( + name: "Name", + table: "Events", + newName: "Title"); + + migrationBuilder.RenameColumn( + name: "Date", + table: "Events", + newName: "EventDate"); + + migrationBuilder.RenameColumn( + name: "Id", + table: "Events", + newName: "EventId"); + + migrationBuilder.AddColumn( + name: "OrganisationId", + table: "Events", + type: "integer", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "CreatedAt", + table: "AspNetUsers", + type: "timestamp with time zone", + nullable: false, + defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); + + migrationBuilder.AddColumn( + name: "FirstName", + table: "AspNetUsers", + type: "text", + nullable: false, + defaultValue: ""); + + migrationBuilder.AddColumn( + name: "IsOrganisation", + table: "AspNetUsers", + type: "boolean", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "LastName", + table: "AspNetUsers", + type: "text", + nullable: false, + defaultValue: ""); + + migrationBuilder.CreateTable( + name: "EventRegistrations", + columns: table => new + { + EventId = table.Column(type: "integer", nullable: false), + UserId = table.Column(type: "text", nullable: false), + RegisteredAt = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_EventRegistrations", x => new { x.UserId, x.EventId }); + table.ForeignKey( + name: "FK_EventRegistrations_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_EventRegistrations_Events_EventId", + column: x => x.EventId, + principalTable: "Events", + principalColumn: "EventId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Organisations", + columns: table => new + { + OrganisationId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + UserId = table.Column(type: "text", nullable: false), + Name = table.Column(type: "text", nullable: false), + Description = table.Column(type: "text", nullable: true), + Website = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Organisations", x => x.OrganisationId); + table.ForeignKey( + name: "FK_Organisations_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Skills", + columns: table => new + { + SkillId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Skills", x => x.SkillId); + }); + + migrationBuilder.CreateTable( + name: "EventSkills", + columns: table => new + { + EventId = table.Column(type: "integer", nullable: false), + SkillId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_EventSkills", x => new { x.EventId, x.SkillId }); + table.ForeignKey( + name: "FK_EventSkills_Events_EventId", + column: x => x.EventId, + principalTable: "Events", + principalColumn: "EventId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_EventSkills_Skills_SkillId", + column: x => x.SkillId, + principalTable: "Skills", + principalColumn: "SkillId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "VolunteerSkills", + columns: table => new + { + UserId = table.Column(type: "text", nullable: false), + SkillId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_VolunteerSkills", x => new { x.UserId, x.SkillId }); + table.ForeignKey( + name: "FK_VolunteerSkills_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_VolunteerSkills_Skills_SkillId", + column: x => x.SkillId, + principalTable: "Skills", + principalColumn: "SkillId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Events_OrganisationId", + table: "Events", + column: "OrganisationId"); + + migrationBuilder.CreateIndex( + name: "IX_EventRegistrations_EventId", + table: "EventRegistrations", + column: "EventId"); + + migrationBuilder.CreateIndex( + name: "IX_EventSkills_SkillId", + table: "EventSkills", + column: "SkillId"); + + migrationBuilder.CreateIndex( + name: "IX_Organisations_UserId", + table: "Organisations", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_VolunteerSkills_SkillId", + table: "VolunteerSkills", + column: "SkillId"); + + migrationBuilder.AddForeignKey( + name: "FK_Events_Organisations_OrganisationId", + table: "Events", + column: "OrganisationId", + principalTable: "Organisations", + principalColumn: "OrganisationId", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Events_Organisations_OrganisationId", + table: "Events"); + + migrationBuilder.DropTable( + name: "EventRegistrations"); + + migrationBuilder.DropTable( + name: "EventSkills"); + + migrationBuilder.DropTable( + name: "Organisations"); + + migrationBuilder.DropTable( + name: "VolunteerSkills"); + + migrationBuilder.DropTable( + name: "Skills"); + + migrationBuilder.DropIndex( + name: "IX_Events_OrganisationId", + table: "Events"); + + migrationBuilder.DropColumn( + name: "OrganisationId", + table: "Events"); + + migrationBuilder.DropColumn( + name: "CreatedAt", + table: "AspNetUsers"); + + migrationBuilder.DropColumn( + name: "FirstName", + table: "AspNetUsers"); + + migrationBuilder.DropColumn( + name: "IsOrganisation", + table: "AspNetUsers"); + + migrationBuilder.DropColumn( + name: "LastName", + table: "AspNetUsers"); + + migrationBuilder.RenameColumn( + name: "Title", + table: "Events", + newName: "Name"); + + migrationBuilder.RenameColumn( + name: "Location", + table: "Events", + newName: "Place"); + + migrationBuilder.RenameColumn( + name: "EventDate", + table: "Events", + newName: "Date"); + + migrationBuilder.RenameColumn( + name: "EventId", + table: "Events", + newName: "Id"); + } + } +} diff --git a/WebApp/Migrations/ApplicationDbContextModelSnapshot.cs b/WebApp/Migrations/ApplicationDbContextModelSnapshot.cs index 6b3e940..46c574d 100644 --- a/WebApp/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/WebApp/Migrations/ApplicationDbContextModelSnapshot.cs @@ -22,7 +22,7 @@ namespace WebApp.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => { b.Property("Id") .HasColumnType("text"); @@ -73,70 +73,6 @@ namespace WebApp.Migrations b.ToTable("AspNetRoleClaims", (string)null); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => - { - b.Property("Id") - .HasColumnType("text"); - - b.Property("AccessFailedCount") - .HasColumnType("integer"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("boolean"); - - 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("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => { b.Property("Id") @@ -224,15 +160,77 @@ namespace WebApp.Migrations modelBuilder.Entity("WebApp.Entities.Event", b => { - b.Property("Id") + b.Property("EventId") .ValueGeneratedOnAdd() .HasColumnType("integer"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("EventId")); - b.Property("Date") + 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"); @@ -240,18 +238,133 @@ namespace WebApp.Migrations .IsRequired() .HasColumnType("text"); - b.Property("Place") + 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.ToTable("Events"); + 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) + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade) @@ -260,7 +373,7 @@ namespace WebApp.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + b.HasOne("WebApp.Entities.User", null) .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) @@ -269,7 +382,7 @@ namespace WebApp.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + b.HasOne("WebApp.Entities.User", null) .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) @@ -278,13 +391,13 @@ namespace WebApp.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + b.HasOne("WebApp.Entities.User", null) .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) @@ -293,12 +406,117 @@ namespace WebApp.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + 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/Views/Events/Create.cshtml b/WebApp/Views/Events/Create.cshtml index b5fef63..1798596 100644 --- a/WebApp/Views/Events/Create.cshtml +++ b/WebApp/Views/Events/Create.cshtml @@ -8,23 +8,23 @@
- - - + + +
- - - + + +
- - - + + +
diff --git a/WebApp/Views/Home/Index.cshtml b/WebApp/Views/Home/Index.cshtml index f1e0bda..3ec7be4 100644 --- a/WebApp/Views/Home/Index.cshtml +++ b/WebApp/Views/Home/Index.cshtml @@ -29,12 +29,12 @@ @foreach (var item in Model) { - @item.Name - @item.Place - @item.Date.ToString("yyyy-MM-dd HH:mm") + @item.Title + @item.Location + @item.EventDate.ToString("yyyy-MM-dd HH:mm")
- +
diff --git a/WebApp/WebApp.csproj b/WebApp/WebApp.csproj index 42a2d12..de1439a 100644 --- a/WebApp/WebApp.csproj +++ b/WebApp/WebApp.csproj @@ -25,4 +25,6 @@ + +