Skip to content
Snippets Groups Projects
Commit 8a722798 authored by Enzo Santangelo Dodera's avatar Enzo Santangelo Dodera
Browse files

Merge branch 'feature/activities' into 'develop'

Feature/activities

See merge request !32
parents 399f38e7 a87c53fd
No related branches found
No related tags found
1 merge request!32Feature/activities
Pipeline #10475 passed
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Text;
using Tsi1.DataLayer.Entities;
namespace Tsi1.DataLayer.EntityConfiguration
{
public class ActivityConfiguration : IEntityTypeConfiguration<Activity>
{
public void Configure(EntityTypeBuilder<Activity> builder)
{
builder.HasKey(x => x.Id);
builder.Property(x => x.Name)
.IsRequired()
.HasColumnType("character varying(50)");
builder.HasOne(x => x.Course)
.WithMany(x => x.Activities)
.HasForeignKey(x => x.CourseId);
}
}
}
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Text;
using Tsi1.DataLayer.Entities;
namespace Tsi1.DataLayer.EntityConfiguration
{
public class AttendanceConfiguration : IEntityTypeConfiguration<Attendance>
{
public void Configure(EntityTypeBuilder<Attendance> builder)
{
builder.HasKey(x => x.Id);
builder.HasOne(x => x.User)
.WithMany(x => x.Attendances)
.HasForeignKey(x => x.UserId);
builder.HasOne(x => x.Activity)
.WithMany(x => x.Attendances)
.HasForeignKey(x => x.ActivityId);
}
}
}
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Tsi1.DataLayer.Migrations
{
public partial class addactivityattendanceentities : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Activities",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "character varying(50)", nullable: false),
IsVideoConference = table.Column<bool>(nullable: false),
CourseId = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Activities", x => x.Id);
table.ForeignKey(
name: "FK_Activities_Courses_CourseId",
column: x => x.CourseId,
principalTable: "Courses",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Attendances",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Date = table.Column<DateTime>(nullable: false),
UserId = table.Column<int>(nullable: false),
ActivityId = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Attendances", x => x.Id);
table.ForeignKey(
name: "FK_Attendances_Activities_ActivityId",
column: x => x.ActivityId,
principalTable: "Activities",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Attendances_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Activities_CourseId",
table: "Activities",
column: "CourseId");
migrationBuilder.CreateIndex(
name: "IX_Attendances_ActivityId",
table: "Attendances",
column: "ActivityId");
migrationBuilder.CreateIndex(
name: "IX_Attendances_UserId",
table: "Attendances",
column: "UserId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Attendances");
migrationBuilder.DropTable(
name: "Activities");
}
}
}
......@@ -19,6 +19,30 @@ namespace Tsi1.DataLayer.Migrations
.HasAnnotation("ProductVersion", "3.1.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
modelBuilder.Entity("Tsi1.DataLayer.Entities.Activity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("CourseId")
.HasColumnType("integer");
b.Property<bool>("IsVideoConference")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("character varying(50)");
b.HasKey("Id");
b.HasIndex("CourseId");
b.ToTable("Activities");
});
modelBuilder.Entity("Tsi1.DataLayer.Entities.AnswerOption", b =>
{
b.Property<int>("Id")
......@@ -37,6 +61,31 @@ namespace Tsi1.DataLayer.Migrations
b.ToTable("AnswerOptions");
});
modelBuilder.Entity("Tsi1.DataLayer.Entities.Attendance", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int>("ActivityId")
.HasColumnType("integer");
b.Property<DateTime>("Date")
.HasColumnType("timestamp without time zone");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ActivityId");
b.HasIndex("UserId");
b.ToTable("Attendances");
});
modelBuilder.Entity("Tsi1.DataLayer.Entities.Communication", b =>
{
b.Property<int>("Id")
......@@ -594,6 +643,30 @@ namespace Tsi1.DataLayer.Migrations
b.ToTable("UserTypes");
});
modelBuilder.Entity("Tsi1.DataLayer.Entities.Activity", b =>
{
b.HasOne("Tsi1.DataLayer.Entities.Course", "Course")
.WithMany("Activities")
.HasForeignKey("CourseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Tsi1.DataLayer.Entities.Attendance", b =>
{
b.HasOne("Tsi1.DataLayer.Entities.Activity", "Activity")
.WithMany("Attendances")
.HasForeignKey("ActivityId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Tsi1.DataLayer.Entities.User", "User")
.WithMany("Attendances")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Tsi1.DataLayer.Entities.Communication", b =>
{
b.HasOne("Tsi1.DataLayer.Entities.Course", "Course")
......
......@@ -32,8 +32,9 @@ namespace Tsi1.DataLayer
public DbSet<SurveyQuestion> SurveyQuestions { get; set; }
public DbSet<SurveyResponse> SurveyResponses { get; set; }
public DbSet<AnswerOption> AnswerOptions { get; set; }
public DbSet<Communication> Communications { get; set; }
public DbSet<Activity> Activities { get; set; }
public DbSet<Attendance> Attendances { get; set; }
......@@ -65,6 +66,8 @@ namespace Tsi1.DataLayer
modelBuilder.ApplyConfiguration(new SurveyResponseConfiguration());
modelBuilder.ApplyConfiguration(new AnswerOptionConfiguration());
modelBuilder.ApplyConfiguration(new CommunicationConfiguration());
modelBuilder.ApplyConfiguration(new ActivityConfiguration());
modelBuilder.ApplyConfiguration(new AttendanceConfiguration());
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment