Merge pull request #2 from GCMatters/Database

feat: update database model
This commit is contained in:
2025-04-29 19:21:43 +02:00
committed by GitHub
20 changed files with 1788 additions and 105 deletions

View File

@@ -24,7 +24,7 @@ namespace WebApp.Controllers
{ {
if (ModelState.IsValid) if (ModelState.IsValid)
{ {
ev.Date = DateTime.SpecifyKind(ev.Date, DateTimeKind.Utc); ev.EventDate = DateTime.SpecifyKind(ev.EventDate, DateTimeKind.Utc);
_context.Events.Add(ev); _context.Events.Add(ev);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();

View File

@@ -1,11 +1,15 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using WebApp.Entities;
namespace WebApp.DTOs; namespace WebApp.DTOs;
public record class EventsDto( public record class EventsDto(
int Id, int EventId,
int IdOrganisation, //foreign key int OrganisationId, //foreign key
string Place, [StringLength(200)] string Title,
[StringLength(200)] string Description, [StringLength(800)] string Description,
DateTime Date [StringLength(100)] string Location,
DateTime EventDate,
Organisation? Organisation,
ICollection<EventSkill> EventSkills,
ICollection<EventRegistration> EventRegistrations
); );

View File

@@ -1,17 +1,37 @@
using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using WebApp.Entities; using WebApp.Entities;
namespace WebApp.Data namespace WebApp.Data
{ {
public class ApplicationDbContext : IdentityDbContext public class ApplicationDbContext : IdentityDbContext<User, IdentityRole<string>, string>
{ {
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options) : base(options)
{ {
} }
public DbSet<Organisation> Organisations => Set<Organisation>();
public DbSet<Event> Events => Set<Event>(); public DbSet<Event> Events => Set<Event>();
public DbSet<Skill> Skills => Set<Skill>();
public DbSet<VolunteerSkill> VolunteerSkills => Set<VolunteerSkill>();
public DbSet<EventSkill> EventSkills => Set<EventSkill>();
public DbSet<EventRegistration> EventRegistrations => Set<EventRegistration>();
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
// Compose keys
builder.Entity<VolunteerSkill>()
.HasKey(vs => new { vs.UserId, vs.SkillId });
builder.Entity<EventSkill>()
.HasKey(es => new { es.EventId, es.SkillId });
builder.Entity<EventRegistration>()
.HasKey(er => new { er.UserId, er.EventId });
}
} }
} }

View File

@@ -2,11 +2,15 @@
{ {
public class Event public class Event
{ {
public int Id { get; set; } public int EventId { get; set; }
public required string Name { get; set; } public int OrganisationId { get; set; }
public required string Place { get; set; } public required string Title { get; set; }
public string? Description { 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<EventSkill> EventSkills { get; set; } = new List<EventSkill>();
public ICollection<EventRegistration> EventRegistrations { get; set; } = new List<EventRegistration>();
} }
} }

View File

@@ -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; }
}
}

View File

@@ -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; }
}
}

View File

@@ -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<Event> Events { get; set; } = new List<Event>();
}
}

11
WebApp/Entities/Skill.cs Normal file
View File

@@ -0,0 +1,11 @@
namespace WebApp.Entities
{
public class Skill
{
public int SkillId { get; set; }
public required string Name { get; set; }
public ICollection<VolunteerSkill> VolunteerSkills { get; set; } = new List<VolunteerSkill>();
public ICollection<EventSkill> EventSkills { get; set; } = new List<EventSkill>();
}
}

15
WebApp/Entities/User.cs Normal file
View File

@@ -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<VolunteerSkill> VolunteerSkills { get; set; } = new List<VolunteerSkill>();
public ICollection<EventRegistration> EventRegistrations { get; set; } = new List<EventRegistration>();
}
}

View File

@@ -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; }
}
}

View File

@@ -0,0 +1,526 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<string>", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("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<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("ProviderKey")
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("Name")
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("WebApp.Entities.Event", b =>
{
b.Property<int>("EventId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("EventId"));
b.Property<string>("Description")
.HasColumnType("text");
b.Property<DateTime>("EventDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("Location")
.IsRequired()
.HasColumnType("text");
b.Property<int>("OrganisationId")
.HasColumnType("integer");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("EventId");
b.HasIndex("OrganisationId");
b.ToTable("Events");
});
modelBuilder.Entity("WebApp.Entities.EventRegistration", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<int>("EventId")
.HasColumnType("integer");
b.Property<DateTime>("RegisteredAt")
.HasColumnType("timestamp with time zone");
b.HasKey("UserId", "EventId");
b.HasIndex("EventId");
b.ToTable("EventRegistrations");
});
modelBuilder.Entity("WebApp.Entities.EventSkill", b =>
{
b.Property<int>("EventId")
.HasColumnType("integer");
b.Property<int>("SkillId")
.HasColumnType("integer");
b.HasKey("EventId", "SkillId");
b.HasIndex("SkillId");
b.ToTable("EventSkills");
});
modelBuilder.Entity("WebApp.Entities.Organisation", b =>
{
b.Property<int>("OrganisationId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("OrganisationId"));
b.Property<string>("Description")
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Website")
.HasColumnType("text");
b.HasKey("OrganisationId");
b.HasIndex("UserId");
b.ToTable("Organisations");
});
modelBuilder.Entity("WebApp.Entities.Skill", b =>
{
b.Property<int>("SkillId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("SkillId"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("SkillId");
b.ToTable("Skills");
});
modelBuilder.Entity("WebApp.Entities.User", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsOrganisation")
.HasColumnType("boolean");
b.Property<string>("LastName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("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<string>("UserId")
.HasColumnType("text");
b.Property<int>("SkillId")
.HasColumnType("integer");
b.HasKey("UserId", "SkillId");
b.HasIndex("SkillId");
b.ToTable("VolunteerSkills");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole<string>", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("WebApp.Entities.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("WebApp.Entities.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole<string>", 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<string>", 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
}
}
}

View File

@@ -0,0 +1,279 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace WebApp.Migrations
{
/// <inheritdoc />
public partial class EventSkillsUsersOrganisations : Migration
{
/// <inheritdoc />
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<int>(
name: "OrganisationId",
table: "Events",
type: "integer",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<DateTime>(
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<string>(
name: "FirstName",
table: "AspNetUsers",
type: "text",
nullable: false,
defaultValue: "");
migrationBuilder.AddColumn<bool>(
name: "IsOrganisation",
table: "AspNetUsers",
type: "boolean",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<string>(
name: "LastName",
table: "AspNetUsers",
type: "text",
nullable: false,
defaultValue: "");
migrationBuilder.CreateTable(
name: "EventRegistrations",
columns: table => new
{
EventId = table.Column<int>(type: "integer", nullable: false),
UserId = table.Column<string>(type: "text", nullable: false),
RegisteredAt = table.Column<DateTime>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UserId = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "text", nullable: true),
Website = table.Column<string>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Skills", x => x.SkillId);
});
migrationBuilder.CreateTable(
name: "EventSkills",
columns: table => new
{
EventId = table.Column<int>(type: "integer", nullable: false),
SkillId = table.Column<int>(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<string>(type: "text", nullable: false),
SkillId = table.Column<int>(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);
}
/// <inheritdoc />
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");
}
}
}

View File

@@ -0,0 +1,526 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<string>", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("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<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("ProviderKey")
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("Name")
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("WebApp.Entities.Event", b =>
{
b.Property<int>("EventId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("EventId"));
b.Property<string>("Description")
.HasColumnType("text");
b.Property<DateTime>("EventDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("Location")
.IsRequired()
.HasColumnType("text");
b.Property<int>("OrganisationId")
.HasColumnType("integer");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("EventId");
b.HasIndex("OrganisationId");
b.ToTable("Events");
});
modelBuilder.Entity("WebApp.Entities.EventRegistration", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<int>("EventId")
.HasColumnType("integer");
b.Property<DateTime>("RegisteredAt")
.HasColumnType("timestamp with time zone");
b.HasKey("UserId", "EventId");
b.HasIndex("EventId");
b.ToTable("EventRegistrations");
});
modelBuilder.Entity("WebApp.Entities.EventSkill", b =>
{
b.Property<int>("EventId")
.HasColumnType("integer");
b.Property<int>("SkillId")
.HasColumnType("integer");
b.HasKey("EventId", "SkillId");
b.HasIndex("SkillId");
b.ToTable("EventSkills");
});
modelBuilder.Entity("WebApp.Entities.Organisation", b =>
{
b.Property<int>("OrganisationId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("OrganisationId"));
b.Property<string>("Description")
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Website")
.HasColumnType("text");
b.HasKey("OrganisationId");
b.HasIndex("UserId");
b.ToTable("Organisations");
});
modelBuilder.Entity("WebApp.Entities.Skill", b =>
{
b.Property<int>("SkillId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("SkillId"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("SkillId");
b.ToTable("Skills");
});
modelBuilder.Entity("WebApp.Entities.User", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsOrganisation")
.HasColumnType("boolean");
b.Property<string>("LastName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("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<string>("UserId")
.HasColumnType("text");
b.Property<int>("SkillId")
.HasColumnType("integer");
b.HasKey("UserId", "SkillId");
b.HasIndex("SkillId");
b.ToTable("VolunteerSkills");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole<string>", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("WebApp.Entities.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("WebApp.Entities.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole<string>", 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<string>", 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
}
}
}

View File

@@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace WebApp.Migrations
{
/// <inheritdoc />
public partial class ESUOrev2 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

View File

@@ -22,7 +22,7 @@ namespace WebApp.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole<string>", b =>
{ {
b.Property<string>("Id") b.Property<string>("Id")
.HasColumnType("text"); .HasColumnType("text");
@@ -73,70 +73,6 @@ namespace WebApp.Migrations
b.ToTable("AspNetRoleClaims", (string)null); b.ToTable("AspNetRoleClaims", (string)null);
}); });
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("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<string>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@@ -224,15 +160,77 @@ namespace WebApp.Migrations
modelBuilder.Entity("WebApp.Entities.Event", b => modelBuilder.Entity("WebApp.Entities.Event", b =>
{ {
b.Property<int>("Id") b.Property<int>("EventId")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("integer"); .HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("EventId"));
b.Property<DateTime>("Date") b.Property<string>("Description")
.HasColumnType("text");
b.Property<DateTime>("EventDate")
.HasColumnType("timestamp with time zone"); .HasColumnType("timestamp with time zone");
b.Property<string>("Location")
.IsRequired()
.HasColumnType("text");
b.Property<int>("OrganisationId")
.HasColumnType("integer");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("EventId");
b.HasIndex("OrganisationId");
b.ToTable("Events");
});
modelBuilder.Entity("WebApp.Entities.EventRegistration", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<int>("EventId")
.HasColumnType("integer");
b.Property<DateTime>("RegisteredAt")
.HasColumnType("timestamp with time zone");
b.HasKey("UserId", "EventId");
b.HasIndex("EventId");
b.ToTable("EventRegistrations");
});
modelBuilder.Entity("WebApp.Entities.EventSkill", b =>
{
b.Property<int>("EventId")
.HasColumnType("integer");
b.Property<int>("SkillId")
.HasColumnType("integer");
b.HasKey("EventId", "SkillId");
b.HasIndex("SkillId");
b.ToTable("EventSkills");
});
modelBuilder.Entity("WebApp.Entities.Organisation", b =>
{
b.Property<int>("OrganisationId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("OrganisationId"));
b.Property<string>("Description") b.Property<string>("Description")
.HasColumnType("text"); .HasColumnType("text");
@@ -240,18 +238,133 @@ namespace WebApp.Migrations
.IsRequired() .IsRequired()
.HasColumnType("text"); .HasColumnType("text");
b.Property<string>("Place") b.Property<string>("UserId")
.IsRequired() .IsRequired()
.HasColumnType("text"); .HasColumnType("text");
b.Property<string>("Website")
.HasColumnType("text");
b.HasKey("OrganisationId");
b.HasIndex("UserId");
b.ToTable("Organisations");
});
modelBuilder.Entity("WebApp.Entities.Skill", b =>
{
b.Property<int>("SkillId")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("SkillId"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("SkillId");
b.ToTable("Skills");
});
modelBuilder.Entity("WebApp.Entities.User", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsOrganisation")
.HasColumnType("boolean");
b.Property<string>("LastName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id"); 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<string>("UserId")
.HasColumnType("text");
b.Property<int>("SkillId")
.HasColumnType("integer");
b.HasKey("UserId", "SkillId");
b.HasIndex("SkillId");
b.ToTable("VolunteerSkills");
}); });
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{ {
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole<string>", null)
.WithMany() .WithMany()
.HasForeignKey("RoleId") .HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
@@ -260,7 +373,7 @@ namespace WebApp.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{ {
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) b.HasOne("WebApp.Entities.User", null)
.WithMany() .WithMany()
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
@@ -269,7 +382,7 @@ namespace WebApp.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{ {
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) b.HasOne("WebApp.Entities.User", null)
.WithMany() .WithMany()
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
@@ -278,13 +391,13 @@ namespace WebApp.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{ {
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole<string>", null)
.WithMany() .WithMany()
.HasForeignKey("RoleId") .HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) b.HasOne("WebApp.Entities.User", null)
.WithMany() .WithMany()
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
@@ -293,12 +406,117 @@ namespace WebApp.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{ {
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) b.HasOne("WebApp.Entities.User", null)
.WithMany() .WithMany()
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .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 #pragma warning restore 612, 618
} }
} }

View File

@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using WebApp.Data; using WebApp.Data;
using WebApp.Entities;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@@ -10,7 +11,7 @@ builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(connectionString)); options.UseNpgsql(connectionString));
builder.Services.AddDatabaseDeveloperPageExceptionFilter(); builder.Services.AddDatabaseDeveloperPageExceptionFilter();
builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true) builder.Services.AddDefaultIdentity<User>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>(); .AddEntityFrameworkStores<ApplicationDbContext>();
builder.Services.AddControllersWithViews(); builder.Services.AddControllersWithViews();

View File

@@ -8,23 +8,28 @@
<form asp-action="Create" method="post"> <form asp-action="Create" method="post">
<div class="form-group"> <div class="form-group">
<label asp-for="Name"></label> <label asp-for="Title"></label>
<input asp-for="Name" class="form-control" /> <input asp-for="Title" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span> <span asp-validation-for="Title" class="text-danger"></span>
</div> </div>
<div class="form-group"> <div class="form-group">
<label asp-for="Place"></label> <label asp-for="Location"></label>
<input asp-for="Place" class="form-control" /> <input asp-for="Location" class="form-control" />
<span asp-validation-for="Place" class="text-danger"></span> <span asp-validation-for="Location" class="text-danger"></span>
</div> </div>
<div class="form-group"> <div class="form-group">
<label asp-for="Description"></label> <label asp-for="Description"></label>
<textarea asp-for="Description" class="form-control"></textarea> <textarea asp-for="Description" class="form-control"></textarea>
</div> </div>
<div class="form-group"> <div class="form-group">
<label asp-for="Date"></label> <label asp-for="EventDate"></label>
<input asp-for="Date" type="datetime-local" class="form-control" /> <input asp-for="EventDate" type="datetime-local" class="form-control" />
<span asp-validation-for="Date" class="text-danger"></span> <span asp-validation-for="EventDate" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="OrganisationId">OrganisationId (for debugging purposes)</label>
<input asp-for="OrganisationId" class="form-control" />
<span asp-validation-for="OrganisationId" class="text-danger"></span>
</div> </div>
<button type="submit" class="btn btn-primary">Save</button> <button type="submit" class="btn btn-primary">Save</button>
</form> </form>

View File

@@ -22,6 +22,7 @@
<th>Nazwa</th> <th>Nazwa</th>
<th>Miejsce</th> <th>Miejsce</th>
<th>Data</th> <th>Data</th>
<th>Organizacja</th>
<th>Akcje</th> <th>Akcje</th>
</tr> </tr>
</thead> </thead>
@@ -29,12 +30,13 @@
@foreach (var item in Model) @foreach (var item in Model)
{ {
<tr> <tr>
<td>@item.Name</td> <td>@item.Title</td>
<td>@item.Place</td> <td>@item.Location</td>
<td>@item.Date.ToString("yyyy-MM-dd HH:mm")</td> <td>@item.EventDate.ToString("yyyy-MM-dd HH:mm")</td>
<td>@item.OrganisationId</td>
<td> <td>
<form asp-action="Delete" asp-controller="Events" method="post" style="display:inline;"> <form asp-action="Delete" asp-controller="Events" method="post" style="display:inline;">
<input type="hidden" name="id" value="@item.Id" /> <input type="hidden" name="id" value="@item.EventId" />
<button type="submit" class="btn btn-danger" onclick="return confirm('Na pewno chcesz usunąć to wydarzenie?')">Usuń</button> <button type="submit" class="btn btn-danger" onclick="return confirm('Na pewno chcesz usunąć to wydarzenie?')">Usuń</button>
</form> </form>
</td> </td>

View File

@@ -1,6 +1,7 @@
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@inject SignInManager<IdentityUser> SignInManager @using WebApp.Entities
@inject UserManager<IdentityUser> UserManager @inject SignInManager<User> SignInManager
@inject UserManager<User> UserManager
<ul class="navbar-nav"> <ul class="navbar-nav">
@if (SignInManager.IsSignedIn(User)) @if (SignInManager.IsSignedIn(User))

View File

@@ -25,4 +25,6 @@
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" /> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
</ItemGroup> </ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties appsettings_1json__JsonSchema="https://json.schemastore.org/abc-inventory-module-data-4.0.0.json" /></VisualStudio></ProjectExtensions>
</Project> </Project>