diff --git a/DamageAssesmentApi/DamageAssesment.Api.Answers/Providers/AnswerProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Answers/Providers/AnswerProvider.cs index 291726f..37e2808 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Answers/Providers/AnswerProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Answers/Providers/AnswerProvider.cs @@ -8,19 +8,20 @@ namespace DamageAssesment.Api.Answers.Providers { public class AnswersProvider : IAnswersProvider { - private AnswerDbContext answerDbContext; private ILogger logger; private IMapper mapper; + // Constructor with dependency injection and data seeding public AnswersProvider(AnswerDbContext answerDbContext, ILogger logger, IMapper mapper) { this.answerDbContext = answerDbContext; this.logger = logger; this.mapper = mapper; - SeedData(); + SeedData(); // Seed initial data if the table is empty } + // Get all answers public async Task<(bool IsSuccess, IEnumerable Answers, string ErrorMessage)> GetAnswersAsync() { try @@ -40,9 +41,9 @@ namespace DamageAssesment.Api.Answers.Providers logger?.LogError(ex.ToString()); return (false, null, ex.Message); } - } + // Get an answer by its ID public async Task<(bool IsSuccess, Models.Answer Answer, string ErrorMessage)> GetAnswerByIdAsync(int Id) { try @@ -63,6 +64,8 @@ namespace DamageAssesment.Api.Answers.Providers return (false, null, ex.Message); } } + + // Get answers by survey response ID public async Task<(bool IsSuccess, IEnumerable Answers, string ErrorMessage)> GetAnswersAsync(int surveyResponseId) { try @@ -74,17 +77,17 @@ namespace DamageAssesment.Api.Answers.Providers { var result = mapper.Map, IEnumerable>(respAnswers); return (true, result, null); - } return (false, null, "Not Found"); } catch (Exception ex) { - logger?.LogError(ex.ToString()); return (false, null, ex.Message); } } + + // Get answers by question ID public async Task<(bool IsSuccess, IEnumerable Answers, string ErrorMessage)> GetAnswersByQuestionAsync(int questionId) { try @@ -96,17 +99,17 @@ namespace DamageAssesment.Api.Answers.Providers { var result = mapper.Map, IEnumerable>(respAnswers); return (true, result, null); - } return (false, null, "Not Found"); } catch (Exception ex) { - logger?.LogError(ex.ToString()); return (false, null, ex.Message); } } + + // Create a new answer public async Task<(bool IsSuccess, Models.Answer Answer, string ErrorMessage)> PostAnswerAsync(Models.Answer Answer) { try @@ -120,7 +123,7 @@ namespace DamageAssesment.Api.Answers.Providers var result = mapper.Map(answer); return (true, result, null); } - return (false, null, "Answer is already exits"); + return (false, null, "Answer is already exists"); } catch (Exception ex) { @@ -128,6 +131,8 @@ namespace DamageAssesment.Api.Answers.Providers return (false, null, ex.Message); } } + + // Update an existing answer public async Task<(bool IsSuccess, Models.Answer Answer, string ErrorMessage)> UpdateAnswerAsync(Models.Answer Answer) { try @@ -156,14 +161,14 @@ namespace DamageAssesment.Api.Answers.Providers } catch (Exception ex) { - logger?.LogError(ex.ToString()); - return (false,null, ex.Message); + return (false, null, ex.Message); } } + + // Delete an answer by its ID public async Task<(bool IsSuccess, Models.Answer Answer, string ErrorMessage)> DeleteAnswerAsync(int Id) { - try { Db.Answer answer = answerDbContext.Answers.AsNoTracking().Where(a => a.Id == Id).FirstOrDefault(); @@ -173,30 +178,32 @@ namespace DamageAssesment.Api.Answers.Providers } answerDbContext.Answers.Remove(answer); answerDbContext.SaveChanges(); - return (true, mapper.Map(answer), $"AnswerId {Id} deleted Successfuly"); + return (true, mapper.Map(answer), $"AnswerId {Id} deleted successfully"); } catch (Exception ex) { - logger?.LogError(ex.ToString()); - return (false,null, ex.Message); + return (false, null, ex.Message); } } + + // Check if an answer with a specific ID exists private bool AnswerExists(int id) { return answerDbContext.Answers.AsNoTracking().Count(e => e.Id == id) > 0; } + // Seed initial data if the table is empty public void SeedData() { if (!answerDbContext.Answers.Any()) { 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.Answers.Add(new Db.Answer() { AnswerText = "No", 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 1cd2bcb..c85db9b 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Answers/appsettings.json +++ b/DamageAssesmentApi/DamageAssesment.Api.Answers/appsettings.json @@ -10,6 +10,7 @@ }, "AllowedHosts": "*", "ConnectionStrings": { - "AnswerConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;" + //"AnswerConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;" + "AnswerConnection": "Server=localhost,1433;Database=da_survey_dev;User Id=sa;Password=Password123;TrustServerCertificate=True;" } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Attachments/appsettings.json b/DamageAssesmentApi/DamageAssesment.Api.Attachments/appsettings.json index 1b48365..2533236 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Attachments/appsettings.json +++ b/DamageAssesmentApi/DamageAssesment.Api.Attachments/appsettings.json @@ -14,6 +14,7 @@ "Deletepath": "DMS_Attachments/Deleted" }, "ConnectionStrings": { - "AttachmentConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;" + //"AttachmentConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;" + "AttachmentConnection": "Server=localhost,1433;Database=da_survey_dev;User Id=sa;Password=Password123;TrustServerCertificate=True;" } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks.Test/DoculinkServiceTest.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks.Test/DoculinkServiceTest.cs index b953eeb..14ddaaa 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks.Test/DoculinkServiceTest.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks.Test/DoculinkServiceTest.cs @@ -16,7 +16,7 @@ namespace DamageAssesment.Api.DocuLinks.Test { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); - var mockResponse = await MockData.getNoContentResponse(); + var mockResponse = await MockData.getNoContentResponses(); mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms","en",null)).ReturnsAsync(mockResponse); var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object); @@ -30,7 +30,7 @@ namespace DamageAssesment.Api.DocuLinks.Test { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); - var mockResponse = await MockData.getNoContentResponse(); + var mockResponse = await MockData.getNoContentResponses(); mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms", "en", true)).ReturnsAsync(mockResponse); var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object); @@ -43,7 +43,7 @@ namespace DamageAssesment.Api.DocuLinks.Test { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); - var mockResponse = await MockData.getOkResponse(); + var mockResponse = await MockData.getOkResponses(); mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms","en", null)).ReturnsAsync(mockResponse); var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object); @@ -56,7 +56,7 @@ namespace DamageAssesment.Api.DocuLinks.Test { var mockDocumentService = new Mock(); var mockUploadService = new Mock(); - var mockResponse = await MockData.getOkResponse(); + var mockResponse = await MockData.getOkResponses(); mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms", "en", true)).ReturnsAsync(mockResponse); var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object); @@ -65,6 +65,32 @@ namespace DamageAssesment.Api.DocuLinks.Test Assert.Equal(200, result.StatusCode); } + [Fact(DisplayName = "Get active Documents by linktypeid - Ok case")] + public async Task GetActiveDocumentsLinkTypeIdAsync_ShouldReturnStatusCode200() + { + var mockDocumentService = new Mock(); + var mockUploadService = new Mock(); + var mockResponse = await MockData.getOkResponses(); + mockDocumentService.Setup(service => service.GetdocumentsByLinkTypeIdAsync(null, "en", true)).ReturnsAsync(mockResponse); + + var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object); + var result = (OkObjectResult)await DocumentProvider.GetDocumentsByActiveLinkTypeIdAsync(null, "en"); + + Assert.Equal(200, result.StatusCode); + } + [Fact(DisplayName = "Get active Documents by linktypeid - NoContent Case")] + public async Task GetDocumentsLinkTypeIdAsync_ShouldReturnStatusCode204() + { + var mockDocumentService = new Mock(); + var mockUploadService = new Mock(); + var mockResponse = await MockData.getNoContentResponses(); + mockDocumentService.Setup(service => service.GetdocumentsByLinkTypeIdAsync(null, "en", true)).ReturnsAsync(mockResponse); + + var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object); + var result = (NoContentResult)await DocumentProvider.GetDocumentsByActiveLinkTypeIdAsync(null, ""); + + Assert.Equal(204, result.StatusCode); + } [Fact(DisplayName = "Get Document by Id - Ok case")] public async Task GetDocumentAsync_ShouldReturnStatusCode200() { diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks.Test/MockData.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks.Test/MockData.cs index bd10e4b..23ffae4 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks.Test/MockData.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks.Test/MockData.cs @@ -11,7 +11,7 @@ namespace DamageAssesment.Api.DocuLinks.Test public class MockData { - public static async Task<(bool, List, string)> getOkResponse() + public static async Task<(bool, List, string)> getOkResponses() { List list = new List(); @@ -46,6 +46,48 @@ namespace DamageAssesment.Api.DocuLinks.Test doclinksAttachments= doclinksAttachments }); } + List doculinks = list.GroupBy(a => a.linkTypeId).Select(a => new ResDoculinks() { linkTypeId = a.Key, doculinks = a.ToList() }).ToList(); + return (true, doculinks, null); + } + + + public static async Task<(bool, List, string)> getOkResponse() + { + List list = new List(); + + for (int i = 1; i < 4; i++) + { + Dictionary dicttitle = new Dictionary(); + Dictionary dictdesc = new Dictionary(); + dicttitle.Add("en", "test"); dicttitle.Add("fr", "tester"); + dictdesc.Add("en", "test"); dictdesc.Add("fr", "tester"); + List DocuLinksTranslations = new List(); + DocuLinksTranslations.Add(new DoculinkTranslation() + { + Language = "en", + title = "tel" + i, + description = "Sample" + i + }); + List doclinksAttachments = new List(); + doclinksAttachments.Add(new DoculinkAttachments() + { + docName = "", + Path = "www.google.com", + IsAttachments = false, + CustomOrder = 1 + }); + list.Add(new DocuLinks.Models.ResDoculink() + { + + Id = i, + linkTypeId = i, + IsActive = true, + titles = dicttitle, + description = dictdesc, + CustomOrder = i, + doclinksAttachments = doclinksAttachments + }); + } return (true, list, null); } public static async Task<(bool, DocuLinks.Models.ResDoculink, string)> getOkResponse(int Id) @@ -64,6 +106,11 @@ namespace DamageAssesment.Api.DocuLinks.Test { return (false, null, "Not Found"); } + public static async Task<(bool, IEnumerable, string)> getNoContentResponses() + { + IEnumerable list = new List(); + return (false, list, null); + } public static async Task<(bool, IEnumerable, string)> getNoContentResponse() { IEnumerable list = new List(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Controllers/DoculinkController.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Controllers/DoculinkController.cs index cfbd508..99d00a8 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Controllers/DoculinkController.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Controllers/DoculinkController.cs @@ -136,7 +136,21 @@ namespace DamageAssesment.Api.DocuLinks.Controllers } return NoContent(); } - + /// + /// Get all active Doculink. + /// + [Route("doculinks/active/{linktypeid:int}")] + [Route("doculinks/active/{linktypeid:int}/{language:alpha}")] + [HttpGet] + public async Task GetDocumentsByActiveLinkTypeIdAsync(int? linktypeid, string? language) + { + var result = await this.documentsProvider.GetdocumentsByLinkTypeIdAsync(linktypeid, language, true); + if (result.IsSuccess) + { + return Ok(result.documents); + } + return NoContent(); + } /// /// Get a Doculink by id. /// diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/DamageAssesment.Api.DocuLinks.csproj b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/DamageAssesment.Api.DocuLinks.csproj index 2e8659c..45347ee 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/DamageAssesment.Api.DocuLinks.csproj +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/DamageAssesment.Api.DocuLinks.csproj @@ -1,4 +1,4 @@ - + net6.0 diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Interfaces/IDoculinkProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Interfaces/IDoculinkProvider.cs index f4f9c84..6d271fd 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Interfaces/IDoculinkProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Interfaces/IDoculinkProvider.cs @@ -7,7 +7,8 @@ namespace DamageAssesment.Api.DocuLinks.Interfaces Task<(bool IsSuccess, Models.ResDoculink Document, string ErrorMessage)> GetDocumentAsync(int id, string? linktype, string? language); Task<(bool IsSuccess, Models.Doculink Document, string ErrorMessage)> GetDocumentByidAsync(int id); // Task<(bool IsSuccess, IEnumerable documents, string ErrorMessage)> GetDocumnetsAsync(string? language); - Task<(bool IsSuccess, IEnumerable documents, string ErrorMessage)> GetdocumentsByLinkAsync(string? linkType, string? language, bool? isactive); + Task<(bool IsSuccess, IEnumerable documents, string ErrorMessage)> GetdocumentsByLinkAsync(string? linkType, string? language, bool? isactive); + Task<(bool IsSuccess, IEnumerable documents, string ErrorMessage)> GetdocumentsByLinkTypeIdAsync(int? linkTypeId, string? language, bool? isactive); Task<(bool IsSuccess, Models.ResDoculink Document, string ErrorMessage)> PostDocumentAsync(Models.Doculink Document); Task<(bool IsSuccess, Models.ResDoculink Document, string ErrorMessage)> UpdateDocumentAsync(int id,Models.Doculink Document); Task<(bool IsSuccess, Models.ResDoculink Document, string ErrorMessage)> DeleteDocumentAsync(int id); diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/20230828165655_InitialDocumentCreate.Designer.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/20230828165655_InitialDocumentCreate.Designer.cs deleted file mode 100644 index 8072057..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/20230828165655_InitialDocumentCreate.Designer.cs +++ /dev/null @@ -1,95 +0,0 @@ -// -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("20230828165655_InitialDocumentCreate")] - partial class InitialDocumentCreate - { - /// - 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.Document", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("IsActive") - .HasColumnType("bit"); - - b.Property("Path") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("dateCreated") - .HasColumnType("datetime2"); - - b.Property("dateUpdated") - .HasColumnType("datetime2"); - - b.Property("description") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("docName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("linkTypeId") - .HasColumnType("int"); - - b.Property("title") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("url") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Documents"); - }); - - modelBuilder.Entity("DamageAssesment.Api.DocuLinks.Db.LinkType", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("IsActive") - .HasColumnType("bit"); - - b.Property("TypeText") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("LinkTypes"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/20230828165655_InitialDocumentCreate.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/20230828165655_InitialDocumentCreate.cs deleted file mode 100644 index 741574e..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/20230828165655_InitialDocumentCreate.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace DamageAssesment.Api.DocuLinks.Migrations -{ - /// - public partial class InitialDocumentCreate : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Documents", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - title = table.Column(type: "nvarchar(max)", nullable: false), - linkTypeId = table.Column(type: "int", nullable: false), - description = table.Column(type: "nvarchar(max)", nullable: false), - docName = table.Column(type: "nvarchar(max)", nullable: false), - url = table.Column(type: "nvarchar(max)", nullable: false), - Path = table.Column(type: "nvarchar(max)", nullable: false), - IsActive = table.Column(type: "bit", nullable: false), - dateCreated = table.Column(type: "datetime2", nullable: false), - dateUpdated = table.Column(type: "datetime2", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Documents", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "LinkTypes", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - TypeText = table.Column(type: "nvarchar(max)", nullable: false), - IsActive = table.Column(type: "bit", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_LinkTypes", x => x.Id); - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Documents"); - - migrationBuilder.DropTable( - name: "LinkTypes"); - } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/20230830200432_DocumentTranslation.Designer.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/20230830200432_DocumentTranslation.Designer.cs deleted file mode 100644 index b9006ba..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/20230830200432_DocumentTranslation.Designer.cs +++ /dev/null @@ -1,118 +0,0 @@ -// -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("20230830200432_DocumentTranslation")] - partial class DocumentTranslation - { - /// - 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.Document", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("IsActive") - .HasColumnType("bit"); - - b.Property("Path") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("dateCreated") - .HasColumnType("datetime2"); - - 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 => - { - 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("IsActive") - .HasColumnType("bit"); - - b.Property("IsAttachment") - .HasColumnType("bit"); - - b.Property("TypeText") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("LinkTypes"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/20230830200432_DocumentTranslation.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/20230830200432_DocumentTranslation.cs deleted file mode 100644 index d639539..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/20230830200432_DocumentTranslation.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace DamageAssesment.Api.DocuLinks.Migrations -{ - /// - public partial class DocumentTranslation : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "description", - table: "Documents"); - - migrationBuilder.DropColumn( - name: "title", - table: "Documents"); - - migrationBuilder.AddColumn( - name: "IsAttachment", - table: "LinkTypes", - type: "bit", - nullable: false, - defaultValue: false); - - migrationBuilder.CreateTable( - name: "DocumentsTranslations", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - DocumentId = table.Column(type: "int", nullable: false), - title = table.Column(type: "nvarchar(max)", nullable: false), - description = table.Column(type: "nvarchar(max)", nullable: false), - Language = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_DocumentsTranslations", x => x.Id); - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "DocumentsTranslations"); - - migrationBuilder.DropColumn( - name: "IsAttachment", - table: "LinkTypes"); - - migrationBuilder.AddColumn( - name: "description", - table: "Documents", - type: "nvarchar(max)", - nullable: false, - defaultValue: ""); - - migrationBuilder.AddColumn( - name: "title", - table: "Documents", - type: "nvarchar(max)", - nullable: false, - defaultValue: ""); - } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/20230926163717_doculinkUpdate.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/20230926163717_doculinkUpdate.cs deleted file mode 100644 index f5df82a..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Migrations/20230926163717_doculinkUpdate.cs +++ /dev/null @@ -1,144 +0,0 @@ -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/Models/Doculink.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Models/Doculink.cs index 6fb538b..33259e1 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Models/Doculink.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Models/Doculink.cs @@ -7,6 +7,11 @@ namespace DamageAssesment.Api.DocuLinks.Models { public List documentsTranslations { get; set; } } + public class ResDoculinks + { + public int linkTypeId { get; set; } + public List doculinks { get; set; } + } public class ResDoculink:BaseDoculink { public object titles { get; set; } diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/DoculinkProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/DoculinkProvider.cs index 9d8eae8..81535ab 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/DoculinkProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/DoculinkProvider.cs @@ -6,8 +6,10 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Internal; using System; +using System.Collections.Immutable; using System.Diagnostics.Eventing.Reader; using System.Reflection.Metadata; +using System.Xml; using System.Xml.Linq; namespace DamageAssesment.Api.DocuLinks.Providers @@ -63,16 +65,20 @@ namespace DamageAssesment.Api.DocuLinks.Providers int counter = 0; for (int i = 1; i <= 4; i++) { - FileModel fileModel = new FileModel() { url = "www.google"+i+".com", IsAttachments = false, CustomOrder = 1 }; - ReqDoculink documentInfo = new ReqDoculink() { linkTypeId = i,CustomOrder=i, Files = new List() { fileModel } }; - List documents = new List(); - documents.Add(new Db.DoculinkTranslation { DocumentId = i, title = "test" + i, description = "test" + i, Language = "en" }); - documents.Add(new Db.DoculinkTranslation { DocumentId = i, title = "prueba" + i, description = "prueba" + i, Language = "es" }); - documents.Add(new Db.DoculinkTranslation { DocumentId = i, title = "test" + i, description = "test" + i, Language = "fr" }); + int linkTypeId = 2; + FileModel fileModel = new FileModel(); + if (i < 3) + { + linkTypeId = 1; + + fileModel = new FileModel() { FileName = "Sample" + i, FileExtension = ".txt", FileContent = "c2FtcGxl", IsAttachments = true, CustomOrder = 1 }; + } + else + fileModel = new FileModel() { url = "www.google" + i + ".com", IsAttachments = false, CustomOrder = 1 }; + ReqDoculink documentInfo = new ReqDoculink() { linkTypeId = linkTypeId, CustomOrder = i, Files = new List() { fileModel } }; Models.Doculink document = uploadservice.UploadDocument(counter, documentInfo); DocumentDbContext.Documents.Add(mapper.Map(document)); DocumentDbContext.SaveChanges(); - DocumentDbContext.DocumentsTranslations.AddRange(documents); var dbattachments = mapper.Map, List>(document.doclinksAttachments); dbattachments.ForEach(a => a.DocumentId = i); DocumentDbContext.DoclinksAttachments.AddRange(dbattachments); @@ -80,6 +86,34 @@ namespace DamageAssesment.Api.DocuLinks.Providers counter++; } } + if (!DocumentDbContext.DocumentsTranslations.Any()) + { + string[] titles = { + "Mobile App Damage Assessment Instructions", + "PC Damage Assessment Instructions", + "Emergency Evacuation centers", + "Mobile App Damage Assessment Instructions" }; + string[] esTranslations = { + "Instrucciones de Evaluación de Daños de la Aplicación Móvil", + "Instrucciones de Evaluación de Daños del PC", + "Centros de Evacuación de Emergencia", + "Instrucciones de Evaluación de Daños de la Aplicación Móvil" }; + string[] frTranslations = { + "Instructions d'Évaluation des Dommages de l'Application Mobile", + "Instructions d'Évaluation des Dommages du PC", + "Centres d'Évacuation d'Urgence", + "Instructions d'Évaluation des Dommages de l'Application Mobile" }; + List documents = new List(); + for (int i = 0; i < 4; i++) + { + documents.Add(new Db.DoculinkTranslation { DocumentId = i + 1, title = titles[i], description = titles[i], Language = "en" }); + documents.Add(new Db.DoculinkTranslation { DocumentId = i + 1, title = esTranslations[i], description = esTranslations[i], Language = "es" }); + documents.Add(new Db.DoculinkTranslation { DocumentId = i + 1, title = frTranslations[i], description = frTranslations[i], Language = "fr" }); + } + DocumentDbContext.DocumentsTranslations.AddRange(documents); + DocumentDbContext.SaveChanges(); + } + } public List GetDocumentTranslations(int id, string? language) { @@ -136,7 +170,44 @@ namespace DamageAssesment.Api.DocuLinks.Providers MultiLanguage = dicttitle; return MultiLanguage; } - public async Task<(bool IsSuccess, IEnumerable documents, string ErrorMessage)> GetdocumentsByLinkAsync(string? linkType, string? language, bool? isactive) + + public async Task<(bool IsSuccess, IEnumerable documents, string ErrorMessage)> GetdocumentsByLinkTypeIdAsync(int? linkTypeId, string? language, bool? isactive) + { + + try + { + logger?.LogInformation("Query Question"); + var documents = new List(); + if (linkTypeId==null) + documents = await DocumentDbContext.Documents.AsNoTracking().Where(q => (isactive == null || q.IsActive == isactive.Value)).ToListAsync(); + else + documents = await DocumentDbContext.Documents.AsNoTracking().Where(q => (isactive == null || q.IsActive == isactive.Value) && + q.linkTypeId == linkTypeId.Value).ToListAsync(); + if (documents != null) + { + var result = mapper.Map, List>(documents); + foreach (var item in result) + { + var multilan = CreateMultiLanguageObject(GetDocumentTranslations(item.Id, language)); + item.titles = multilan.titles; + item.description = multilan.description; + item.linktypes = CreateMultiLanguageLinkTypeObject(GetLinkTypeTranslations(item.linkTypeId, language)); + item.doclinksAttachments = mapper.Map, List>( + DocumentDbContext.DoclinksAttachments.AsNoTracking().Where(a => a.DocumentId == item.Id).ToList()); + } + List doculinks = result.GroupBy(a => a.linkTypeId).Select(a => new ResDoculinks() { linkTypeId = a.Key, doculinks = a.ToList() }).ToList(); + return (true, doculinks, null); + } + return (false, null, "Not found"); + } + catch (Exception ex) + { + logger?.LogError(ex.ToString()); + return (false, null, ex.Message); + } + + } + public async Task<(bool IsSuccess, IEnumerable documents, string ErrorMessage)> GetdocumentsByLinkAsync(string? linkType, string? language, bool? isactive) { try @@ -160,7 +231,8 @@ namespace DamageAssesment.Api.DocuLinks.Providers item.doclinksAttachments = mapper.Map, List>( DocumentDbContext.DoclinksAttachments.AsNoTracking().Where(a => a.DocumentId == item.Id).ToList()); } - return (true, result, null); + List doculinks = result.GroupBy(a => a.linkTypeId).Select(a => new ResDoculinks() { linkTypeId = a.Key, doculinks = a.ToList() }).ToList(); + return (true, doculinks, null); } return (false, null, "Not found"); } diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/appsettings.json b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/appsettings.json index 0006765..6ce12d8 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/appsettings.json +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/appsettings.json @@ -7,7 +7,8 @@ }, "AllowedHosts": "*", "ConnectionStrings": { - "DoculinConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;" + //"DoculinConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;", + "DoculinConnection": "Server=localhost,1433;Database=da_survey_dev;User Id=sa;Password=Password123;TrustServerCertificate=True;" }, "Fileupload": { "folderpath": "DASA_Documents/Active", diff --git a/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230817213656_InitialEmployee.Designer.cs b/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230817213656_InitialEmployee.Designer.cs deleted file mode 100644 index d747ab1..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230817213656_InitialEmployee.Designer.cs +++ /dev/null @@ -1,64 +0,0 @@ -// -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/20230913164315_employeeupdate.cs b/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230913164315_employeeupdate.cs deleted file mode 100644 index 8b5ff7f..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230913164315_employeeupdate.cs +++ /dev/null @@ -1,48 +0,0 @@ -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 deleted file mode 100644 index 35e45ac..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230913170055_updatedemployee_id.Designer.cs +++ /dev/null @@ -1,72 +0,0 @@ -// -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 deleted file mode 100644 index 8b004ed..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.Employees/Migrations/20230913170055_updatedemployee_id.cs +++ /dev/null @@ -1,22 +0,0 @@ -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/Providers/EmployeesProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Employees/Providers/EmployeesProvider.cs index 2aa0551..b1741be 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Employees/Providers/EmployeesProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Employees/Providers/EmployeesProvider.cs @@ -19,7 +19,7 @@ namespace DamageAssesment.Api.Employees.Providers this.EmployeeDbContext = EmployeeDbContext; this.logger = logger; this.mapper = mapper; - SeedData(); + // SeedData(); } public async Task<(bool IsSuccess, IEnumerable Employees, string ErrorMessage)> GetEmployeesAsync() @@ -156,12 +156,12 @@ namespace DamageAssesment.Api.Employees.Providers { if (!EmployeeDbContext.Employees.Any()) { - 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.Employees.Add(new Db.Employee() { EmployeeCode = "10101", Name = "David", Email = "david@gmail.com", OfficePhoneNumber = "12345678", BirthDate = DateTime.Now.AddYears(-18), IsActive = true, PreferredLanguage = "en" }); + EmployeeDbContext.Employees.Add(new Db.Employee() { EmployeeCode = "20202", 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.SaveChanges(); } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Employees/appsettings.json b/DamageAssesmentApi/DamageAssesment.Api.Employees/appsettings.json index e4445e8..d016799 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Employees/appsettings.json +++ b/DamageAssesmentApi/DamageAssesment.Api.Employees/appsettings.json @@ -15,6 +15,7 @@ "endpoint3": "xxx" }, "ConnectionStrings": { - "EmployeeConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;" + //"EmployeeConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;", + "EmployeeConnection": "Server=localhost,1433;Database=da_survey_dev;User Id=sa;Password=Password123;TrustServerCertificate=True;" } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Locations/Providers/LocationsProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Locations/Providers/LocationsProvider.cs index 8c4adce..198a765 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Locations/Providers/LocationsProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Locations/Providers/LocationsProvider.cs @@ -17,7 +17,7 @@ namespace DamageAssesment.Api.Locations.Providers this.locationDbContext = locationDbContext; this.logger = logger; this.mapper = mapper; - SeedData(); + // SeedData(); } public async Task<(bool IsSuccess, IEnumerable Locations, string ErrorMessage)> GetLocationsAsync() @@ -139,12 +139,13 @@ namespace DamageAssesment.Api.Locations.Providers { if (!locationDbContext.Locations.Any()) { - 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() { 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.Locations.Add(new Db.Location() { LocationCode = "0091", RegionId = 5, Name = "BOB GRAHAM EDUCATION CENTER", MaintenanceCenter = "1", SchoolType = "K8" }); + locationDbContext.Locations.Add(new Db.Location() { LocationCode = "0092", RegionId = 1, Name = "NORMAN S. EDELCUP/SUNNY ISLES BEACH K-8", MaintenanceCenter = "1", SchoolType = "K8" }); + locationDbContext.Locations.Add(new Db.Location() { LocationCode = "7511", RegionId = 4, Name = "MIAMI SPRINGS SHS", MaintenanceCenter = "2", SchoolType = "S" }); + //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.SaveChanges(); } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Locations/Providers/RegionsProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Locations/Providers/RegionsProvider.cs index 7e140ab..2eb72ac 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Locations/Providers/RegionsProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Locations/Providers/RegionsProvider.cs @@ -16,7 +16,7 @@ namespace DamageAssesment.Api.Locations.Providers this.locationDbContext = regionDbContext; this.logger = logger; this.mapper = mapper; - SeedData(); + // SeedData(); } public async Task<(bool IsSuccess, Models.Region Region, string ErrorMessage)> GetRegionByIdAsync(int Id) @@ -166,8 +166,10 @@ namespace DamageAssesment.Api.Locations.Providers if (!locationDbContext.Regions.Any()) { locationDbContext.Regions.Add(new Db.Region() { Name = "North", Abbreviation = "N" }); - locationDbContext.Regions.Add(new Db.Region() { Name = "South", Abbreviation = "S" }); locationDbContext.Regions.Add(new Db.Region() { Name = "Central", Abbreviation = "C" }); + locationDbContext.Regions.Add(new Db.Region() { Name = "South", Abbreviation = "S" }); + locationDbContext.Regions.Add(new Db.Region() { Name = "Charter Schools", Abbreviation = "CS" }); + locationDbContext.Regions.Add(new Db.Region() { Name = "Alternate and Special Centers", Abbreviation = "AC" }); locationDbContext.SaveChanges(); } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Locations/appsettings.json b/DamageAssesmentApi/DamageAssesment.Api.Locations/appsettings.json index 37d1aef..04f8480 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Locations/appsettings.json +++ b/DamageAssesmentApi/DamageAssesment.Api.Locations/appsettings.json @@ -10,6 +10,7 @@ }, "AllowedHosts": "*", "ConnectionStrings": { - "LocationConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;" + //"LocationConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;", + "LocationConnection": "Server=localhost,1433;Database=da_survey_dev;User Id=sa;Password=Password123;TrustServerCertificate=True;" } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs index 9f8a3dc..baad532 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs @@ -19,38 +19,12 @@ namespace DamageAssesment.Api.Questions.Providers this.questionDbContext = questionDbContext; this.logger = logger; this.mapper = mapper; - SeedData(); + // SeedData(); } public void SeedData() { - - 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" }); - questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 1, QuestionText = "Puedes abrir ?", Language = "es" }); - questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 2, QuestionText = "Are the grounds flodded ?", Language = "en" }); - questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 2, QuestionText = "Les terrains sont-ils inondés ?", Language = "fr" }); - questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 2, QuestionText = "¿Están inundados los terrenos?", Language = "es" }); - questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 3, QuestionText = "Is the access blocked by flooding ?", Language = "en" }); - questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 3, QuestionText = "L'accès est-il bloqué par les inondations ?", Language = "fr" }); - questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 3, QuestionText = "¿El acceso está bloqueado por inundaciones?", Language = "es" }); - questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 4, QuestionText = "Are the grounds flodded ?", Language = "en" }); - questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 4, QuestionText = "Les terrains sont-ils inondés ?", Language = "fr" }); - questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 4, QuestionText = "¿Están inundados los terrenos?", Language = "es" }); - questionDbContext.SaveChanges(); - } 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 }); - questionDbContext.Questions.Add(new Db.Question() { QuestionTypeId = 1, SurveyId = 2, QuestionNumber = 1, IsRequired = true, Comment = false, Key = true, CategoryId = 1 }); - questionDbContext.Questions.Add(new Db.Question() { QuestionTypeId = 1, SurveyId = 2, QuestionNumber = 2, IsRequired = false, Comment = true, Key = false, CategoryId = 1 }); - //questionDbContext.Questions.Add(new Db.Question() { QuestionTypeId = 1, SurveyId = 2, QuestionNumber = 3, IsRequired = true, Comment = false, Key = true, CategoryId = 2 }); - questionDbContext.SaveChanges(); - } - if (!questionDbContext.Questions.Any()) { questionDbContext.QuestionTypes.Add(new Db.QuestionType() { TypeText = "RadioButton" }); questionDbContext.QuestionTypes.Add(new Db.QuestionType() { TypeText = "CheckBox" }); @@ -59,7 +33,7 @@ namespace DamageAssesment.Api.Questions.Providers } 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 = "Flooding", IconLibrary = "https://example.com/images/img1.png" }); questionDbContext.QuestionCategories.Add(new Db.QuestionCategory() { IconName = "Electrical", IconLibrary = "https://example.com/images/img2.png" }); questionDbContext.QuestionCategories.Add(new Db.QuestionCategory() { IconName = "Structural", IconLibrary = "https://example.com/images/img3.png" }); questionDbContext.QuestionCategories.Add(new Db.QuestionCategory() { IconName = "Utility", IconLibrary = "https://example.com/images/img4.png" }); @@ -69,22 +43,52 @@ 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.SaveChanges(); + } - 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" }); + if (!questionDbContext.Questions.Any()) + { + var question1 = new Db.Question() { QuestionTypeId = 1, SurveyId = 1, QuestionNumber = 1, IsRequired = true, Comment = false, Key = true, CategoryId = 1 }; + var question2 = new Db.Question() { QuestionTypeId = 1, SurveyId = 1, QuestionNumber = 2, IsRequired = false, Comment = true, Key = false, CategoryId = 1 }; + var question3 = new Db.Question() { QuestionTypeId = 1, SurveyId = 2, QuestionNumber = 1, IsRequired = true, Comment = false, Key = true, CategoryId = 1 }; + var question4 = new Db.Question() { QuestionTypeId = 1, SurveyId = 2, QuestionNumber = 2, IsRequired = false, Comment = true, Key = false, CategoryId = 1 }; + + questionDbContext.Questions.Add(question1); + questionDbContext.Questions.Add(question2); + questionDbContext.Questions.Add(question3); + questionDbContext.Questions.Add(question4); + questionDbContext.SaveChanges(); + } + + if (!questionDbContext.QuestionsTranslations.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" }); + questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 1, QuestionText = "Puedes abrir ?", Language = "es" }); + questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 2, QuestionText = "Are the grounds flooded ?", Language = "en" }); + questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 2, QuestionText = "Les terrains sont-ils inondés ?", Language = "fr" }); + questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 2, QuestionText = "¿Están inundados los terrenos?", Language = "es" }); + questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 3, QuestionText = "Is the access blocked by flooding ?", Language = "en" }); + questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 3, QuestionText = "L'accès est-il bloqué par les inondations ?", Language = "fr" }); + questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 3, QuestionText = "¿El acceso está bloqueado por inundaciones?", Language = "es" }); + questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 4, QuestionText = "Are the grounds flooded ?", Language = "en" }); + questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 4, QuestionText = "Les terrains sont-ils inondés ?", Language = "fr" }); + questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { QuestionId = 4, QuestionText = "¿Están inundados los terrenos?", Language = "es" }); questionDbContext.SaveChanges(); } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/appsettings.json b/DamageAssesmentApi/DamageAssesment.Api.Questions/appsettings.json index 8c0132f..b901439 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Questions/appsettings.json +++ b/DamageAssesmentApi/DamageAssesment.Api.Questions/appsettings.json @@ -10,6 +10,7 @@ }, "AllowedHosts": "*", "ConnectionStrings": { - "QuestionConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;" + //"QuestionConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;" + "QuestionConnection": "Server=localhost,1433;Database=da_survey_dev;User Id=sa;Password=Password123;TrustServerCertificate=True;" } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Responses/Db/SurveyResponseDbContext.cs b/DamageAssesmentApi/DamageAssesment.Api.Responses/Db/SurveyResponseDbContext.cs index cc786ab..37acddf 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Responses/Db/SurveyResponseDbContext.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Responses/Db/SurveyResponseDbContext.cs @@ -12,7 +12,7 @@ namespace DamageAssesment.Api.Responses.Db protected override void OnConfiguring(DbContextOptionsBuilder options) { // connect to sql server with connection string from app settings - options.UseSqlServer(_Configuration.GetConnectionString("SurveyResponseConnection")); + options.UseSqlServer(_Configuration.GetConnectionString("ResponsesConnection")); } public DbSet SurveyResponses { get; set; } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Responses/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.Responses/Program.cs index f7b7216..1641e75 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Responses/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Responses/Program.cs @@ -44,7 +44,7 @@ builder.Services.AddSwaggerGen(c => }); builder.Services.AddDbContext(option => { - option.UseInMemoryDatabase("Responses"); + option.UseSqlServer("ResponsesConnection"); }); var app = builder.Build(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Responses/Providers/SurveyResponsesProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Responses/Providers/SurveyResponsesProvider.cs index 0631932..5278c5c 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Responses/Providers/SurveyResponsesProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Responses/Providers/SurveyResponsesProvider.cs @@ -31,23 +31,24 @@ namespace DamageAssesment.Api.Responses.Providers this.questionServiceProvider = questionServiceProvider; this.surveyServiceProvider = surveyServiceProvider; this.mapper = mapper; - seedData(); + SeedData(); } - private void seedData() + public void SeedData() { + // Check if SurveyResponses exist, if not, seed data if (!surveyResponseDbContext.SurveyResponses.Any()) { + + // Create and save SurveyResponse records with references to existing Employee and Location records surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { SurveyId = 1, EmployeeId = 1, LocationId = 1, ClientDevice = "Mobile", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "true", CreatedDate = DateTime.Now }); - surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { SurveyId = 2, EmployeeId = 2, LocationId = 2, ClientDevice = "Desktop", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "true", CreatedDate = DateTime.Now }); - //surveyResponseDbContext.Responses.Add(new Db.SurveyResponse { Id = 3, SurveyId = 3, EmployeeId = 4, LocationId = 1, ClientDevice = "Mobile", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "true", CreatedDate = DateTime.Now }); - //surveyResponseDbContext.Responses.Add(new Db.SurveyResponse { Id = 4, SurveyId = 4, EmployeeId = 1, LocationId = 2, ClientDevice = "Desktop", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "false", CreatedDate = DateTime.Now }); - //surveyResponseDbContext.Responses.Add(new Db.SurveyResponse { Id = 6, SurveyId = 1, EmployeeId = 4, LocationId = 2, ClientDevice = "Desktop", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "true", CreatedDate = DateTime.Now }); - //surveyResponseDbContext.Responses.Add(new Db.SurveyResponse { Id = 7, SurveyId = 1, EmployeeId = 4, LocationId = 3, ClientDevice = "Desktop", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "false", CreatedDate = DateTime.Now }); + surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { SurveyId = 1, EmployeeId = 2, LocationId = 2, ClientDevice = "Mobile", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "true", CreatedDate = DateTime.Now }); + surveyResponseDbContext.SaveChanges(); } } + public async Task<(bool IsSuccess, dynamic Answers, string ErrorMessage)> GetAnswersByRegionAsync(int surveyId, int employeeid) { try diff --git a/DamageAssesmentApi/DamageAssesment.Api.Responses/appsettings.json b/DamageAssesmentApi/DamageAssesment.Api.Responses/appsettings.json index 914d671..6f72262 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Responses/appsettings.json +++ b/DamageAssesmentApi/DamageAssesment.Api.Responses/appsettings.json @@ -16,13 +16,14 @@ // "AttachmentUrlBase": "http://localhost:5243", // "SurveyUrlBase": "http://localhost:5009" //}, + //Endpoints for docker-container "EndPointSettings": { "AnswerUrlBase": "http://damageassesment.api.answers:80", "LocationUrlBase": "http://damageassesment.api.locations:80", "QuestionUrlBase": "http://damageassesment.api.questions:80", "EmployeeUrlBase": "http://damageassesment.api.employees:80", "AttachmentUrlBase": "http://damageassesment.api.attachments:80", - "SurveyUrlBase": "http://damageassesment.api.survey:80" + "SurveyUrlBase": "http://damageassesment.api.surveys:80" }, "RessourceSettings": { @@ -38,5 +39,9 @@ "AnswerByResponse": "/answers/byresponse/{0}", "Location": "/locations", "Region": "/regions" + }, + "ConnectionStrings": { + //"SurveyResponseConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;" + "ResponsesConnection": "Server=localhost,1433;Database=da_survey_dev;User Id=sa;Password=Password123;TrustServerCertificate=True;" } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Providers/SurveysProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Providers/SurveysProvider.cs index 3d08544..2d6cbc9 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Providers/SurveysProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Providers/SurveysProvider.cs @@ -18,39 +18,44 @@ namespace DamageAssesment.Api.Surveys.Providers this.surveyDbContext = surveysDbContext; this.logger = logger; this.mapper = mapper; - seedData(); + //seedData(); } + // Method to seed initial data into the database public void seedData() { if (!surveyDbContext.Surveys.Any()) { - surveyDbContext.Surveys.Add(new Db.Survey {IsEnabled = true, StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(90), CreatedDate = DateTime.Now }); - surveyDbContext.Surveys.Add(new Db.Survey { IsEnabled = true, StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(90), CreatedDate = DateTime.Now }); - //surveyDbContext.Surveys.Add(new Db.Survey { Id = 2, IsEnabled = true, StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(90), CreatedDate = DateTime.Now }); - //surveyDbContext.Surveys.Add(new Db.Survey { Id = 3, IsEnabled = true, StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(90), CreatedDate = DateTime.Now }); - surveyDbContext.SaveChangesAsync(); - } + var survey1 = new Db.Survey { IsEnabled = true, StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(90), CreatedDate = DateTime.Now }; + var survey2 = new Db.Survey { IsEnabled = true, StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(90), CreatedDate = DateTime.Now }; + var survey3 = new Db.Survey { IsEnabled = false, StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(90), CreatedDate = DateTime.Now }; - if (!surveyDbContext.SurveysTranslation.Any()) - { - surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = 1, Language = "en", Title = "Impact of Tropical Storm Emily on Florida's Economy" }); - surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = 1, Language = "es", Title = "Impacto de la tormenta tropical Emily en la economía de Florida" }); - surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = 1, Language = "fr", Title = "Impact de la tempête tropicale Emily sur l'économie de la Floride" }); + surveyDbContext.Surveys.Add(survey1); + surveyDbContext.Surveys.Add(survey2); + surveyDbContext.Surveys.Add(survey3); + surveyDbContext.SaveChanges(); - surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = 2, Language = "en", Title = "Hurricane Andrew Aftermath Survey" }); - surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = 2, Language = "es", Title = "Encuesta sobre las secuelas del huracán Andrew" }); - surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = 2, Language = "fr", Title = "Enquête sur les conséquences de l'ouragan Andrew" }); + if (!surveyDbContext.SurveysTranslation.Any()) + { + surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey1.Id, Language = "en", Title = "Impact of Tropical Storm Emily on Florida's Economy" }); + surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey1.Id, Language = "es", Title = "Impacto de la tormenta tropical Emily en la economía de Florida" }); + surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey1.Id, Language = "fr", Title = "Impact de la tempête tropicale Emily sur l'économie de la Floride" }); - //surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { Id = 7, SurveyId = 3, Language = "en", Title = "Public Perception of Hurricane Michael's Response" }); - //surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { Id = 8, SurveyId = 3, Language = "es", Title = "Percepción pública de la respuesta del huracán Michael" }); - //surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { Id = 9, SurveyId = 3, Language = "fr", Title = "Perception du public de la réponse de l'ouragan Michael" }); + surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey2.Id, Language = "en", Title = "Hurricane Andrew Aftermath Survey" }); + surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey2.Id, Language = "es", Title = "Encuesta sobre las secuelas del huracán Andrew" }); + surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey2.Id, Language = "fr", Title = "Enquête sur les conséquences de l'ouragan Andrew" }); + + surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey3.Id, Language = "en", Title = "Hurricane Idalia Aftermath Survey" }); + surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey3.Id, Language = "es", Title = "Encuesta sobre las secuelas del huracán Idalia" }); + surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = survey3.Id, Language = "fr", Title = "Enquête sur les conséquences de l'ouragan Idalia" }); - surveyDbContext.SaveChangesAsync(); + surveyDbContext.SaveChanges(); + } } } - public IEnumerable GetSurveyTranslations(int id, IEnumerable SurveyTranslation,string? language) + // Method to get survey translations for a given survey ID and language + public IEnumerable GetSurveyTranslations(int id, IEnumerable SurveyTranslation, string? language) { if (SurveyTranslation == null) { @@ -67,6 +72,8 @@ namespace DamageAssesment.Api.Surveys.Providers } return SurveyTranslation; } + + // Method to create a multi-language object from survey translations public object CreateMultiLanguageObject(IEnumerable surveyTranslations) { object MultiLanguage = new object(); @@ -78,28 +85,27 @@ namespace DamageAssesment.Api.Surveys.Providers MultiLanguage = dict; return MultiLanguage; } + + // Method to get surveys asynchronously with multi-language support public async Task<(bool IsSuccess, IEnumerable Surveys, string ErrorMessage)> GetSurveysAsync(string language) { IEnumerable surveysList = null; try { - logger?.LogInformation("Gell all Surveys from DB"); + logger?.LogInformation("Get all Surveys from DB"); var surveys = await surveyDbContext.Surveys.Where(s => s.IsEnabled == true).ToListAsync(); - //var surveyTranslations = await surveyDbContext.SurveysTranslation.ToListAsync(); if (surveys != null) { surveysList = from s in surveys - select new - Models.MultiLanSurvey + select new Models.MultiLanSurvey { Id = s.Id, StartDate = s.StartDate, EndDate = s.EndDate, IsEnabled = s.IsEnabled, CreatedDate = s.CreatedDate, - Titles = CreateMultiLanguageObject(GetSurveyTranslations(s.Id,null, language)) - + Titles = CreateMultiLanguageObject(GetSurveyTranslations(s.Id, null, language)) }; logger?.LogInformation($"{surveys.Count} Items(s) found"); @@ -113,12 +119,15 @@ namespace DamageAssesment.Api.Surveys.Providers return (false, null, ex.Message); } } + + // Method to get a specific survey by ID asynchronously with multi-language support public async Task<(bool IsSuccess, Models.MultiLanSurvey Surveys, string ErrorMessage)> GetSurveysAsync(int id, string language) { try { logger?.LogInformation("Query Survey"); var survey = await surveyDbContext.Surveys.SingleOrDefaultAsync(s => s.Id == id && s.IsEnabled == true); + if (survey != null) { Models.MultiLanSurvey result = null; @@ -130,8 +139,7 @@ namespace DamageAssesment.Api.Surveys.Providers EndDate = survey.EndDate, IsEnabled = survey.IsEnabled, CreatedDate = survey.CreatedDate, - Titles = CreateMultiLanguageObject(GetSurveyTranslations(survey.Id,null, language)) - + Titles = CreateMultiLanguageObject(GetSurveyTranslations(survey.Id, null, language)) }; logger?.LogInformation($"Survey Id: {id} found"); return (true, result, null); @@ -145,6 +153,7 @@ namespace DamageAssesment.Api.Surveys.Providers } } + // Method to create a new survey asynchronously with multi-language support public async Task<(bool IsSuccess, Models.MultiLanSurvey Survey, string ErrorMessage)> PostSurveyAsync(Models.Survey survey) { try @@ -156,14 +165,14 @@ namespace DamageAssesment.Api.Surveys.Providers surveyDbContext.Surveys.Add(_survey); await surveyDbContext.SaveChangesAsync(); - + foreach (var title in survey.Titles) { - surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation {SurveyId = _survey.Id, Language = title.Language, Title = title.Title }); + surveyDbContext.SurveysTranslation.Add(new Db.SurveyTranslation { SurveyId = _survey.Id, Language = title.Language, Title = title.Title }); } await surveyDbContext.SaveChangesAsync(); var result = mapper.Map(_survey); - result.Titles = CreateMultiLanguageObject(GetSurveyTranslations(_survey.Id, survey.Titles, "")); + result.Titles = CreateMultiLanguageObject(GetSurveyTranslations(_survey.Id, survey.Titles, "")); return (true, result, "Successful"); } else @@ -179,6 +188,7 @@ namespace DamageAssesment.Api.Surveys.Providers } } + // Method to update an existing survey asynchronously with multi-language support public async Task<(bool IsSuccess, Models.MultiLanSurvey Survey, string ErrorMessage)> PutSurveyAsync(int Id, Models.Survey survey) { try @@ -228,6 +238,7 @@ namespace DamageAssesment.Api.Surveys.Providers } } + // Method to delete a survey by ID asynchronously with multi-language support public async Task<(bool IsSuccess, Models.MultiLanSurvey Survey, string ErrorMessage)> DeleteSurveyAsync(int Id) { try @@ -240,7 +251,7 @@ namespace DamageAssesment.Api.Surveys.Providers result.Titles = CreateMultiLanguageObject(GetSurveyTranslations(survey.Id, null, "")); surveyDbContext.Surveys.Remove(survey); await surveyDbContext.SaveChangesAsync(); - return (true, result, $"Survey Id: {Id} deleted Successfuly"); + return (true, result, $"Survey Id: {Id} deleted Successfully"); } else { diff --git a/DamageAssesmentApi/DamageAssesment.Api.Surveys/appsettings.json b/DamageAssesmentApi/DamageAssesment.Api.Surveys/appsettings.json index 0057832..b33ff1e 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Surveys/appsettings.json +++ b/DamageAssesmentApi/DamageAssesment.Api.Surveys/appsettings.json @@ -10,6 +10,7 @@ }, "AllowedHosts": "*", "ConnectionStrings": { - "SurveyConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;" + //"SurveyConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;" + "SurveyConnection": "Server=localhost,1433;Database=da_survey_dev;User Id=sa;Password=Password123;TrustServerCertificate=True;" } } diff --git a/DamageAssesmentApi/DamageAssesment.sln b/DamageAssesmentApi/DamageAssesment.sln index da3ce6f..23f7731 100644 --- a/DamageAssesmentApi/DamageAssesment.sln +++ b/DamageAssesmentApi/DamageAssesment.sln @@ -11,6 +11,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DamageAssesment.Api.Attachm EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4CB40DC2-D9D2-4384-A7A6-9968F5C777A2}" ProjectSection(SolutionItems) = preProject + ..\..\..\..\Sample\Migrations.ps1 = ..\..\..\..\Sample\Migrations.ps1 ReadMe.txt = ReadMe.txt ReadMe4Dev.txt = ReadMe4Dev.txt EndProjectSection diff --git a/DamageAssesmentApi/docker-compose.yml b/DamageAssesmentApi/docker-compose.yml index f421f5a..0e6f487 100644 --- a/DamageAssesmentApi/docker-compose.yml +++ b/DamageAssesmentApi/docker-compose.yml @@ -34,14 +34,7 @@ services: context: . dockerfile: DamageAssesment.Api.Questions/Dockerfile - - # damageassesment.api.surveyresponses: - # image: ${DOCKER_REGISTRY-}damageassesmentapisurveyresponses - # build: - # context: . - # dockerfile: DamageAssesment.Api.SurveyResponses/Dockerfile - - + damageassesment.api.surveys: image: ${DOCKER_REGISTRY-}damageassesmentapisurveys build: