diff --git a/Tsi1.Api/Tsi1.BusinessLayer/DataLoad/DataLoad.cs b/Tsi1.Api/Tsi1.BusinessLayer/DataLoad/DataLoad.cs index ea09ddf721818c249411dcdc6219633d99d350ad..531c3ddb99ebef6b6e5483525ea8ef9a7855db45 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/DataLoad/DataLoad.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/DataLoad/DataLoad.cs @@ -258,6 +258,35 @@ namespace Tsi1.BusinessLayer.DataLoad } }; await _sectionItemService.Create(sectionItem4); + + // ANSWER OPTIONS + var answerOptions = new List<AnswerOption> + { + new AnswerOption + { + Name = "Excelente" + }, + new AnswerOption + { + Name = "Conforme" + }, + new AnswerOption + { + Name = "Neutro" + }, + new AnswerOption + { + Name = "No Conforme" + }, + new AnswerOption + { + Name = "Mal" + }, + }; + + _context.AnswerOptions.AddRange(answerOptions); + await _context.SaveChangesAsync(); + } } } \ No newline at end of file diff --git a/Tsi1.Api/Tsi1.DataLayer/Entities/AnswerOption.cs b/Tsi1.Api/Tsi1.DataLayer/Entities/AnswerOption.cs new file mode 100644 index 0000000000000000000000000000000000000000..bf05fa1f904e6cabe57457c029ec4b82c923924c --- /dev/null +++ b/Tsi1.Api/Tsi1.DataLayer/Entities/AnswerOption.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tsi1.DataLayer.Entities +{ + public class AnswerOption + { + public AnswerOption() + { + SurveyAnswers = new HashSet<SurveyAnswer>(); + } + + public int Id { get; set; } + public string Name { get; set; } + + public ICollection<SurveyAnswer> SurveyAnswers { get; set; } + } +} diff --git a/Tsi1.Api/Tsi1.DataLayer/Entities/SectionItem.cs b/Tsi1.Api/Tsi1.DataLayer/Entities/SectionItem.cs index 3bd1ea22fc82fb58c6cc1015adeeae598bc64c67..f42b25859f23d392b954868de6e9059b5cc3356b 100644 --- a/Tsi1.Api/Tsi1.DataLayer/Entities/SectionItem.cs +++ b/Tsi1.Api/Tsi1.DataLayer/Entities/SectionItem.cs @@ -13,9 +13,13 @@ namespace Tsi1.DataLayer.Entities public int? ForumId { get; set; } public int? FileId { get; set; } + public int? SurveyId { get; set; } + public Section Section { get; set; } public SectionItemType SectionItemType { get; set; } public Forum Forum { get; set; } public File File { get; set; } + + public Survey Survey { get; set; } } } diff --git a/Tsi1.Api/Tsi1.DataLayer/Entities/Survey.cs b/Tsi1.Api/Tsi1.DataLayer/Entities/Survey.cs new file mode 100644 index 0000000000000000000000000000000000000000..c36cdca0c731a41588317d955d657843237c0e92 --- /dev/null +++ b/Tsi1.Api/Tsi1.DataLayer/Entities/Survey.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tsi1.DataLayer.Entities +{ + public class Survey + { + public Survey() + { + SurveyQuestions = new HashSet<SurveyQuestion>(); + SurveyResponses = new HashSet<SurveyResponse>(); + } + public int Id { get; set; } + public string Name { get; set; } + public bool IsGlobal { get; set; } + public int TenantId { get; set; } + + public SectionItem SectionItem { get; set; } + public Tenant Tenant { get; set; } + + public ICollection<SurveyQuestion> SurveyQuestions { get; set; } + public ICollection<SurveyResponse> SurveyResponses { get; set; } + } +} diff --git a/Tsi1.Api/Tsi1.DataLayer/Entities/SurveyAnswer.cs b/Tsi1.Api/Tsi1.DataLayer/Entities/SurveyAnswer.cs new file mode 100644 index 0000000000000000000000000000000000000000..f7d573bd0fd37a269d4d18d7fe17695f2684d39a --- /dev/null +++ b/Tsi1.Api/Tsi1.DataLayer/Entities/SurveyAnswer.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tsi1.DataLayer.Entities +{ + public class SurveyAnswer + { + public int Id { get; set; } + public int AnswerOptionId { get; set; } + public int SurveyResponseId { get; set; } + public int SurveyQuestionId { get; set; } + + public AnswerOption AnswerOption { get; set; } + public SurveyResponse SurveyResponse { get; set; } + public SurveyQuestion SurveyQuestion { get; set; } + } +} diff --git a/Tsi1.Api/Tsi1.DataLayer/Entities/SurveyQuestion.cs b/Tsi1.Api/Tsi1.DataLayer/Entities/SurveyQuestion.cs new file mode 100644 index 0000000000000000000000000000000000000000..32769392e5a21636f11181be36fe3c3da4815045 --- /dev/null +++ b/Tsi1.Api/Tsi1.DataLayer/Entities/SurveyQuestion.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tsi1.DataLayer.Entities +{ + public class SurveyQuestion + { + public SurveyQuestion() + { + SurveyAnswers = new HashSet<SurveyAnswer>(); + } + + public int Id { get; set; } + public string Question { get; set; } + public int SurveyId { get; set; } + public Survey Survey { get; set; } + + public ICollection<SurveyAnswer> SurveyAnswers { get; set; } + + } +} diff --git a/Tsi1.Api/Tsi1.DataLayer/Entities/SurveyResponse.cs b/Tsi1.Api/Tsi1.DataLayer/Entities/SurveyResponse.cs new file mode 100644 index 0000000000000000000000000000000000000000..c5af9e970ca490d625d4cc482c9dd3716172fef7 --- /dev/null +++ b/Tsi1.Api/Tsi1.DataLayer/Entities/SurveyResponse.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tsi1.DataLayer.Entities +{ + public class SurveyResponse + { + public SurveyResponse() + { + SurveyAnswers = new HashSet<SurveyAnswer>(); + } + + public int Id { get; set; } + public int UserId { get; set; } + public int SurveyId { get; set; } + + public User User { get; set; } + public Survey Survey { get; set; } + public ICollection<SurveyAnswer> SurveyAnswers { get; set; } + } +} diff --git a/Tsi1.Api/Tsi1.DataLayer/Entities/Tenant.cs b/Tsi1.Api/Tsi1.DataLayer/Entities/Tenant.cs index ce807be9044482303da464874681b0f0b4814d67..0a153f83884dc7a09793b79647cb6dc174309b54 100644 --- a/Tsi1.Api/Tsi1.DataLayer/Entities/Tenant.cs +++ b/Tsi1.Api/Tsi1.DataLayer/Entities/Tenant.cs @@ -12,6 +12,7 @@ namespace Tsi1.DataLayer.Entities Professors = new HashSet<Professor>(); Students = new HashSet<Student>(); Users = new HashSet<User>(); + Surveys = new HashSet<Survey>(); } public int Id { get; set; } @@ -22,5 +23,6 @@ namespace Tsi1.DataLayer.Entities public ICollection<Professor> Professors { get; set; } public ICollection<Student> Students { get; set; } public ICollection<User> Users { get; set; } + public ICollection<Survey> Surveys { get; set; } } } diff --git a/Tsi1.Api/Tsi1.DataLayer/Entities/User.cs b/Tsi1.Api/Tsi1.DataLayer/Entities/User.cs index a62c4662edc5a781040ab78d454b33875ebb76d3..e3656322faa236d10a84b18c1fc4985cb240280d 100644 --- a/Tsi1.Api/Tsi1.DataLayer/Entities/User.cs +++ b/Tsi1.Api/Tsi1.DataLayer/Entities/User.cs @@ -11,6 +11,7 @@ namespace Tsi1.DataLayer.Entities Posts = new HashSet<Post>(); PostMessages = new HashSet<PostMessage>(); ForumUsers = new HashSet<ForumUser>(); + SurveyResponses = new HashSet<SurveyResponse>(); } public int Id { get; set; } @@ -41,5 +42,6 @@ namespace Tsi1.DataLayer.Entities public ICollection<Post> Posts { get; set; } public ICollection<PostMessage> PostMessages { get; set; } public ICollection<ForumUser> ForumUsers { get; set; } + public ICollection<SurveyResponse> SurveyResponses { get; set; } } } diff --git a/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/AnswerOptionConfiguration.cs b/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/AnswerOptionConfiguration.cs new file mode 100644 index 0000000000000000000000000000000000000000..e0ef2bbf59cffa846bf1e88b7e343da1c55a78ee --- /dev/null +++ b/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/AnswerOptionConfiguration.cs @@ -0,0 +1,23 @@ +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 AnswerOptionConfiguration : IEntityTypeConfiguration<AnswerOption> + { + public void Configure(EntityTypeBuilder<AnswerOption> builder) + { + builder.HasKey(x => x.Id); + + builder.HasIndex(x => x.Name); + + builder.Property(x => x.Name) + .IsRequired() + .HasColumnType("character varying(100)"); + } + } +} diff --git a/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/SectionItemConfiguration.cs b/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/SectionItemConfiguration.cs index ffcda8dfd6c0f26718219dd2e30e04fcd6a1db81..592b44415b20ebc4ec13287c82e07a252ded9b92 100644 --- a/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/SectionItemConfiguration.cs +++ b/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/SectionItemConfiguration.cs @@ -31,6 +31,10 @@ namespace Tsi1.DataLayer.EntityConfiguration builder.HasOne(x => x.Section) .WithMany(x => x.SectionItems) .HasForeignKey(x => x.SectionId); + + builder.HasOne(x => x.Survey) + .WithOne(x => x.SectionItem) + .HasForeignKey<SectionItem>(x => x.SurveyId); } } } diff --git a/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/SurveyAnswerConfiguration.cs b/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/SurveyAnswerConfiguration.cs new file mode 100644 index 0000000000000000000000000000000000000000..8b4f6739f8a13c3590f6494ff8a177441b95ef94 --- /dev/null +++ b/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/SurveyAnswerConfiguration.cs @@ -0,0 +1,29 @@ +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 SurveyAnswerConfiguration : IEntityTypeConfiguration<SurveyAnswer> + { + public void Configure(EntityTypeBuilder<SurveyAnswer> builder) + { + builder.HasKey(x => x.Id); + + builder.HasOne(x => x.AnswerOption) + .WithMany(x => x.SurveyAnswers) + .HasForeignKey(x => x.AnswerOptionId); + + builder.HasOne(x => x.SurveyResponse) + .WithMany(x => x.SurveyAnswers) + .HasForeignKey(x => x.SurveyResponseId); + + builder.HasOne(x => x.SurveyQuestion) + .WithMany(x => x.SurveyAnswers) + .HasForeignKey(x => x.SurveyQuestionId); + } + } +} diff --git a/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/SurveyConfiguration.cs b/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/SurveyConfiguration.cs new file mode 100644 index 0000000000000000000000000000000000000000..c7ded29ae2848583317ad28ca0b4830d56776540 --- /dev/null +++ b/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/SurveyConfiguration.cs @@ -0,0 +1,28 @@ +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 SurveyConfiguration : IEntityTypeConfiguration<Survey> + { + public void Configure(EntityTypeBuilder<Survey> builder) + { + builder.HasKey(x => x.Id); + + builder.HasIndex(x => x.Name); + + builder.Property(x => x.Name) + .IsRequired() + .HasColumnType("character varying(255)"); + + builder.HasOne(x => x.Tenant) + .WithMany(x => x.Surveys) + .HasForeignKey(x => x.TenantId); + + } + } +} diff --git a/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/SurveyQuestionConfiguration.cs b/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/SurveyQuestionConfiguration.cs new file mode 100644 index 0000000000000000000000000000000000000000..34fc8b49ae3de6e20a421fb47adc8fecdef054e1 --- /dev/null +++ b/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/SurveyQuestionConfiguration.cs @@ -0,0 +1,25 @@ +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 SurveyQuestionConfiguration : IEntityTypeConfiguration<SurveyQuestion> + { + public void Configure(EntityTypeBuilder<SurveyQuestion> builder) + { + builder.HasKey(x => x.Id); + + builder.Property(x => x.Question) + .IsRequired() + .HasColumnType("character varying(255)"); + + builder.HasOne(x => x.Survey) + .WithMany(x => x.SurveyQuestions) + .HasForeignKey(x => x.SurveyId); + } + } +} diff --git a/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/SurveyResponseConfiguration.cs b/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/SurveyResponseConfiguration.cs new file mode 100644 index 0000000000000000000000000000000000000000..b9ad0c750d5acff46cb6dbffd5b95f9c78d343f8 --- /dev/null +++ b/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/SurveyResponseConfiguration.cs @@ -0,0 +1,25 @@ +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 SurveyResponseConfiguration : IEntityTypeConfiguration<SurveyResponse> + { + public void Configure(EntityTypeBuilder<SurveyResponse> builder) + { + builder.HasKey(x => x.Id); + + builder.HasOne(x => x.User) + .WithMany(x => x.SurveyResponses) + .HasForeignKey(x => x.UserId); + + builder.HasOne(x => x.Survey) + .WithMany(x => x.SurveyResponses) + .HasForeignKey(x => x.SurveyId); + } + } +} diff --git a/Tsi1.Api/Tsi1.DataLayer/Migrations/20201108233000_add-survey-entities.Designer.cs b/Tsi1.Api/Tsi1.DataLayer/Migrations/20201108233000_add-survey-entities.Designer.cs new file mode 100644 index 0000000000000000000000000000000000000000..8e3d4e0be10bfcc9a7f8e9e7429ae05f8022d492 --- /dev/null +++ b/Tsi1.Api/Tsi1.DataLayer/Migrations/20201108233000_add-survey-entities.Designer.cs @@ -0,0 +1,786 @@ +// <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 Tsi1.DataLayer; + +namespace Tsi1.DataLayer.Migrations +{ + [DbContext(typeof(Tsi1Context))] + [Migration("20201108233000_add-survey-entities")] + partial class addsurveyentities + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) + .HasAnnotation("ProductVersion", "3.1.4") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.AnswerOption", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<string>("Name") + .IsRequired() + .HasColumnType("character varying(100)"); + + b.HasKey("Id"); + + b.HasIndex("Name"); + + b.ToTable("AnswerOptions"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.Connection", b => + { + b.Property<string>("ConnectionId") + .HasColumnType("text"); + + b.Property<string>("GroupName") + .HasColumnType("text"); + + b.Property<int>("UserId") + .HasColumnType("integer"); + + b.HasKey("ConnectionId"); + + b.HasIndex("GroupName"); + + b.ToTable("Connections"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.Course", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<string>("Name") + .IsRequired() + .HasColumnType("character varying(50)"); + + b.Property<int>("TenantId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("TenantId"); + + b.HasIndex("Name", "TenantId") + .IsUnique(); + + b.ToTable("Courses"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.File", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<string>("Name") + .IsRequired() + .HasColumnType("character varying(50)"); + + b.Property<string>("Path") + .IsRequired() + .HasColumnType("character varying(1000)"); + + b.HasKey("Id"); + + b.HasIndex("Path") + .IsUnique(); + + b.ToTable("Files"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.Forum", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<string>("Name") + .IsRequired() + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.ToTable("Forums"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.ForumUser", b => + { + b.Property<int>("ForumId") + .HasColumnType("integer"); + + b.Property<int>("UserId") + .HasColumnType("integer"); + + b.HasKey("ForumId", "UserId"); + + b.HasIndex("UserId"); + + b.ToTable("ForumUsers"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.Group", b => + { + b.Property<string>("Name") + .HasColumnType("text"); + + b.HasKey("Name"); + + b.ToTable("Groups"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.Post", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<DateTime>("Date") + .HasColumnType("timestamp without time zone"); + + b.Property<int>("ForumId") + .HasColumnType("integer"); + + b.Property<string>("Title") + .IsRequired() + .HasColumnType("character varying(100)"); + + b.Property<int>("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.HasIndex("ForumId", "Title") + .IsUnique(); + + b.ToTable("Posts"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.PostMessage", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<string>("Content") + .IsRequired() + .HasColumnType("character varying(10485760)"); + + b.Property<DateTime>("Date") + .HasColumnType("timestamp without time zone"); + + b.Property<int>("PostId") + .HasColumnType("integer"); + + b.Property<int>("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("PostId"); + + b.HasIndex("UserId"); + + b.ToTable("PostMessages"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.Professor", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<string>("IdentityCard") + .IsRequired() + .HasColumnType("character varying(50)"); + + b.Property<int>("TenantId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("TenantId"); + + b.HasIndex("IdentityCard", "TenantId") + .IsUnique(); + + b.ToTable("Professors"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.ProfessorCourse", b => + { + b.Property<int>("ProfessorId") + .HasColumnType("integer"); + + b.Property<int>("CourseId") + .HasColumnType("integer"); + + b.HasKey("ProfessorId", "CourseId"); + + b.HasIndex("CourseId"); + + b.ToTable("ProfessorCourses"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.Section", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<int>("CourseId") + .HasColumnType("integer"); + + b.Property<string>("Name") + .IsRequired() + .HasColumnType("character varying(255)"); + + b.Property<int>("Order") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CourseId"); + + b.ToTable("Sections"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.SectionItem", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<int?>("FileId") + .HasColumnType("integer"); + + b.Property<int?>("ForumId") + .HasColumnType("integer"); + + b.Property<int>("Order") + .HasColumnType("integer"); + + b.Property<int>("SectionId") + .HasColumnType("integer"); + + b.Property<int>("SectionItemTypeId") + .HasColumnType("integer"); + + b.Property<int?>("SurveyId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("FileId") + .IsUnique(); + + b.HasIndex("ForumId") + .IsUnique(); + + b.HasIndex("SectionId"); + + b.HasIndex("SectionItemTypeId"); + + b.HasIndex("SurveyId") + .IsUnique(); + + b.ToTable("SectionItems"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.SectionItemType", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<string>("Name") + .IsRequired() + .HasColumnType("character varying(100)"); + + b.HasKey("Id"); + + b.ToTable("SectionItemTypes"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.Student", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<int>("Age") + .HasColumnType("integer"); + + b.Property<string>("IdentityCard") + .IsRequired() + .HasColumnType("character varying(50)"); + + b.Property<int>("TenantId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("TenantId"); + + b.HasIndex("IdentityCard", "TenantId") + .IsUnique(); + + b.ToTable("Students"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.StudentCourse", b => + { + b.Property<int>("StudentId") + .HasColumnType("integer"); + + b.Property<int>("CourseId") + .HasColumnType("integer"); + + b.HasKey("StudentId", "CourseId"); + + b.HasIndex("CourseId"); + + b.ToTable("StudentCourses"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.Survey", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<bool>("IsGlobal") + .HasColumnType("boolean"); + + b.Property<string>("Name") + .IsRequired() + .HasColumnType("character varying(255)"); + + b.Property<int>("TenantId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("Name"); + + b.HasIndex("TenantId"); + + b.ToTable("Surveys"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.SurveyAnswer", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<int>("AnswerOptionId") + .HasColumnType("integer"); + + b.Property<int>("SurveyQuestionId") + .HasColumnType("integer"); + + b.Property<int>("SurveyResponseId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("AnswerOptionId"); + + b.HasIndex("SurveyQuestionId"); + + b.HasIndex("SurveyResponseId"); + + b.ToTable("SurveyAnswers"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.SurveyQuestion", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<string>("Question") + .IsRequired() + .HasColumnType("character varying(255)"); + + b.Property<int>("SurveyId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("SurveyId"); + + b.ToTable("SurveyQuestions"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.SurveyResponse", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<int>("SurveyId") + .HasColumnType("integer"); + + b.Property<int>("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("SurveyId"); + + b.HasIndex("UserId"); + + b.ToTable("SurveyResponses"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.Tenant", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<string>("Name") + .IsRequired() + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("Tenants"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.User", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<string>("Email") + .IsRequired() + .HasColumnType("character varying(255)"); + + b.Property<string>("FirstName") + .IsRequired() + .HasColumnType("character varying(255)"); + + b.Property<string>("LastName") + .IsRequired() + .HasColumnType("character varying(255)"); + + b.Property<string>("Password") + .IsRequired() + .HasColumnType("character varying(255)"); + + b.Property<int?>("ProfessorId") + .HasColumnType("integer"); + + b.Property<int?>("StudentId") + .HasColumnType("integer"); + + b.Property<int>("TenantId") + .HasColumnType("integer"); + + b.Property<int>("UserTypeId") + .HasColumnType("integer"); + + b.Property<string>("Username") + .IsRequired() + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.HasIndex("ProfessorId") + .IsUnique(); + + b.HasIndex("StudentId") + .IsUnique(); + + b.HasIndex("TenantId"); + + b.HasIndex("UserTypeId"); + + b.HasIndex("Username", "TenantId") + .IsUnique(); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.UserType", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<string>("Name") + .IsRequired() + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("UserTypes"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.Connection", b => + { + b.HasOne("Tsi1.DataLayer.Entities.Group", "Group") + .WithMany("Connections") + .HasForeignKey("GroupName"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.Course", b => + { + b.HasOne("Tsi1.DataLayer.Entities.Tenant", "Tenant") + .WithMany("Courses") + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.ForumUser", b => + { + b.HasOne("Tsi1.DataLayer.Entities.Forum", "Forum") + .WithMany("ForumUsers") + .HasForeignKey("ForumId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Tsi1.DataLayer.Entities.User", "User") + .WithMany("ForumUsers") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.Post", b => + { + b.HasOne("Tsi1.DataLayer.Entities.Forum", "Forum") + .WithMany("Posts") + .HasForeignKey("ForumId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Tsi1.DataLayer.Entities.User", "User") + .WithMany("Posts") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.PostMessage", b => + { + b.HasOne("Tsi1.DataLayer.Entities.Post", "Post") + .WithMany("PostMessages") + .HasForeignKey("PostId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Tsi1.DataLayer.Entities.User", "User") + .WithMany("PostMessages") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.Professor", b => + { + b.HasOne("Tsi1.DataLayer.Entities.Tenant", "Tenant") + .WithMany("Professors") + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.ProfessorCourse", b => + { + b.HasOne("Tsi1.DataLayer.Entities.Course", "Course") + .WithMany("ProfessorCourses") + .HasForeignKey("CourseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Tsi1.DataLayer.Entities.Professor", "Professor") + .WithMany("ProfessorCourses") + .HasForeignKey("ProfessorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.Section", b => + { + b.HasOne("Tsi1.DataLayer.Entities.Course", "Course") + .WithMany("Sections") + .HasForeignKey("CourseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.SectionItem", b => + { + b.HasOne("Tsi1.DataLayer.Entities.File", "File") + .WithOne("SectionItem") + .HasForeignKey("Tsi1.DataLayer.Entities.SectionItem", "FileId"); + + b.HasOne("Tsi1.DataLayer.Entities.Forum", "Forum") + .WithOne("SectionItem") + .HasForeignKey("Tsi1.DataLayer.Entities.SectionItem", "ForumId"); + + b.HasOne("Tsi1.DataLayer.Entities.Section", "Section") + .WithMany("SectionItems") + .HasForeignKey("SectionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Tsi1.DataLayer.Entities.SectionItemType", "SectionItemType") + .WithMany("SectionItems") + .HasForeignKey("SectionItemTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Tsi1.DataLayer.Entities.Survey", "Survey") + .WithOne("SectionItem") + .HasForeignKey("Tsi1.DataLayer.Entities.SectionItem", "SurveyId"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.Student", b => + { + b.HasOne("Tsi1.DataLayer.Entities.Tenant", "Tenant") + .WithMany("Students") + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.StudentCourse", b => + { + b.HasOne("Tsi1.DataLayer.Entities.Course", "Course") + .WithMany("StudentCourses") + .HasForeignKey("CourseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Tsi1.DataLayer.Entities.Student", "Student") + .WithMany("StudentCourses") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.Survey", b => + { + b.HasOne("Tsi1.DataLayer.Entities.Tenant", "Tenant") + .WithMany("Surveys") + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.SurveyAnswer", b => + { + b.HasOne("Tsi1.DataLayer.Entities.AnswerOption", "AnswerOption") + .WithMany("SurveyAnswers") + .HasForeignKey("AnswerOptionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Tsi1.DataLayer.Entities.SurveyQuestion", "SurveyQuestion") + .WithMany("SurveyAnswers") + .HasForeignKey("SurveyQuestionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Tsi1.DataLayer.Entities.SurveyResponse", "SurveyResponse") + .WithMany("SurveyAnswers") + .HasForeignKey("SurveyResponseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.SurveyQuestion", b => + { + b.HasOne("Tsi1.DataLayer.Entities.Survey", "Survey") + .WithMany("SurveyQuestions") + .HasForeignKey("SurveyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.SurveyResponse", b => + { + b.HasOne("Tsi1.DataLayer.Entities.Survey", "Survey") + .WithMany("SurveyResponses") + .HasForeignKey("SurveyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Tsi1.DataLayer.Entities.User", "User") + .WithMany("SurveyResponses") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.User", b => + { + b.HasOne("Tsi1.DataLayer.Entities.Professor", "Professor") + .WithOne("User") + .HasForeignKey("Tsi1.DataLayer.Entities.User", "ProfessorId"); + + b.HasOne("Tsi1.DataLayer.Entities.Student", "Student") + .WithOne("User") + .HasForeignKey("Tsi1.DataLayer.Entities.User", "StudentId"); + + b.HasOne("Tsi1.DataLayer.Entities.Tenant", "Tenant") + .WithMany("Users") + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Tsi1.DataLayer.Entities.UserType", "UserType") + .WithMany() + .HasForeignKey("UserTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Tsi1.Api/Tsi1.DataLayer/Migrations/20201108233000_add-survey-entities.cs b/Tsi1.Api/Tsi1.DataLayer/Migrations/20201108233000_add-survey-entities.cs new file mode 100644 index 0000000000000000000000000000000000000000..9ec24a5d00e7bc9f7e894209671769346c8f6895 --- /dev/null +++ b/Tsi1.Api/Tsi1.DataLayer/Migrations/20201108233000_add-survey-entities.cs @@ -0,0 +1,218 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +namespace Tsi1.DataLayer.Migrations +{ + public partial class addsurveyentities : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn<int>( + name: "SurveyId", + table: "SectionItems", + nullable: true); + + migrationBuilder.CreateTable( + name: "AnswerOptions", + columns: table => new + { + Id = table.Column<int>(nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column<string>(type: "character varying(100)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AnswerOptions", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Surveys", + columns: table => new + { + Id = table.Column<int>(nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column<string>(type: "character varying(255)", nullable: false), + IsGlobal = table.Column<bool>(nullable: false), + TenantId = table.Column<int>(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Surveys", x => x.Id); + table.ForeignKey( + name: "FK_Surveys_Tenants_TenantId", + column: x => x.TenantId, + principalTable: "Tenants", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "SurveyQuestions", + columns: table => new + { + Id = table.Column<int>(nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Question = table.Column<string>(type: "character varying(255)", nullable: false), + SurveyId = table.Column<int>(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SurveyQuestions", x => x.Id); + table.ForeignKey( + name: "FK_SurveyQuestions_Surveys_SurveyId", + column: x => x.SurveyId, + principalTable: "Surveys", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "SurveyResponses", + columns: table => new + { + Id = table.Column<int>(nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + UserId = table.Column<int>(nullable: false), + SurveyId = table.Column<int>(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SurveyResponses", x => x.Id); + table.ForeignKey( + name: "FK_SurveyResponses_Surveys_SurveyId", + column: x => x.SurveyId, + principalTable: "Surveys", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_SurveyResponses_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "SurveyAnswers", + columns: table => new + { + Id = table.Column<int>(nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + AnswerOptionId = table.Column<int>(nullable: false), + SurveyResponseId = table.Column<int>(nullable: false), + SurveyQuestionId = table.Column<int>(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SurveyAnswers", x => x.Id); + table.ForeignKey( + name: "FK_SurveyAnswers_AnswerOptions_AnswerOptionId", + column: x => x.AnswerOptionId, + principalTable: "AnswerOptions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_SurveyAnswers_SurveyQuestions_SurveyQuestionId", + column: x => x.SurveyQuestionId, + principalTable: "SurveyQuestions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_SurveyAnswers_SurveyResponses_SurveyResponseId", + column: x => x.SurveyResponseId, + principalTable: "SurveyResponses", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_SectionItems_SurveyId", + table: "SectionItems", + column: "SurveyId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_AnswerOptions_Name", + table: "AnswerOptions", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_SurveyAnswers_AnswerOptionId", + table: "SurveyAnswers", + column: "AnswerOptionId"); + + migrationBuilder.CreateIndex( + name: "IX_SurveyAnswers_SurveyQuestionId", + table: "SurveyAnswers", + column: "SurveyQuestionId"); + + migrationBuilder.CreateIndex( + name: "IX_SurveyAnswers_SurveyResponseId", + table: "SurveyAnswers", + column: "SurveyResponseId"); + + migrationBuilder.CreateIndex( + name: "IX_SurveyQuestions_SurveyId", + table: "SurveyQuestions", + column: "SurveyId"); + + migrationBuilder.CreateIndex( + name: "IX_SurveyResponses_SurveyId", + table: "SurveyResponses", + column: "SurveyId"); + + migrationBuilder.CreateIndex( + name: "IX_SurveyResponses_UserId", + table: "SurveyResponses", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_Surveys_Name", + table: "Surveys", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_Surveys_TenantId", + table: "Surveys", + column: "TenantId"); + + migrationBuilder.AddForeignKey( + name: "FK_SectionItems_Surveys_SurveyId", + table: "SectionItems", + column: "SurveyId", + principalTable: "Surveys", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_SectionItems_Surveys_SurveyId", + table: "SectionItems"); + + migrationBuilder.DropTable( + name: "SurveyAnswers"); + + migrationBuilder.DropTable( + name: "AnswerOptions"); + + migrationBuilder.DropTable( + name: "SurveyQuestions"); + + migrationBuilder.DropTable( + name: "SurveyResponses"); + + migrationBuilder.DropTable( + name: "Surveys"); + + migrationBuilder.DropIndex( + name: "IX_SectionItems_SurveyId", + table: "SectionItems"); + + migrationBuilder.DropColumn( + name: "SurveyId", + table: "SectionItems"); + } + } +} diff --git a/Tsi1.Api/Tsi1.DataLayer/Migrations/Tsi1ContextModelSnapshot.cs b/Tsi1.Api/Tsi1.DataLayer/Migrations/Tsi1ContextModelSnapshot.cs index e661f62fc22750b698b1da14d4ac889d01af8e80..f07e8b8562e475ad108b9f9b18ed7ae457d0ba29 100644 --- a/Tsi1.Api/Tsi1.DataLayer/Migrations/Tsi1ContextModelSnapshot.cs +++ b/Tsi1.Api/Tsi1.DataLayer/Migrations/Tsi1ContextModelSnapshot.cs @@ -19,6 +19,24 @@ namespace Tsi1.DataLayer.Migrations .HasAnnotation("ProductVersion", "3.1.4") .HasAnnotation("Relational:MaxIdentifierLength", 63); + modelBuilder.Entity("Tsi1.DataLayer.Entities.AnswerOption", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<string>("Name") + .IsRequired() + .HasColumnType("character varying(100)"); + + b.HasKey("Id"); + + b.HasIndex("Name"); + + b.ToTable("AnswerOptions"); + }); + modelBuilder.Entity("Tsi1.DataLayer.Entities.Connection", b => { b.Property<string>("ConnectionId") @@ -269,6 +287,9 @@ namespace Tsi1.DataLayer.Migrations b.Property<int>("SectionItemTypeId") .HasColumnType("integer"); + b.Property<int?>("SurveyId") + .HasColumnType("integer"); + b.HasKey("Id"); b.HasIndex("FileId") @@ -281,6 +302,9 @@ namespace Tsi1.DataLayer.Migrations b.HasIndex("SectionItemTypeId"); + b.HasIndex("SurveyId") + .IsUnique(); + b.ToTable("SectionItems"); }); @@ -342,6 +366,102 @@ namespace Tsi1.DataLayer.Migrations b.ToTable("StudentCourses"); }); + modelBuilder.Entity("Tsi1.DataLayer.Entities.Survey", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<bool>("IsGlobal") + .HasColumnType("boolean"); + + b.Property<string>("Name") + .IsRequired() + .HasColumnType("character varying(255)"); + + b.Property<int>("TenantId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("Name"); + + b.HasIndex("TenantId"); + + b.ToTable("Surveys"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.SurveyAnswer", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<int>("AnswerOptionId") + .HasColumnType("integer"); + + b.Property<int>("SurveyQuestionId") + .HasColumnType("integer"); + + b.Property<int>("SurveyResponseId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("AnswerOptionId"); + + b.HasIndex("SurveyQuestionId"); + + b.HasIndex("SurveyResponseId"); + + b.ToTable("SurveyAnswers"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.SurveyQuestion", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<string>("Question") + .IsRequired() + .HasColumnType("character varying(255)"); + + b.Property<int>("SurveyId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("SurveyId"); + + b.ToTable("SurveyQuestions"); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.SurveyResponse", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property<int>("SurveyId") + .HasColumnType("integer"); + + b.Property<int>("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("SurveyId"); + + b.HasIndex("UserId"); + + b.ToTable("SurveyResponses"); + }); + modelBuilder.Entity("Tsi1.DataLayer.Entities.Tenant", b => { b.Property<int>("Id") @@ -552,6 +672,10 @@ namespace Tsi1.DataLayer.Migrations .HasForeignKey("SectionItemTypeId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + + b.HasOne("Tsi1.DataLayer.Entities.Survey", "Survey") + .WithOne("SectionItem") + .HasForeignKey("Tsi1.DataLayer.Entities.SectionItem", "SurveyId"); }); modelBuilder.Entity("Tsi1.DataLayer.Entities.Student", b => @@ -578,6 +702,60 @@ namespace Tsi1.DataLayer.Migrations .IsRequired(); }); + modelBuilder.Entity("Tsi1.DataLayer.Entities.Survey", b => + { + b.HasOne("Tsi1.DataLayer.Entities.Tenant", "Tenant") + .WithMany("Surveys") + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.SurveyAnswer", b => + { + b.HasOne("Tsi1.DataLayer.Entities.AnswerOption", "AnswerOption") + .WithMany("SurveyAnswers") + .HasForeignKey("AnswerOptionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Tsi1.DataLayer.Entities.SurveyQuestion", "SurveyQuestion") + .WithMany("SurveyAnswers") + .HasForeignKey("SurveyQuestionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Tsi1.DataLayer.Entities.SurveyResponse", "SurveyResponse") + .WithMany("SurveyAnswers") + .HasForeignKey("SurveyResponseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.SurveyQuestion", b => + { + b.HasOne("Tsi1.DataLayer.Entities.Survey", "Survey") + .WithMany("SurveyQuestions") + .HasForeignKey("SurveyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Tsi1.DataLayer.Entities.SurveyResponse", b => + { + b.HasOne("Tsi1.DataLayer.Entities.Survey", "Survey") + .WithMany("SurveyResponses") + .HasForeignKey("SurveyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Tsi1.DataLayer.Entities.User", "User") + .WithMany("SurveyResponses") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + modelBuilder.Entity("Tsi1.DataLayer.Entities.User", b => { b.HasOne("Tsi1.DataLayer.Entities.Professor", "Professor") diff --git a/Tsi1.Api/Tsi1.DataLayer/Tsi1Context.cs b/Tsi1.Api/Tsi1.DataLayer/Tsi1Context.cs index ba1524c725417ba94a5672a0254a9cd05d66f911..468e7dd1b6849216aedf0fee5ad9ae03bffd44b9 100644 --- a/Tsi1.Api/Tsi1.DataLayer/Tsi1Context.cs +++ b/Tsi1.Api/Tsi1.DataLayer/Tsi1Context.cs @@ -27,6 +27,12 @@ namespace Tsi1.DataLayer public DbSet<Section> Sections { get; set; } public DbSet<SectionItem> SectionItems { get; set; } public DbSet<SectionItemType> SectionItemTypes { get; set; } + public DbSet<Survey> Surveys { get; set; } + public DbSet<SurveyAnswer> SurveyAnswers { get; set; } + public DbSet<SurveyQuestion> SurveyQuestions { get; set; } + public DbSet<SurveyResponse> SurveyResponses { get; set; } + public DbSet<AnswerOption> AnswerOptions { get; set; } + public Tsi1Context(DbContextOptions options) : base(options) { } @@ -51,6 +57,11 @@ namespace Tsi1.DataLayer modelBuilder.ApplyConfiguration(new SectionConfiguration()); modelBuilder.ApplyConfiguration(new SectionItemConfiguration()); modelBuilder.ApplyConfiguration(new SectionItemTypeConfiguration()); + modelBuilder.ApplyConfiguration(new SurveyConfiguration()); + modelBuilder.ApplyConfiguration(new SurveyAnswerConfiguration()); + modelBuilder.ApplyConfiguration(new SurveyQuestionConfiguration()); + modelBuilder.ApplyConfiguration(new SurveyResponseConfiguration()); + modelBuilder.ApplyConfiguration(new AnswerOptionConfiguration()); } } }