diff --git a/DamageAssesmentApi/DamageAssesment.Api.Answers/DamageAssesment.Api.Answers.csproj b/DamageAssesmentApi/DamageAssesment.Api.Answers/DamageAssesment.Api.Answers.csproj index 4b1c8e9..853990d 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Answers/DamageAssesment.Api.Answers.csproj +++ b/DamageAssesmentApi/DamageAssesment.Api.Answers/DamageAssesment.Api.Answers.csproj @@ -13,7 +13,12 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/DamageAssesmentApi/DamageAssesment.Api.Answers/Db/AnswerDbContext.cs b/DamageAssesmentApi/DamageAssesment.Api.Answers/Db/AnswerDbContext.cs index 1f3c996..2460385 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Answers/Db/AnswerDbContext.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Answers/Db/AnswerDbContext.cs @@ -1,13 +1,19 @@ using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; namespace DamageAssesment.Api.Answers.Db { public class AnswerDbContext:DbContext { - - public AnswerDbContext(DbContextOptions options):base(options) + private IConfiguration _Configuration { get; set; } + public AnswerDbContext(DbContextOptions options,IConfiguration configuration):base(options) { - + _Configuration= configuration; + } + protected override void OnConfiguring(DbContextOptionsBuilder options) + { + // connect to sql server with connection string from app settings + options.UseSqlServer(_Configuration.GetConnectionString("AnswerConnection")); } public DbSet Answers { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) diff --git a/DamageAssesmentApi/DamageAssesment.Api.Answers/Migrations/20230816214724_InitialCreate.Designer.cs b/DamageAssesmentApi/DamageAssesment.Api.Answers/Migrations/20230816214724_InitialCreate.Designer.cs new file mode 100644 index 0000000..cd62640 --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.Answers/Migrations/20230816214724_InitialCreate.Designer.cs @@ -0,0 +1,58 @@ +// +using System; +using DamageAssesment.Api.Answers.Db; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DamageAssesment.Api.Answers.Migrations +{ + [DbContext(typeof(AnswerDbContext))] + [Migration("20230816214724_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DamageAssesment.Api.Answers.Db.Answer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AnswerText") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("nvarchar(250)"); + + b.Property("Comment") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("QuestionId") + .HasColumnType("int"); + + b.Property("SurveyResponseId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Answers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Answers/Migrations/20230816214724_InitialCreate.cs b/DamageAssesmentApi/DamageAssesment.Api.Answers/Migrations/20230816214724_InitialCreate.cs new file mode 100644 index 0000000..ff519b4 --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.Answers/Migrations/20230816214724_InitialCreate.cs @@ -0,0 +1,37 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DamageAssesment.Api.Answers.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Answers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + QuestionId = table.Column(type: "int", nullable: false), + AnswerText = table.Column(type: "nvarchar(250)", maxLength: 250, nullable: false), + Comment = table.Column(type: "nvarchar(max)", nullable: false), + SurveyResponseId = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Answers", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Answers"); + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Answers/Migrations/AnswerDbContextModelSnapshot.cs b/DamageAssesmentApi/DamageAssesment.Api.Answers/Migrations/AnswerDbContextModelSnapshot.cs new file mode 100644 index 0000000..02d3df3 --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.Answers/Migrations/AnswerDbContextModelSnapshot.cs @@ -0,0 +1,55 @@ +// +using System; +using DamageAssesment.Api.Answers.Db; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DamageAssesment.Api.Answers.Migrations +{ + [DbContext(typeof(AnswerDbContext))] + partial class AnswerDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DamageAssesment.Api.Answers.Db.Answer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AnswerText") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("nvarchar(250)"); + + b.Property("Comment") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("QuestionId") + .HasColumnType("int"); + + b.Property("SurveyResponseId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Answers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Answers/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.Answers/Program.cs index 7229cf9..0a38399 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Answers/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Answers/Program.cs @@ -23,7 +23,7 @@ builder.Services.AddScoped(); builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30 builder.Services.AddDbContext(option => { - option.UseInMemoryDatabase("Answers"); + option.UseSqlServer("AnswerConnection"); }); var app = builder.Build(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Answers/Providers/AnswerProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Answers/Providers/AnswerProvider.cs index 9291628..291726f 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Answers/Providers/AnswerProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Answers/Providers/AnswerProvider.cs @@ -191,12 +191,12 @@ namespace DamageAssesment.Api.Answers.Providers { if (!answerDbContext.Answers.Any()) { - answerDbContext.Answers.Add(new Db.Answer() { Id = 1, AnswerText = "Yes", Comment = "Comment test 4", QuestionId = 1, SurveyResponseId = 1 }); - answerDbContext.Answers.Add(new Db.Answer() { Id = 2, AnswerText = "No", Comment = "Comment test 5", QuestionId = 2, SurveyResponseId = 1 }); - //answerDbContext.Answers.Add(new Db.Answer() { Id = 3, AnswerText = "No", Comment = "No Comment", QuestionId = 3, SurveyResponseId = 1 }); - //answerDbContext.Answers.Add(new Db.Answer() { Id = 4, AnswerText = "Yes", Comment = "No Comment", QuestionId = 1, SurveyResponseId = 2 }); - //answerDbContext.Answers.Add(new Db.Answer() { Id = 5, AnswerText = "No", Comment = "No Comment", QuestionId = 2, SurveyResponseId = 2 }); - //answerDbContext.Answers.Add(new Db.Answer() { Id = 6, AnswerText = "No", Comment = "No Comment", QuestionId = 3, SurveyResponseId = 2 }); + answerDbContext.Answers.Add(new Db.Answer() { AnswerText = "Yes", Comment = "", QuestionId = 1, SurveyResponseId = 1 }); + answerDbContext.Answers.Add(new Db.Answer() { AnswerText = "Yes", Comment = "myComment", QuestionId = 2, SurveyResponseId = 1 }); + answerDbContext.Answers.Add(new Db.Answer() { AnswerText = "No", Comment = "No Comment", QuestionId = 3, SurveyResponseId = 1 }); + answerDbContext.Answers.Add(new Db.Answer() { AnswerText = "Yes", Comment = "No Comment", QuestionId = 1, SurveyResponseId = 2 }); + answerDbContext.Answers.Add(new Db.Answer() { AnswerText = "No", Comment = "No Comment", QuestionId = 2, SurveyResponseId = 2 }); + answerDbContext.Answers.Add(new Db.Answer() { AnswerText = "No", Comment = "No Comment", QuestionId = 3, SurveyResponseId = 2 }); answerDbContext.SaveChanges(); } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Answers/appsettings.json b/DamageAssesmentApi/DamageAssesment.Api.Answers/appsettings.json index ff5949d..1cd2bcb 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Answers/appsettings.json +++ b/DamageAssesmentApi/DamageAssesment.Api.Answers/appsettings.json @@ -8,5 +8,8 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "ConnectionStrings": { + "AnswerConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;" + } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Attachments/DamageAssesment.Api.Attachments.csproj b/DamageAssesmentApi/DamageAssesment.Api.Attachments/DamageAssesment.Api.Attachments.csproj index 9aec665..157cd85 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Attachments/DamageAssesment.Api.Attachments.csproj +++ b/DamageAssesmentApi/DamageAssesment.Api.Attachments/DamageAssesment.Api.Attachments.csproj @@ -14,8 +14,19 @@ - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/DamageAssesmentApi/DamageAssesment.Api.Attachments/Db/AttachmentsDbContext.cs b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Db/AttachmentsDbContext.cs index b4e8d0c..7d92f3a 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Attachments/Db/AttachmentsDbContext.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Db/AttachmentsDbContext.cs @@ -1,11 +1,19 @@ using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; namespace DamageAssesment.Api.Attachments.Db { public class AttachmentsDbContext:DbContext { - public AttachmentsDbContext(DbContextOptions options) : base(options) + private IConfiguration _Configuration { get; set; } + public AttachmentsDbContext(DbContextOptions options, IConfiguration configuration) : base(options) { + _Configuration = configuration; + } + protected override void OnConfiguring(DbContextOptionsBuilder options) + { + // connect to sql server with connection string from app settings + options.UseSqlServer(_Configuration.GetConnectionString("AttachmentConnection")); } public DbSet Attachments { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) diff --git a/DamageAssesmentApi/DamageAssesment.Api.Attachments/Migrations/20230817212256_InitialAttachment.Designer.cs b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Migrations/20230817212256_InitialAttachment.Designer.cs new file mode 100644 index 0000000..ae47dfd --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Migrations/20230817212256_InitialAttachment.Designer.cs @@ -0,0 +1,60 @@ +// +using System; +using DamageAssesment.Api.Attachments.Db; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DamageAssesment.Api.Attachments.Migrations +{ + [DbContext(typeof(AttachmentsDbContext))] + [Migration("20230817212256_InitialAttachment")] + partial class InitialAttachment + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DamageAssesment.Api.Attachments.Db.Attachment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AnswerId") + .HasColumnType("int"); + + b.Property("FileName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("ResponseId") + .HasColumnType("int"); + + b.Property("URI") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Attachments"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Attachments/Migrations/20230817212256_InitialAttachment.cs b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Migrations/20230817212256_InitialAttachment.cs new file mode 100644 index 0000000..2b260ed --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Migrations/20230817212256_InitialAttachment.cs @@ -0,0 +1,38 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DamageAssesment.Api.Attachments.Migrations +{ + /// + public partial class InitialAttachment : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Attachments", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + URI = table.Column(type: "nvarchar(max)", nullable: false), + AnswerId = table.Column(type: "int", nullable: true), + ResponseId = table.Column(type: "int", nullable: false), + IsDeleted = table.Column(type: "bit", nullable: false), + FileName = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Attachments", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Attachments"); + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Attachments/Migrations/AttachmentsDbContextModelSnapshot.cs b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Migrations/AttachmentsDbContextModelSnapshot.cs new file mode 100644 index 0000000..8f0cc45 --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Migrations/AttachmentsDbContextModelSnapshot.cs @@ -0,0 +1,57 @@ +// +using System; +using DamageAssesment.Api.Attachments.Db; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DamageAssesment.Api.Attachments.Migrations +{ + [DbContext(typeof(AttachmentsDbContext))] + partial class AttachmentsDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DamageAssesment.Api.Attachments.Db.Attachment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AnswerId") + .HasColumnType("int"); + + b.Property("FileName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("ResponseId") + .HasColumnType("int"); + + b.Property("URI") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Attachments"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Attachments/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Program.cs index 61ce1c5..4fd2e59 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Attachments/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Program.cs @@ -27,7 +27,7 @@ builder.Services.AddScoped(); builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30 builder.Services.AddDbContext(option => { - option.UseInMemoryDatabase("Attachments"); + option.UseSqlServer("AttachmentConnection"); }); builder.Services.Configure(o => { diff --git a/DamageAssesmentApi/DamageAssesment.Api.Attachments/Providers/AttachmentsProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Providers/AttachmentsProvider.cs index c18cd05..92c20e5 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Attachments/Providers/AttachmentsProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Attachments/Providers/AttachmentsProvider.cs @@ -21,7 +21,7 @@ namespace DamageAssesment.Api.Attachments.Providers this.logger = logger; this.mapper = mapper; this.uploadservice = uploadservice; - SeedData(); + //SeedData(); } public async Task<(bool IsSuccess, IEnumerable Attachments, string ErrorMessage)> GetAttachmentsAsync() { diff --git a/DamageAssesmentApi/DamageAssesment.Api.Attachments/appsettings.json b/DamageAssesmentApi/DamageAssesment.Api.Attachments/appsettings.json index 78aa6b5..1b48365 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Attachments/appsettings.json +++ b/DamageAssesmentApi/DamageAssesment.Api.Attachments/appsettings.json @@ -12,5 +12,8 @@ "Fileupload": { "folderpath": "DMS_Attachments/Active", "Deletepath": "DMS_Attachments/Deleted" + }, + "ConnectionStrings": { + "AttachmentConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;" } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Db/DoculinkDbContext.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Db/DoculinkDbContext.cs index e3fdccc..f24303e 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Db/DoculinkDbContext.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Db/DoculinkDbContext.cs @@ -7,8 +7,15 @@ namespace DamageAssesment.Api.DocuLinks.Db { public class DoculinkDbContext : DbContext { - public DoculinkDbContext(DbContextOptions options) : base(options) + private IConfiguration _Configuration { get; set; } + public DoculinkDbContext(DbContextOptions options, IConfiguration configuration) : base(options) { + _Configuration = configuration; + } + protected override void OnConfiguring(DbContextOptionsBuilder options) + { + // connect to sql server with connection string from app settings + options.UseSqlServer(_Configuration.GetConnectionString("DoculinConnection")); } public DbSet Documents { get; set; } public DbSet LinkTypes { get; set; } diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/20230926163717_doculinkUpdate.Designer.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/20230926163717_doculinkUpdate.Designer.cs new file mode 100644 index 0000000..a8fd840 --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/20230926163717_doculinkUpdate.Designer.cs @@ -0,0 +1,162 @@ +// +using System; +using DamageAssesment.Api.DocuLinks.Db; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DamageAssesment.Api.DocuLinks.Migrations +{ + [DbContext(typeof(DoculinkDbContext))] + [Migration("20230926163717_doculinkUpdate")] + partial class doculinkUpdate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DamageAssesment.Api.DocuLinks.Db.Doculink", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CustomOrder") + .HasColumnType("int"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("dateCreated") + .HasColumnType("datetime2"); + + b.Property("dateUpdated") + .HasColumnType("datetime2"); + + b.Property("linkTypeId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Documents"); + }); + + modelBuilder.Entity("DamageAssesment.Api.DocuLinks.Db.DoculinkAttachments", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CustomOrder") + .HasColumnType("int"); + + b.Property("DocumentId") + .HasColumnType("int"); + + b.Property("IsAttachments") + .HasColumnType("bit"); + + b.Property("Path") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("docName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("DoclinksAttachments"); + }); + + modelBuilder.Entity("DamageAssesment.Api.DocuLinks.Db.DoculinkTranslation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DocumentId") + .HasColumnType("int"); + + b.Property("Language") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("DocumentsTranslations"); + }); + + modelBuilder.Entity("DamageAssesment.Api.DocuLinks.Db.LinkType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CustomOrder") + .HasColumnType("int"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.HasKey("Id"); + + b.ToTable("LinkTypes"); + }); + + modelBuilder.Entity("DamageAssesment.Api.DocuLinks.Db.LinksTranslation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Language") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("LinkTypeId") + .HasColumnType("int"); + + b.Property("TypeText") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("LinksTranslations"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/20230926163717_doculinkUpdate.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/20230926163717_doculinkUpdate.cs new file mode 100644 index 0000000..f5df82a --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/20230926163717_doculinkUpdate.cs @@ -0,0 +1,144 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DamageAssesment.Api.DocuLinks.Migrations +{ + /// + public partial class doculinkUpdate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "IsAttachment", + table: "LinkTypes"); + + migrationBuilder.DropColumn( + name: "TypeText", + table: "LinkTypes"); + + migrationBuilder.DropColumn( + name: "Path", + table: "Documents"); + + migrationBuilder.DropColumn( + name: "docName", + table: "Documents"); + + migrationBuilder.DropColumn( + name: "url", + table: "Documents"); + + migrationBuilder.AddColumn( + name: "CustomOrder", + table: "LinkTypes", + type: "int", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "CustomOrder", + table: "Documents", + type: "int", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "IsDeleted", + table: "Documents", + type: "bit", + nullable: false, + defaultValue: false); + + migrationBuilder.CreateTable( + name: "DoclinksAttachments", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DocumentId = table.Column(type: "int", nullable: false), + docName = table.Column(type: "nvarchar(max)", nullable: false), + Path = table.Column(type: "nvarchar(max)", nullable: false), + IsAttachments = table.Column(type: "bit", nullable: false), + CustomOrder = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_DoclinksAttachments", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "LinksTranslations", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + LinkTypeId = table.Column(type: "int", nullable: false), + TypeText = table.Column(type: "nvarchar(max)", nullable: false), + Language = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_LinksTranslations", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "DoclinksAttachments"); + + migrationBuilder.DropTable( + name: "LinksTranslations"); + + migrationBuilder.DropColumn( + name: "CustomOrder", + table: "LinkTypes"); + + migrationBuilder.DropColumn( + name: "CustomOrder", + table: "Documents"); + + migrationBuilder.DropColumn( + name: "IsDeleted", + table: "Documents"); + + migrationBuilder.AddColumn( + name: "IsAttachment", + table: "LinkTypes", + type: "bit", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "TypeText", + table: "LinkTypes", + type: "nvarchar(max)", + nullable: false, + defaultValue: ""); + + migrationBuilder.AddColumn( + name: "Path", + table: "Documents", + type: "nvarchar(max)", + nullable: false, + defaultValue: ""); + + migrationBuilder.AddColumn( + name: "docName", + table: "Documents", + type: "nvarchar(max)", + nullable: false, + defaultValue: ""); + + migrationBuilder.AddColumn( + name: "url", + table: "Documents", + type: "nvarchar(max)", + nullable: false, + defaultValue: ""); + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/DocumentDbContextModelSnapshot.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/DocumentDbContextModelSnapshot.cs index a692f80..536727e 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/DocumentDbContextModelSnapshot.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/DocumentDbContextModelSnapshot.cs @@ -22,7 +22,7 @@ namespace DamageAssesment.Api.DocuLinks.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - modelBuilder.Entity("DamageAssesment.Api.DocuLinks.Db.Document", b => + modelBuilder.Entity("DamageAssesment.Api.DocuLinks.Db.Doculink", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -30,12 +30,14 @@ namespace DamageAssesment.Api.DocuLinks.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("CustomOrder") + .HasColumnType("int"); + b.Property("IsActive") .HasColumnType("bit"); - b.Property("Path") - .IsRequired() - .HasColumnType("nvarchar(max)"); + b.Property("IsDeleted") + .HasColumnType("bit"); b.Property("dateCreated") .HasColumnType("datetime2"); @@ -43,23 +45,45 @@ namespace DamageAssesment.Api.DocuLinks.Migrations b.Property("dateUpdated") .HasColumnType("datetime2"); - b.Property("docName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - b.Property("linkTypeId") .HasColumnType("int"); - b.Property("url") - .IsRequired() - .HasColumnType("nvarchar(max)"); - b.HasKey("Id"); b.ToTable("Documents"); }); - modelBuilder.Entity("DamageAssesment.Api.DocuLinks.Db.DocumentsTranslation", b => + modelBuilder.Entity("DamageAssesment.Api.DocuLinks.Db.DoculinkAttachments", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CustomOrder") + .HasColumnType("int"); + + b.Property("DocumentId") + .HasColumnType("int"); + + b.Property("IsAttachments") + .HasColumnType("bit"); + + b.Property("Path") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("docName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("DoclinksAttachments"); + }); + + modelBuilder.Entity("DamageAssesment.Api.DocuLinks.Db.DoculinkTranslation", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -95,11 +119,31 @@ namespace DamageAssesment.Api.DocuLinks.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("CustomOrder") + .HasColumnType("int"); + b.Property("IsActive") .HasColumnType("bit"); - b.Property("IsAttachment") - .HasColumnType("bit"); + b.HasKey("Id"); + + b.ToTable("LinkTypes"); + }); + + modelBuilder.Entity("DamageAssesment.Api.DocuLinks.Db.LinksTranslation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Language") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("LinkTypeId") + .HasColumnType("int"); b.Property("TypeText") .IsRequired() @@ -107,7 +151,7 @@ namespace DamageAssesment.Api.DocuLinks.Migrations b.HasKey("Id"); - b.ToTable("LinkTypes"); + b.ToTable("LinksTranslations"); }); #pragma warning restore 612, 618 } diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Program.cs index f25927c..f28dd76 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Program.cs @@ -25,7 +25,7 @@ builder.Services.AddScoped(); builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30 builder.Services.AddDbContext(option => { - option.UseInMemoryDatabase("DocumentConnection"); + option.UseSqlServer("DoculinConnection"); }); var app = builder.Build(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/appsettings.json b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/appsettings.json index e38d9fb..0006765 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/appsettings.json +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/appsettings.json @@ -6,6 +6,9 @@ } }, "AllowedHosts": "*", + "ConnectionStrings": { + "DoculinConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;" + }, "Fileupload": { "folderpath": "DASA_Documents/Active", "Deletepath": "DASA_Documents/Deleted" diff --git a/DamageAssesmentApi/DamageAssesment.Api.Employees/DamageAssesment.Api.Employees.csproj b/DamageAssesmentApi/DamageAssesment.Api.Employees/DamageAssesment.Api.Employees.csproj index 6789613..cbaabfd 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Employees/DamageAssesment.Api.Employees.csproj +++ b/DamageAssesmentApi/DamageAssesment.Api.Employees/DamageAssesment.Api.Employees.csproj @@ -12,8 +12,18 @@ - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/DamageAssesmentApi/DamageAssesment.Api.Employees/Db/EmployeeDbContext.cs b/DamageAssesmentApi/DamageAssesment.Api.Employees/Db/EmployeeDbContext.cs index ec7b0f0..b04cfd2 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Employees/Db/EmployeeDbContext.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Employees/Db/EmployeeDbContext.cs @@ -4,18 +4,23 @@ namespace DamageAssesment.Api.Employees.Db { public class EmployeeDbContext: DbContext { - public DbSet Employees { get; set; } - public EmployeeDbContext(DbContextOptions options) : base(options) + private IConfiguration _Configuration { get; set; } + public EmployeeDbContext(DbContextOptions options, IConfiguration configuration) : base(options) { + _Configuration = configuration; + } + protected override void OnConfiguring(DbContextOptionsBuilder options) + { + // connect to sql server with connection string from app settings + options.UseSqlServer(_Configuration.GetConnectionString("EmployeeConnection")); } - protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); - modelBuilder.Entity() .Property(item => item.Id) .ValueGeneratedOnAdd(); } + public DbSet Employees { get; set; } } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230817213656_InitialEmployee.Designer.cs b/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230817213656_InitialEmployee.Designer.cs new file mode 100644 index 0000000..d747ab1 --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230817213656_InitialEmployee.Designer.cs @@ -0,0 +1,64 @@ +// +using System; +using DamageAssesment.Api.Employees.Db; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DamageAssesment.Api.Employees.Migrations +{ + [DbContext(typeof(EmployeeDbContext))] + [Migration("20230817213656_InitialEmployee")] + partial class InitialEmployee + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DamageAssesment.Api.Employees.Db.Employee", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("BirthDate") + .HasColumnType("datetime2"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("OfficePhoneNumber") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("PreferredLanguage") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230817213656_InitialEmployee.cs b/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230817213656_InitialEmployee.cs new file mode 100644 index 0000000..607751e --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230817213656_InitialEmployee.cs @@ -0,0 +1,39 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DamageAssesment.Api.Employees.Migrations +{ + /// + public partial class InitialEmployee : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Employees", + columns: table => new + { + Id = table.Column(type: "nvarchar(450)", nullable: false), + Name = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + BirthDate = table.Column(type: "datetime2", nullable: false), + OfficePhoneNumber = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Email = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + IsActive = table.Column(type: "bit", nullable: false), + PreferredLanguage = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Employees", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Employees"); + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230913164315_employeeupdate.Designer.cs b/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230913164315_employeeupdate.Designer.cs new file mode 100644 index 0000000..b4aebb2 --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230913164315_employeeupdate.Designer.cs @@ -0,0 +1,72 @@ +// +using System; +using DamageAssesment.Api.Employees.Db; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DamageAssesment.Api.Employees.Migrations +{ + [DbContext(typeof(EmployeeDbContext))] + [Migration("20230913164315_employeeupdate")] + partial class employeeupdate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DamageAssesment.Api.Employees.Db.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BirthDate") + .HasColumnType("datetime2"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("EmployeeCode") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("OfficePhoneNumber") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("PreferredLanguage") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230913164315_employeeupdate.cs b/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230913164315_employeeupdate.cs new file mode 100644 index 0000000..8b5ff7f --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230913164315_employeeupdate.cs @@ -0,0 +1,48 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DamageAssesment.Api.Employees.Migrations +{ + /// + public partial class employeeupdate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Id", + table: "Employees", + type: "int", + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(450)") + .Annotation("SqlServer:Identity", "1, 1"); + + migrationBuilder.AddColumn( + name: "EmployeeCode", + table: "Employees", + type: "nvarchar(50)", + maxLength: 50, + nullable: false, + defaultValue: ""); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "EmployeeCode", + table: "Employees"); + + migrationBuilder.AlterColumn( + name: "Id", + table: "Employees", + type: "nvarchar(450)", + nullable: false, + oldClrType: typeof(int), + oldType: "int") + .OldAnnotation("SqlServer:Identity", "1, 1"); + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230913170055_updatedemployee_id.Designer.cs b/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230913170055_updatedemployee_id.Designer.cs new file mode 100644 index 0000000..35e45ac --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230913170055_updatedemployee_id.Designer.cs @@ -0,0 +1,72 @@ +// +using System; +using DamageAssesment.Api.Employees.Db; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DamageAssesment.Api.Employees.Migrations +{ + [DbContext(typeof(EmployeeDbContext))] + [Migration("20230913170055_updatedemployee_id")] + partial class updatedemployee_id + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DamageAssesment.Api.Employees.Db.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BirthDate") + .HasColumnType("datetime2"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("EmployeeCode") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("OfficePhoneNumber") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("PreferredLanguage") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230913170055_updatedemployee_id.cs b/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230913170055_updatedemployee_id.cs new file mode 100644 index 0000000..8b004ed --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230913170055_updatedemployee_id.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DamageAssesment.Api.Employees.Migrations +{ + /// + public partial class updatedemployee_id : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/EmployeeDbContextModelSnapshot.cs b/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/EmployeeDbContextModelSnapshot.cs new file mode 100644 index 0000000..3bfb33c --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/EmployeeDbContextModelSnapshot.cs @@ -0,0 +1,69 @@ +// +using System; +using DamageAssesment.Api.Employees.Db; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DamageAssesment.Api.Employees.Migrations +{ + [DbContext(typeof(EmployeeDbContext))] + partial class EmployeeDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DamageAssesment.Api.Employees.Db.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BirthDate") + .HasColumnType("datetime2"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("EmployeeCode") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("OfficePhoneNumber") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("PreferredLanguage") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Employees/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.Employees/Program.cs index 1e88127..7d61871 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Employees/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Employees/Program.cs @@ -24,7 +24,7 @@ builder.Services.AddScoped(); builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30 builder.Services.AddDbContext(option => { - option.UseInMemoryDatabase("Employees"); + option.UseSqlServer("EmployeeConnection"); }); var app = builder.Build(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Employees/Providers/EmployeesProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Employees/Providers/EmployeesProvider.cs index eed1e09..2aa0551 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Employees/Providers/EmployeesProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Employees/Providers/EmployeesProvider.cs @@ -156,12 +156,12 @@ namespace DamageAssesment.Api.Employees.Providers { if (!EmployeeDbContext.Employees.Any()) { - EmployeeDbContext.Employees.Add(new Db.Employee() { EmployeeCode = "Emp1", Name = "David", Email = "David@gmail.com", OfficePhoneNumber = "12345678", BirthDate = DateTime.Now.AddYears(-18), IsActive = true, PreferredLanguage = "en" }); - EmployeeDbContext.Employees.Add(new Db.Employee() { EmployeeCode = "Emp2", Name = "Smith", Email = "Smith@gmail.com", OfficePhoneNumber = "12345678", BirthDate = DateTime.Now.AddYears(-22), IsActive = true, PreferredLanguage = "fr" }); - //EmployeeDbContext.Employees.Add(new Db.Employee() { Id = 3, EmployeeCode = "Emp3", Name = "ABC3", Email = "abc3@gmail.com", OfficePhoneNumber = "12345678", BirthDate = DateTime.Now.AddYears(-30), IsActive = true, PreferredLanguage = "fr" }); - //EmployeeDbContext.Employees.Add(new Db.Employee() { Id = 4, EmployeeCode = "Emp4", Name = "ABC4", Email = "abc4@gmail.com", OfficePhoneNumber = "12345678", BirthDate = DateTime.Now.AddYears(-20), IsActive = true, PreferredLanguage = "en" }); - //EmployeeDbContext.Employees.Add(new Db.Employee() { Id = 5, EmployeeCode = "Emp5", Name = "ABC5", Email = "abc5@gmail.com", OfficePhoneNumber = "12345678", BirthDate = DateTime.Now.AddYears(-23), IsActive = true, PreferredLanguage = "es" }); - //EmployeeDbContext.Employees.Add(new Db.Employee() { Id = 6, EmployeeCode = "Emp6", Name = "ABC6", Email = "abc6@gmail.com", OfficePhoneNumber = "12345678", BirthDate = DateTime.Now.AddYears(-32), IsActive = true, PreferredLanguage = "es" }); + EmployeeDbContext.Employees.Add(new Db.Employee() { EmployeeCode = "Emp1", Name = "ABC1", Email = "abc1@gmail.com", OfficePhoneNumber = "12345678", BirthDate = DateTime.Now.AddYears(-18), IsActive = true, PreferredLanguage = "en" }); + EmployeeDbContext.Employees.Add(new Db.Employee() { EmployeeCode = "Emp2", Name = "ABC2", Email = "abc2@gmail.com", OfficePhoneNumber = "12345678", BirthDate = DateTime.Now.AddYears(-22), IsActive = true, PreferredLanguage = "fr" }); + EmployeeDbContext.Employees.Add(new Db.Employee() { EmployeeCode = "Emp3", Name = "ABC3", Email = "abc3@gmail.com", OfficePhoneNumber = "12345678", BirthDate = DateTime.Now.AddYears(-30), IsActive = true, PreferredLanguage = "fr" }); + EmployeeDbContext.Employees.Add(new Db.Employee() { EmployeeCode = "Emp4", Name = "ABC4", Email = "abc4@gmail.com", OfficePhoneNumber = "12345678", BirthDate = DateTime.Now.AddYears(-20), IsActive = true, PreferredLanguage = "en" }); + EmployeeDbContext.Employees.Add(new Db.Employee() { EmployeeCode = "Emp5", Name = "ABC5", Email = "abc5@gmail.com", OfficePhoneNumber = "12345678", BirthDate = DateTime.Now.AddYears(-23), IsActive = true, PreferredLanguage = "es" }); + EmployeeDbContext.Employees.Add(new Db.Employee() { EmployeeCode = "Emp6", Name = "ABC6", Email = "abc6@gmail.com", OfficePhoneNumber = "12345678", BirthDate = DateTime.Now.AddYears(-32), IsActive = true, PreferredLanguage = "es" }); EmployeeDbContext.SaveChanges(); } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Employees/appsettings.json b/DamageAssesmentApi/DamageAssesment.Api.Employees/appsettings.json index 1a1f3fe..e4445e8 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Employees/appsettings.json +++ b/DamageAssesmentApi/DamageAssesment.Api.Employees/appsettings.json @@ -13,5 +13,8 @@ "endpoint1": "xxx", "endpoint2": "xxx", "endpoint3": "xxx" + }, + "ConnectionStrings": { + "EmployeeConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;" } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Locations/DamageAssesment.Api.Locations.csproj b/DamageAssesmentApi/DamageAssesment.Api.Locations/DamageAssesment.Api.Locations.csproj index 6789613..60acab4 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Locations/DamageAssesment.Api.Locations.csproj +++ b/DamageAssesmentApi/DamageAssesment.Api.Locations/DamageAssesment.Api.Locations.csproj @@ -11,6 +11,17 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/DamageAssesmentApi/DamageAssesment.Api.Locations/Db/LocationDbContext.cs b/DamageAssesmentApi/DamageAssesment.Api.Locations/Db/LocationDbContext.cs index 48f0543..2e85262 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Locations/Db/LocationDbContext.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Locations/Db/LocationDbContext.cs @@ -4,6 +4,16 @@ namespace DamageAssesment.Api.Locations.Db { public class LocationDbContext : DbContext { + private IConfiguration _Configuration { get; set; } + public LocationDbContext(DbContextOptions options, IConfiguration configuration) : base(options) + { + _Configuration = configuration; + } + protected override void OnConfiguring(DbContextOptionsBuilder options) + { + // connect to sql server with connection string from app settings + options.UseSqlServer(_Configuration.GetConnectionString("LocationConnection")); + } public DbSet Locations { get; set; } public DbSet Regions { get; set; } public LocationDbContext(DbContextOptions options) : base(options) diff --git a/DamageAssesmentApi/DamageAssesment.Api.Locations/Migrations/20230817214454_InitialLocation.Designer.cs b/DamageAssesmentApi/DamageAssesment.Api.Locations/Migrations/20230817214454_InitialLocation.Designer.cs new file mode 100644 index 0000000..3e27956 --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.Locations/Migrations/20230817214454_InitialLocation.Designer.cs @@ -0,0 +1,80 @@ +// +using DamageAssesment.Api.Locations.Db; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DamageAssesment.Api.Locations.Migrations +{ + [DbContext(typeof(LocationDbContext))] + [Migration("20230817214454_InitialLocation")] + partial class InitialLocation + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DamageAssesment.Api.Locations.Db.Location", b => + { + b.Property("Id") + .HasMaxLength(4) + .HasColumnType("nvarchar(4)"); + + b.Property("MaintenanceCenter") + .IsRequired() + .HasMaxLength(1) + .HasColumnType("nvarchar(1)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("RegionId") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SchoolType") + .IsRequired() + .HasMaxLength(2) + .HasColumnType("nvarchar(2)"); + + b.HasKey("Id"); + + b.ToTable("Locations"); + }); + + modelBuilder.Entity("DamageAssesment.Api.Locations.Db.Region", b => + { + b.Property("Id") + .HasMaxLength(2) + .HasColumnType("nvarchar(2)"); + + b.Property("Abbreviation") + .IsRequired() + .HasMaxLength(5) + .HasColumnType("nvarchar(5)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("Regions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Locations/Migrations/20230817214454_InitialLocation.cs b/DamageAssesmentApi/DamageAssesment.Api.Locations/Migrations/20230817214454_InitialLocation.cs new file mode 100644 index 0000000..4143c63 --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.Locations/Migrations/20230817214454_InitialLocation.cs @@ -0,0 +1,52 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DamageAssesment.Api.Locations.Migrations +{ + /// + public partial class InitialLocation : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Locations", + columns: table => new + { + Id = table.Column(type: "nvarchar(4)", maxLength: 4, nullable: false), + Name = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + MaintenanceCenter = table.Column(type: "nvarchar(1)", maxLength: 1, nullable: false), + SchoolType = table.Column(type: "nvarchar(2)", maxLength: 2, nullable: false), + RegionId = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Locations", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Regions", + columns: table => new + { + Id = table.Column(type: "nvarchar(2)", maxLength: 2, nullable: false), + Name = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Abbreviation = table.Column(type: "nvarchar(5)", maxLength: 5, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Regions", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Locations"); + + migrationBuilder.DropTable( + name: "Regions"); + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Locations/Migrations/LocationDbContextModelSnapshot.cs b/DamageAssesmentApi/DamageAssesment.Api.Locations/Migrations/LocationDbContextModelSnapshot.cs new file mode 100644 index 0000000..0ae10ad --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.Locations/Migrations/LocationDbContextModelSnapshot.cs @@ -0,0 +1,77 @@ +// +using DamageAssesment.Api.Locations.Db; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DamageAssesment.Api.Locations.Migrations +{ + [DbContext(typeof(LocationDbContext))] + partial class LocationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DamageAssesment.Api.Locations.Db.Location", b => + { + b.Property("Id") + .HasMaxLength(4) + .HasColumnType("nvarchar(4)"); + + b.Property("MaintenanceCenter") + .IsRequired() + .HasMaxLength(1) + .HasColumnType("nvarchar(1)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("RegionId") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SchoolType") + .IsRequired() + .HasMaxLength(2) + .HasColumnType("nvarchar(2)"); + + b.HasKey("Id"); + + b.ToTable("Locations"); + }); + + modelBuilder.Entity("DamageAssesment.Api.Locations.Db.Region", b => + { + b.Property("Id") + .HasMaxLength(2) + .HasColumnType("nvarchar(2)"); + + b.Property("Abbreviation") + .IsRequired() + .HasMaxLength(5) + .HasColumnType("nvarchar(5)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("Regions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Locations/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.Locations/Program.cs index 200e39b..f8136bd 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Locations/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Locations/Program.cs @@ -24,7 +24,7 @@ builder.Services.AddScoped(); builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30 builder.Services.AddDbContext(option => { - option.UseInMemoryDatabase("Locations"); + option.UseSqlServer("LocationConnection"); }); var app = builder.Build(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Locations/Providers/LocationsProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Locations/Providers/LocationsProvider.cs index 9952655..8c4adce 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Locations/Providers/LocationsProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Locations/Providers/LocationsProvider.cs @@ -141,10 +141,10 @@ namespace DamageAssesment.Api.Locations.Providers { locationDbContext.Locations.Add(new Db.Location() { LocationCode = "Loc1", RegionId = 1, Name = "BOB GRAHAM EDUCATION CENTER 1", MaintenanceCenter = "1", SchoolType = "US" }); locationDbContext.Locations.Add(new Db.Location() { LocationCode = "Loc2", RegionId = 2, Name = "BOB GRAHAM EDUCATION CENTER 2", MaintenanceCenter = "1", SchoolType = "US" }); - //locationDbContext.Locations.Add(new Db.Location() { Id = 3, LocationCode = "Loc3", RegionId = 3, Name = "BOB GRAHAM EDUCATION CENTER 3", MaintenanceCenter = "1", SchoolType = "US" }); - //locationDbContext.Locations.Add(new Db.Location() { Id = 4, LocationCode = "Loc4", RegionId = 1, Name = "BOB GRAHAM EDUCATION CENTER 4", MaintenanceCenter = "1", SchoolType = "US" }); - //locationDbContext.Locations.Add(new Db.Location() { Id = 5, LocationCode = "Loc5", RegionId = 2, Name = "BOB GRAHAM EDUCATION CENTER 5", MaintenanceCenter = "1", SchoolType = "US" }); - //locationDbContext.Locations.Add(new Db.Location() { Id = 6, LocationCode = "Loc6", RegionId = 3, Name = "BOB GRAHAM EDUCATION CENTER 6", MaintenanceCenter = "1", SchoolType = "US" }); + locationDbContext.Locations.Add(new Db.Location() { LocationCode = "Loc3", RegionId = 3, Name = "BOB GRAHAM EDUCATION CENTER 3", MaintenanceCenter = "1", SchoolType = "US" }); + locationDbContext.Locations.Add(new Db.Location() { LocationCode = "Loc4", RegionId = 1, Name = "BOB GRAHAM EDUCATION CENTER 4", MaintenanceCenter = "1", SchoolType = "US" }); + locationDbContext.Locations.Add(new Db.Location() { LocationCode = "Loc5", RegionId = 2, Name = "BOB GRAHAM EDUCATION CENTER 5", MaintenanceCenter = "1", SchoolType = "US" }); + locationDbContext.Locations.Add(new Db.Location() { LocationCode = "Loc6", RegionId = 3, Name = "BOB GRAHAM EDUCATION CENTER 6", MaintenanceCenter = "1", SchoolType = "US" }); locationDbContext.SaveChanges(); } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Locations/appsettings.json b/DamageAssesmentApi/DamageAssesment.Api.Locations/appsettings.json index ff5949d..37d1aef 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Locations/appsettings.json +++ b/DamageAssesmentApi/DamageAssesment.Api.Locations/appsettings.json @@ -8,5 +8,8 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "ConnectionStrings": { + "LocationConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;" + } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/DamageAssesment.Api.Questions.csproj b/DamageAssesmentApi/DamageAssesment.Api.Questions/DamageAssesment.Api.Questions.csproj index 6789613..60acab4 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Questions/DamageAssesment.Api.Questions.csproj +++ b/DamageAssesmentApi/DamageAssesment.Api.Questions/DamageAssesment.Api.Questions.csproj @@ -11,6 +11,17 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/Db/QuestionDbContext.cs b/DamageAssesmentApi/DamageAssesment.Api.Questions/Db/QuestionDbContext.cs index 01e3c3d..51df110 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Questions/Db/QuestionDbContext.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Questions/Db/QuestionDbContext.cs @@ -6,6 +6,16 @@ namespace DamageAssesment.Api.Questions.Db { public class QuestionDbContext : DbContext { + private IConfiguration _Configuration { get; set; } + public QuestionDbContext(DbContextOptions options, IConfiguration configuration) : base(options) + { + _Configuration = configuration; + } + protected override void OnConfiguring(DbContextOptionsBuilder options) + { + // connect to sql server with connection string from app settings + options.UseSqlServer(_Configuration.GetConnectionString("QuestionConnection")); + } public DbSet Questions { get; set; } public DbSet QuestionTypes { get; set; } public DbSet QuestionsTranslations { get; set; } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/Migrations/20230817215744_InitialQuestion.Designer.cs b/DamageAssesmentApi/DamageAssesment.Api.Questions/Migrations/20230817215744_InitialQuestion.Designer.cs new file mode 100644 index 0000000..4cbbf64 --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.Questions/Migrations/20230817215744_InitialQuestion.Designer.cs @@ -0,0 +1,143 @@ +// +using System; +using DamageAssesment.Api.Questions.Db; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DamageAssesment.Api.Questions.Migrations +{ + [DbContext(typeof(QuestionDbContext))] + [Migration("20230817215744_InitialQuestion")] + partial class InitialQuestion + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DamageAssesment.Api.Questions.Db.Question", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("Comment") + .HasColumnType("bit"); + + b.Property("IsRequired") + .HasColumnType("bit"); + + b.Property("Key") + .HasColumnType("bit"); + + b.Property("QuestionGroup") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("QuestionNumber") + .HasColumnType("int"); + + b.Property("QuestionTypeId") + .HasColumnType("int"); + + b.Property("SurveyId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("QuestionTypeId"); + + b.ToTable("Questions"); + }); + + modelBuilder.Entity("DamageAssesment.Api.Questions.Db.QuestionCategory", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CategoryImage") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CategoryName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("QuestionCategories"); + }); + + modelBuilder.Entity("DamageAssesment.Api.Questions.Db.QuestionType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("TypeText") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("QuestionTypes"); + }); + + modelBuilder.Entity("DamageAssesment.Api.Questions.Db.QuestionsTranslation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Language") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("QuestionId") + .HasColumnType("int"); + + b.Property("QuestionText") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("QuestionsTranslations"); + }); + + modelBuilder.Entity("DamageAssesment.Api.Questions.Db.Question", b => + { + b.HasOne("DamageAssesment.Api.Questions.Db.QuestionType", "QuestionType") + .WithMany() + .HasForeignKey("QuestionTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("QuestionType"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/Migrations/20230817215744_InitialQuestion.cs b/DamageAssesmentApi/DamageAssesment.Api.Questions/Migrations/20230817215744_InitialQuestion.cs new file mode 100644 index 0000000..aaaf018 --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.Questions/Migrations/20230817215744_InitialQuestion.cs @@ -0,0 +1,103 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DamageAssesment.Api.Questions.Migrations +{ + /// + public partial class InitialQuestion : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "QuestionCategories", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + CategoryName = table.Column(type: "nvarchar(max)", nullable: false), + CategoryImage = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_QuestionCategories", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "QuestionsTranslations", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + QuestionId = table.Column(type: "int", nullable: false), + QuestionText = table.Column(type: "nvarchar(max)", nullable: false), + Language = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_QuestionsTranslations", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "QuestionTypes", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + TypeText = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_QuestionTypes", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Questions", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + QuestionTypeId = table.Column(type: "int", nullable: false), + QuestionNumber = table.Column(type: "int", nullable: false), + IsRequired = table.Column(type: "bit", nullable: false), + Comment = table.Column(type: "bit", nullable: false), + Key = table.Column(type: "bit", nullable: false), + SurveyId = table.Column(type: "int", nullable: true), + QuestionGroup = table.Column(type: "nvarchar(max)", nullable: false), + CategoryId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Questions", x => x.Id); + table.ForeignKey( + name: "FK_Questions_QuestionTypes_QuestionTypeId", + column: x => x.QuestionTypeId, + principalTable: "QuestionTypes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Questions_QuestionTypeId", + table: "Questions", + column: "QuestionTypeId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "QuestionCategories"); + + migrationBuilder.DropTable( + name: "Questions"); + + migrationBuilder.DropTable( + name: "QuestionsTranslations"); + + migrationBuilder.DropTable( + name: "QuestionTypes"); + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/Migrations/QuestionDbContextModelSnapshot.cs b/DamageAssesmentApi/DamageAssesment.Api.Questions/Migrations/QuestionDbContextModelSnapshot.cs new file mode 100644 index 0000000..018f296 --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.Questions/Migrations/QuestionDbContextModelSnapshot.cs @@ -0,0 +1,140 @@ +// +using System; +using DamageAssesment.Api.Questions.Db; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DamageAssesment.Api.Questions.Migrations +{ + [DbContext(typeof(QuestionDbContext))] + partial class QuestionDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DamageAssesment.Api.Questions.Db.Question", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("Comment") + .HasColumnType("bit"); + + b.Property("IsRequired") + .HasColumnType("bit"); + + b.Property("Key") + .HasColumnType("bit"); + + b.Property("QuestionGroup") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("QuestionNumber") + .HasColumnType("int"); + + b.Property("QuestionTypeId") + .HasColumnType("int"); + + b.Property("SurveyId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("QuestionTypeId"); + + b.ToTable("Questions"); + }); + + modelBuilder.Entity("DamageAssesment.Api.Questions.Db.QuestionCategory", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CategoryImage") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CategoryName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("QuestionCategories"); + }); + + modelBuilder.Entity("DamageAssesment.Api.Questions.Db.QuestionType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("TypeText") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("QuestionTypes"); + }); + + modelBuilder.Entity("DamageAssesment.Api.Questions.Db.QuestionsTranslation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Language") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("QuestionId") + .HasColumnType("int"); + + b.Property("QuestionText") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("QuestionsTranslations"); + }); + + modelBuilder.Entity("DamageAssesment.Api.Questions.Db.Question", b => + { + b.HasOne("DamageAssesment.Api.Questions.Db.QuestionType", "QuestionType") + .WithMany() + .HasForeignKey("QuestionTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("QuestionType"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.Questions/Program.cs index 073cb10..c47a38d 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Questions/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Questions/Program.cs @@ -26,7 +26,7 @@ builder.Services.AddSwaggerGen(c => }); builder.Services.AddDbContext(option => { - option.UseInMemoryDatabase("Questions"); + option.UseSqlServer("QuestionConnection"); }); var app = builder.Build(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs index 850c165..9f8a3dc 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs @@ -25,7 +25,7 @@ namespace DamageAssesment.Api.Questions.Providers public void SeedData() { - if (!questionDbContext.QuestionsTranslations.Any()) + if (!questionDbContext.QuestionCategories.Any()) { questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 1, QuestionText = "Can You Open ?", Language = "en" }); questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 1, QuestionText = "Peux-tu ouvrir ?", Language = "fr" }); @@ -41,7 +41,7 @@ namespace DamageAssesment.Api.Questions.Providers questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 4, QuestionText = "¿Están inundados los terrenos?", Language = "es" }); questionDbContext.SaveChanges(); } - if (!questionDbContext.Questions.Any()) + if (!questionDbContext.QuestionTypes.Any()) { questionDbContext.Questions.Add(new Db.Question() { QuestionTypeId = 1, SurveyId = 1, QuestionNumber = 1, IsRequired = true, Comment = false, Key = true, CategoryId=1 }); questionDbContext.Questions.Add(new Db.Question() { QuestionTypeId = 1, SurveyId = 1, QuestionNumber = 2, IsRequired = false, Comment = true, Key = false, CategoryId = 1 }); @@ -50,15 +50,14 @@ namespace DamageAssesment.Api.Questions.Providers //questionDbContext.Questions.Add(new Db.Question() { QuestionTypeId = 1, SurveyId = 2, QuestionNumber = 3, IsRequired = true, Comment = false, Key = true, CategoryId = 2 }); questionDbContext.SaveChanges(); } - if (!questionDbContext.QuestionTypes.Any()) + if (!questionDbContext.Questions.Any()) { questionDbContext.QuestionTypes.Add(new Db.QuestionType() { TypeText = "RadioButton" }); questionDbContext.QuestionTypes.Add(new Db.QuestionType() { TypeText = "CheckBox" }); questionDbContext.QuestionTypes.Add(new Db.QuestionType() { TypeText = "TextBox" }); questionDbContext.SaveChanges(); } - - if (!questionDbContext.QuestionCategories.Any()) + if (!questionDbContext.QuestionsTranslations.Any()) { questionDbContext.QuestionCategories.Add(new Db.QuestionCategory() { IconName = "Flooding", IconLibrary= "https://example.com/images/img1.png" }); questionDbContext.QuestionCategories.Add(new Db.QuestionCategory() { IconName = "Electrical", IconLibrary = "https://example.com/images/img2.png" }); @@ -71,21 +70,21 @@ namespace DamageAssesment.Api.Questions.Providers if (!questionDbContext.CategoryTranslations.Any()) { - questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { CategoryId = 1, Title = "Flooding", Language = "en" }); - questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { CategoryId = 2, Title = "Electrical", Language = "en" }); - questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { CategoryId = 3, Title = "Structural", Language = "en" }); - questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { CategoryId = 4, Title = "Utility", Language = "en" }); - questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { CategoryId = 5, Title = "Debris", Language = "en" }); - questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { CategoryId = 1, Title = "Inondation", Language = "fr" }); - questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { CategoryId = 2, Title = "Électrique", Language = "fr" }); - questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { CategoryId = 3, Title = "De construction", Language = "fr" }); - questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { CategoryId = 4, Title = "Utilitaire", Language = "fr" }); - questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { CategoryId = 5, Title = "Débris", Language = "fr" }); - questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { CategoryId = 1, Title = "Inundación", Language = "es" }); - questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { CategoryId = 2, Title = "Eléctrica", Language = "es" }); - questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { CategoryId = 3, Title = "Estructural", Language = "es" }); - questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { CategoryId = 4, Title = "Utilidad", Language = "es" }); - questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { CategoryId = 5, Title = "Escombros", Language = "es" }); + questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { Id = 1, CategoryId = 1, Title = "Flooding", Language = "en" }); + questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { Id = 2, CategoryId = 2, Title = "Electrical", Language = "en" }); + questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { Id = 3, CategoryId = 3, Title = "Structural", Language = "en" }); + questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { Id = 4, CategoryId = 4, Title = "Utility", Language = "en" }); + questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { Id = 5, CategoryId = 5, Title = "Debris", Language = "en" }); + questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { Id = 6, CategoryId = 1, Title = "Inondation", Language = "fr" }); + questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { Id = 7, CategoryId = 2, Title = "Électrique", Language = "fr" }); + questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { Id = 8, CategoryId = 3, Title = "De construction", Language = "fr" }); + questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { Id = 9, CategoryId = 4, Title = "Utilitaire", Language = "fr" }); + questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { Id = 10, CategoryId = 5, Title = "Débris", Language = "fr" }); + questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { Id = 11, CategoryId = 1, Title = "Inundación", Language = "es" }); + questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { Id = 12, CategoryId = 2, Title = "Eléctrica", Language = "es" }); + questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { Id = 13, CategoryId = 3, Title = "Estructural", Language = "es" }); + questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { Id = 14, CategoryId = 4, Title = "Utilidad", Language = "es" }); + questionDbContext.CategoryTranslations.Add(new Db.CategoryTranslation() { Id = 15, CategoryId = 5, Title = "Escombros", Language = "es" }); questionDbContext.SaveChanges(); } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/appsettings.json b/DamageAssesmentApi/DamageAssesment.Api.Questions/appsettings.json index ff5949d..8c0132f 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Questions/appsettings.json +++ b/DamageAssesmentApi/DamageAssesment.Api.Questions/appsettings.json @@ -8,5 +8,8 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "ConnectionStrings": { + "QuestionConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;" + } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.QuestionsTest/DamageAssesment.Api.Questions.Test.csproj b/DamageAssesmentApi/DamageAssesment.Api.QuestionsTest/DamageAssesment.Api.Questions.Test.csproj index fea3dd0..46d6ab1 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.QuestionsTest/DamageAssesment.Api.Questions.Test.csproj +++ b/DamageAssesmentApi/DamageAssesment.Api.QuestionsTest/DamageAssesment.Api.Questions.Test.csproj @@ -10,7 +10,7 @@ - + diff --git a/DamageAssesmentApi/DamageAssesment.Api.Responses/DamageAssesment.Api.Responses.csproj b/DamageAssesmentApi/DamageAssesment.Api.Responses/DamageAssesment.Api.Responses.csproj index 1ee7c58..c704179 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Responses/DamageAssesment.Api.Responses.csproj +++ b/DamageAssesmentApi/DamageAssesment.Api.Responses/DamageAssesment.Api.Responses.csproj @@ -11,6 +11,19 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/DamageAssesmentApi/DamageAssesment.Api.Responses/Db/SurveyResponseDbContext.cs b/DamageAssesmentApi/DamageAssesment.Api.Responses/Db/SurveyResponseDbContext.cs index c1fae2d..cc786ab 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Responses/Db/SurveyResponseDbContext.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Responses/Db/SurveyResponseDbContext.cs @@ -4,12 +4,17 @@ namespace DamageAssesment.Api.Responses.Db { public class SurveyResponseDbContext:DbContext { - public DbSet SurveyResponses { get; set; } - - public SurveyResponseDbContext(DbContextOptions options) : base(options) + private IConfiguration _Configuration { get; set; } + public SurveyResponseDbContext(DbContextOptions options, IConfiguration configuration) : base(options) { - + _Configuration = configuration; } + protected override void OnConfiguring(DbContextOptionsBuilder options) + { + // connect to sql server with connection string from app settings + options.UseSqlServer(_Configuration.GetConnectionString("SurveyResponseConnection")); + } + public DbSet SurveyResponses { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { diff --git a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Migrations/20230817221348_InitialSurveyResponse.Designer.cs b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Migrations/20230817221348_InitialSurveyResponse.Designer.cs new file mode 100644 index 0000000..edec629 --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Migrations/20230817221348_InitialSurveyResponse.Designer.cs @@ -0,0 +1,55 @@ +// +using DamageAssesment.Api.SurveyResponses.Db; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DamageAssesment.Api.SurveyResponses.Migrations +{ + [DbContext(typeof(SurveyResponseDbContext))] + [Migration("20230817221348_InitialSurveyResponse")] + partial class InitialSurveyResponse + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DamageAssesment.Api.SurveyResponses.Db.SurveyResponse", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("EmployeeId") + .IsRequired() + .HasMaxLength(6) + .HasColumnType("nvarchar(6)"); + + b.Property("LocationId") + .IsRequired() + .HasMaxLength(4) + .HasColumnType("nvarchar(4)"); + + b.Property("SurveyId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("SurveyResponses"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Migrations/20230817221348_InitialSurveyResponse.cs b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Migrations/20230817221348_InitialSurveyResponse.cs new file mode 100644 index 0000000..e886ab1 --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Migrations/20230817221348_InitialSurveyResponse.cs @@ -0,0 +1,36 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DamageAssesment.Api.SurveyResponses.Migrations +{ + /// + public partial class InitialSurveyResponse : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "SurveyResponses", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + SurveyId = table.Column(type: "int", nullable: false), + LocationId = table.Column(type: "nvarchar(4)", maxLength: 4, nullable: false), + EmployeeId = table.Column(type: "nvarchar(6)", maxLength: 6, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SurveyResponses", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "SurveyResponses"); + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Migrations/SurveyResponseDbContextModelSnapshot.cs b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Migrations/SurveyResponseDbContextModelSnapshot.cs new file mode 100644 index 0000000..1870d21 --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Migrations/SurveyResponseDbContextModelSnapshot.cs @@ -0,0 +1,52 @@ +// +using DamageAssesment.Api.SurveyResponses.Db; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DamageAssesment.Api.SurveyResponses.Migrations +{ + [DbContext(typeof(SurveyResponseDbContext))] + partial class SurveyResponseDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DamageAssesment.Api.SurveyResponses.Db.SurveyResponse", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("EmployeeId") + .IsRequired() + .HasMaxLength(6) + .HasColumnType("nvarchar(6)"); + + b.Property("LocationId") + .IsRequired() + .HasMaxLength(4) + .HasColumnType("nvarchar(4)"); + + b.Property("SurveyId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("SurveyResponses"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Surveys/DamageAssesment.Api.Surveys.csproj b/DamageAssesmentApi/DamageAssesment.Api.Surveys/DamageAssesment.Api.Surveys.csproj index 6789613..60acab4 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Surveys/DamageAssesment.Api.Surveys.csproj +++ b/DamageAssesmentApi/DamageAssesment.Api.Surveys/DamageAssesment.Api.Surveys.csproj @@ -11,6 +11,17 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Db/SurveysDbContext.cs b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Db/SurveysDbContext.cs index 95c73b0..7b63771 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Db/SurveysDbContext.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Db/SurveysDbContext.cs @@ -4,11 +4,18 @@ namespace DamageAssesment.Api.Surveys.Db { public class SurveysDbContext : DbContext { + private IConfiguration _Configuration { get; set; } + public SurveysDbContext(DbContextOptions options, IConfiguration configuration) : base(options) + { + _Configuration = configuration; + } + public DbSet Surveys { get; set; } public DbSet SurveysTranslation { get; set; } - public SurveysDbContext(DbContextOptions options) : base(options) + protected override void OnConfiguring(DbContextOptionsBuilder options) { - + // connect to sql server with connection string from app settings + options.UseSqlServer(_Configuration.GetConnectionString("SurveyConnection")); } protected override void OnModelCreating(ModelBuilder modelBuilder) { diff --git a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Migrations/20230817220614_InitialSurvey.Designer.cs b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Migrations/20230817220614_InitialSurvey.Designer.cs new file mode 100644 index 0000000..c0f4172 --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Migrations/20230817220614_InitialSurvey.Designer.cs @@ -0,0 +1,57 @@ +// +using System; +using DamageAssesment.Api.Surveys.Db; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DamageAssesment.Api.Survey.Migrations +{ + [DbContext(typeof(SurveysDbContext))] + [Migration("20230817220614_InitialSurvey")] + partial class InitialSurvey + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DamageAssesment.Api.Surveys.Db.Survey", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("EndDate") + .HasColumnType("datetime2"); + + b.Property("IsEnabled") + .HasColumnType("bit"); + + b.Property("StartDate") + .HasColumnType("datetime2"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.ToTable("Surveys"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Migrations/20230817220614_InitialSurvey.cs b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Migrations/20230817220614_InitialSurvey.cs new file mode 100644 index 0000000..1d62693 --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Migrations/20230817220614_InitialSurvey.cs @@ -0,0 +1,38 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DamageAssesment.Api.Survey.Migrations +{ + /// + public partial class InitialSurvey : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Surveys", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Title = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + IsEnabled = table.Column(type: "bit", nullable: false), + StartDate = table.Column(type: "datetime2", nullable: true), + EndDate = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Surveys", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Surveys"); + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Migrations/SurveysDbContextModelSnapshot.cs b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Migrations/SurveysDbContextModelSnapshot.cs new file mode 100644 index 0000000..969a062 --- /dev/null +++ b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Migrations/SurveysDbContextModelSnapshot.cs @@ -0,0 +1,54 @@ +// +using System; +using DamageAssesment.Api.Surveys.Db; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DamageAssesment.Api.Survey.Migrations +{ + [DbContext(typeof(SurveysDbContext))] + partial class SurveysDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DamageAssesment.Api.Surveys.Db.Survey", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("EndDate") + .HasColumnType("datetime2"); + + b.Property("IsEnabled") + .HasColumnType("bit"); + + b.Property("StartDate") + .HasColumnType("datetime2"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.ToTable("Surveys"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Program.cs index fadf4de..178b5fd 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Program.cs @@ -44,7 +44,7 @@ builder.Services.AddSwaggerGen(c => }); builder.Services.AddDbContext(option => { - option.UseInMemoryDatabase("Surveys"); + option.UseSqlServer("SurveyConnection"); }); var app = builder.Build(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Surveys/appsettings.json b/DamageAssesmentApi/DamageAssesment.Api.Surveys/appsettings.json index ff5949d..0057832 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Surveys/appsettings.json +++ b/DamageAssesmentApi/DamageAssesment.Api.Surveys/appsettings.json @@ -8,5 +8,8 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "ConnectionStrings": { + "SurveyConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;" + } } diff --git a/DamageAssesmentApi/docker-compose.sql.yml b/DamageAssesmentApi/docker-compose.sql.yml index e029b38..0c97f83 100644 --- a/DamageAssesmentApi/docker-compose.sql.yml +++ b/DamageAssesmentApi/docker-compose.sql.yml @@ -1,78 +1,13 @@ version: '3.4' services: - answers: - image: santhoshsnair/damageassesmentapianswers:latest - environment: - - ASPNETCORE_ENVIRONMENT=Development - ports: - - "6001:80" - - attachments: - image: santhoshsnair/damageassesmentapiattachments:latest - environment: - - ASPNETCORE_ENVIRONMENT=Development - ports: - - "6002:80" - - - employees: - image: santhoshsnair/damageassesmentapiemployees:latest - environment: - - ASPNETCORE_ENVIRONMENT=Development - ports: - - "6003:80" - - - locations: - image: santhoshsnair/damageassesmentapilocations:latest - environment: - - ASPNETCORE_ENVIRONMENT=Development - ports: - - "6004:80" - - - questions: - image: santhoshsnair/damageassesmentapiquestions:latest - environment: - - ASPNETCORE_ENVIRONMENT=Development - ports: - - "6005:80" - - - responses: - image: santhoshsnair/damageassesmentapisurveyresponses:latest - environment: - - ASPNETCORE_ENVIRONMENT=Development - - services__Answers=http://10.0.0.4:19081/dasapp/answers/ - - services__Locations=http://10.0.0.4:19081/dasapp/locations/ - - services__Questions=http://10.0.0.4:19081/dasapp/questions/ - - services__Employees=http://10.0.0.4:19081/dasapp/employees/ - - services__Attachments=http://10.0.0.4:19081/dasapp/attachments/ - - services__Surveys=http://10.0.0.4:19081/dasapp/survey/ - - ports: - - "6006:80" - - - surveys: - image: santhoshsnair/damageassesmentapisurveys:latest - environment: - - ASPNETCORE_ENVIRONMENT=Development - ports: - - "6007:80" - - - doculinks: - image: santhoshsnair/damageassesmentapidoculinks:latest - environment: - - ASPNETCORE_ENVIRONMENT=Development - ports: - - "6009:80" + sqlserver: image: mcr.microsoft.com/mssql/server:2019-latest environment: - - SA_PASSWORD=your_password + - SA_PASSWORD=Test123 - ACCEPT_EULA=Y ports: - "1433:1433" + volumes: + - ./data:/var/opt/mssql # Mount a volume to persist data