Added sql docker logic
This commit is contained in:
commit
46794057c4
@ -8,19 +8,20 @@ namespace DamageAssesment.Api.Answers.Providers
|
||||
{
|
||||
public class AnswersProvider : IAnswersProvider
|
||||
{
|
||||
|
||||
private AnswerDbContext answerDbContext;
|
||||
private ILogger<AnswersProvider> logger;
|
||||
private IMapper mapper;
|
||||
|
||||
// Constructor with dependency injection and data seeding
|
||||
public AnswersProvider(AnswerDbContext answerDbContext, ILogger<AnswersProvider> 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<Models.Answer> 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<Models.Answer> Answers, string ErrorMessage)> GetAnswersAsync(int surveyResponseId)
|
||||
{
|
||||
try
|
||||
@ -74,17 +77,17 @@ namespace DamageAssesment.Api.Answers.Providers
|
||||
{
|
||||
var result = mapper.Map<IEnumerable<Db.Answer>, IEnumerable<Models.Answer>>(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<Models.Answer> Answers, string ErrorMessage)> GetAnswersByQuestionAsync(int questionId)
|
||||
{
|
||||
try
|
||||
@ -96,17 +99,17 @@ namespace DamageAssesment.Api.Answers.Providers
|
||||
{
|
||||
var result = mapper.Map<IEnumerable<Db.Answer>, IEnumerable<Models.Answer>>(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<Db.Answer, Models.Answer>(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<Db.Answer, Models.Answer>(answer), $"AnswerId {Id} deleted Successfuly");
|
||||
return (true, mapper.Map<Db.Answer, Models.Answer>(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();
|
||||
}
|
||||
}
|
||||
|
@ -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;"
|
||||
}
|
||||
}
|
||||
|
@ -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;"
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
||||
{
|
||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||
var mockUploadService = new Mock<IUploadService>();
|
||||
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<IDoculinkProvider>();
|
||||
var mockUploadService = new Mock<IUploadService>();
|
||||
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<IDoculinkProvider>();
|
||||
var mockUploadService = new Mock<IUploadService>();
|
||||
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<IDoculinkProvider>();
|
||||
var mockUploadService = new Mock<IUploadService>();
|
||||
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<IDoculinkProvider>();
|
||||
var mockUploadService = new Mock<IUploadService>();
|
||||
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<IDoculinkProvider>();
|
||||
var mockUploadService = new Mock<IUploadService>();
|
||||
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()
|
||||
{
|
||||
|
@ -11,7 +11,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
||||
public class MockData
|
||||
{
|
||||
|
||||
public static async Task<(bool, List<DocuLinks.Models.ResDoculink>, string)> getOkResponse()
|
||||
public static async Task<(bool, List<DocuLinks.Models.ResDoculinks>, string)> getOkResponses()
|
||||
{
|
||||
List<DocuLinks.Models.ResDoculink> list = new List<DocuLinks.Models.ResDoculink>();
|
||||
|
||||
@ -46,6 +46,48 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
||||
doclinksAttachments= doclinksAttachments
|
||||
});
|
||||
}
|
||||
List<ResDoculinks> 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<DocuLinks.Models.ResDoculink>, string)> getOkResponse()
|
||||
{
|
||||
List<DocuLinks.Models.ResDoculink> list = new List<DocuLinks.Models.ResDoculink>();
|
||||
|
||||
for (int i = 1; i < 4; i++)
|
||||
{
|
||||
Dictionary<string, string> dicttitle = new Dictionary<string, string>();
|
||||
Dictionary<string, string> dictdesc = new Dictionary<string, string>();
|
||||
dicttitle.Add("en", "test"); dicttitle.Add("fr", "tester");
|
||||
dictdesc.Add("en", "test"); dictdesc.Add("fr", "tester");
|
||||
List<DoculinkTranslation> DocuLinksTranslations = new List<DoculinkTranslation>();
|
||||
DocuLinksTranslations.Add(new DoculinkTranslation()
|
||||
{
|
||||
Language = "en",
|
||||
title = "tel" + i,
|
||||
description = "Sample" + i
|
||||
});
|
||||
List<DoculinkAttachments> doclinksAttachments = new List<DoculinkAttachments>();
|
||||
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<DocuLinks.Models.ResDoculinks>, string)> getNoContentResponses()
|
||||
{
|
||||
IEnumerable<DocuLinks.Models.ResDoculinks> list = new List<DocuLinks.Models.ResDoculinks>();
|
||||
return (false, list, null);
|
||||
}
|
||||
public static async Task<(bool, IEnumerable<DocuLinks.Models.ResDoculink>, string)> getNoContentResponse()
|
||||
{
|
||||
IEnumerable<DocuLinks.Models.ResDoculink> list = new List<DocuLinks.Models.ResDoculink>();
|
||||
|
@ -136,7 +136,21 @@ namespace DamageAssesment.Api.DocuLinks.Controllers
|
||||
}
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all active Doculink.
|
||||
/// </summary>
|
||||
[Route("doculinks/active/{linktypeid:int}")]
|
||||
[Route("doculinks/active/{linktypeid:int}/{language:alpha}")]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetDocumentsByActiveLinkTypeIdAsync(int? linktypeid, string? language)
|
||||
{
|
||||
var result = await this.documentsProvider.GetdocumentsByLinkTypeIdAsync(linktypeid, language, true);
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
return Ok(result.documents);
|
||||
}
|
||||
return NoContent();
|
||||
}
|
||||
/// <summary>
|
||||
/// Get a Doculink by id.
|
||||
/// </summary>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
|
@ -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<Models.ResDoculink> documents, string ErrorMessage)> GetDocumnetsAsync(string? language);
|
||||
Task<(bool IsSuccess, IEnumerable<Models.ResDoculink> documents, string ErrorMessage)> GetdocumentsByLinkAsync(string? linkType, string? language, bool? isactive);
|
||||
Task<(bool IsSuccess, IEnumerable<Models.ResDoculinks> documents, string ErrorMessage)> GetdocumentsByLinkAsync(string? linkType, string? language, bool? isactive);
|
||||
Task<(bool IsSuccess, IEnumerable<Models.ResDoculinks> 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);
|
||||
|
@ -1,95 +0,0 @@
|
||||
// <auto-generated />
|
||||
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
|
||||
{
|
||||
/// <inheritdoc />
|
||||
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<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Path")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("dateCreated")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime>("dateUpdated")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("description")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("docName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("linkTypeId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("title")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("url")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Documents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DamageAssesment.Api.DocuLinks.Db.LinkType", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("TypeText")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("LinkTypes");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DamageAssesment.Api.DocuLinks.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialDocumentCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Documents",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
title = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
linkTypeId = table.Column<int>(type: "int", nullable: false),
|
||||
description = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
docName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
url = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Path = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
IsActive = table.Column<bool>(type: "bit", nullable: false),
|
||||
dateCreated = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
dateUpdated = table.Column<DateTime>(type: "datetime2", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Documents", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "LinkTypes",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
TypeText = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
IsActive = table.Column<bool>(type: "bit", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_LinkTypes", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Documents");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "LinkTypes");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,118 +0,0 @@
|
||||
// <auto-generated />
|
||||
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
|
||||
{
|
||||
/// <inheritdoc />
|
||||
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<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Path")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("dateCreated")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime>("dateUpdated")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("docName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("linkTypeId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("url")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Documents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DamageAssesment.Api.DocuLinks.Db.DocumentsTranslation", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("DocumentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Language")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("description")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("title")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("DocumentsTranslations");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DamageAssesment.Api.DocuLinks.Db.LinkType", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("IsAttachment")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("TypeText")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("LinkTypes");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DamageAssesment.Api.DocuLinks.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class DocumentTranslation : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "description",
|
||||
table: "Documents");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "title",
|
||||
table: "Documents");
|
||||
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "IsAttachment",
|
||||
table: "LinkTypes",
|
||||
type: "bit",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "DocumentsTranslations",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
DocumentId = table.Column<int>(type: "int", nullable: false),
|
||||
title = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
description = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Language = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_DocumentsTranslations", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "DocumentsTranslations");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "IsAttachment",
|
||||
table: "LinkTypes");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "description",
|
||||
table: "Documents",
|
||||
type: "nvarchar(max)",
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "title",
|
||||
table: "Documents",
|
||||
type: "nvarchar(max)",
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,144 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DamageAssesment.Api.DocuLinks.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class doculinkUpdate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
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<int>(
|
||||
name: "CustomOrder",
|
||||
table: "LinkTypes",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "CustomOrder",
|
||||
table: "Documents",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "IsDeleted",
|
||||
table: "Documents",
|
||||
type: "bit",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "DoclinksAttachments",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
DocumentId = table.Column<int>(type: "int", nullable: false),
|
||||
docName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Path = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
IsAttachments = table.Column<bool>(type: "bit", nullable: false),
|
||||
CustomOrder = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_DoclinksAttachments", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "LinksTranslations",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
LinkTypeId = table.Column<int>(type: "int", nullable: false),
|
||||
TypeText = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Language = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_LinksTranslations", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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<bool>(
|
||||
name: "IsAttachment",
|
||||
table: "LinkTypes",
|
||||
type: "bit",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "TypeText",
|
||||
table: "LinkTypes",
|
||||
type: "nvarchar(max)",
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Path",
|
||||
table: "Documents",
|
||||
type: "nvarchar(max)",
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "docName",
|
||||
table: "Documents",
|
||||
type: "nvarchar(max)",
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "url",
|
||||
table: "Documents",
|
||||
type: "nvarchar(max)",
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
}
|
||||
}
|
||||
}
|
@ -7,6 +7,11 @@ namespace DamageAssesment.Api.DocuLinks.Models
|
||||
{
|
||||
public List<DoculinkTranslation> documentsTranslations { get; set; }
|
||||
}
|
||||
public class ResDoculinks
|
||||
{
|
||||
public int linkTypeId { get; set; }
|
||||
public List<ResDoculink> doculinks { get; set; }
|
||||
}
|
||||
public class ResDoculink:BaseDoculink
|
||||
{
|
||||
public object titles { get; set; }
|
||||
|
@ -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>() { fileModel } };
|
||||
List<Db.DoculinkTranslation> documents = new List<Db.DoculinkTranslation>();
|
||||
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>() { fileModel } };
|
||||
Models.Doculink document = uploadservice.UploadDocument(counter, documentInfo);
|
||||
DocumentDbContext.Documents.Add(mapper.Map<Models.Doculink, Db.Doculink>(document));
|
||||
DocumentDbContext.SaveChanges();
|
||||
DocumentDbContext.DocumentsTranslations.AddRange(documents);
|
||||
var dbattachments = mapper.Map<List<Models.DoculinkAttachments>, List<Db.DoculinkAttachments>>(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<Db.DoculinkTranslation> documents = new List<Db.DoculinkTranslation>();
|
||||
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<Models.DoculinkTranslation> GetDocumentTranslations(int id, string? language)
|
||||
{
|
||||
@ -136,7 +170,44 @@ namespace DamageAssesment.Api.DocuLinks.Providers
|
||||
MultiLanguage = dicttitle;
|
||||
return MultiLanguage;
|
||||
}
|
||||
public async Task<(bool IsSuccess, IEnumerable<Models.ResDoculink> documents, string ErrorMessage)> GetdocumentsByLinkAsync(string? linkType, string? language, bool? isactive)
|
||||
|
||||
public async Task<(bool IsSuccess, IEnumerable<Models.ResDoculinks> documents, string ErrorMessage)> GetdocumentsByLinkTypeIdAsync(int? linkTypeId, string? language, bool? isactive)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
logger?.LogInformation("Query Question");
|
||||
var documents = new List<Db.Doculink>();
|
||||
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<Db.Doculink>, List<Models.ResDoculink>>(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<Db.DoculinkAttachments>, List<Models.DoculinkAttachments>>(
|
||||
DocumentDbContext.DoclinksAttachments.AsNoTracking().Where(a => a.DocumentId == item.Id).ToList());
|
||||
}
|
||||
List<ResDoculinks> 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<Models.ResDoculinks> 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<Db.DoculinkAttachments>, List<Models.DoculinkAttachments>>(
|
||||
DocumentDbContext.DoclinksAttachments.AsNoTracking().Where(a => a.DocumentId == item.Id).ToList());
|
||||
}
|
||||
return (true, result, null);
|
||||
List<ResDoculinks> 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");
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -1,64 +0,0 @@
|
||||
// <auto-generated />
|
||||
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
|
||||
{
|
||||
/// <inheritdoc />
|
||||
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<string>("Id")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.Property<string>("OfficePhoneNumber")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.Property<string>("PreferredLanguage")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Employees");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DamageAssesment.Api.Employees.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class employeeupdate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "Id",
|
||||
table: "Employees",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(450)")
|
||||
.Annotation("SqlServer:Identity", "1, 1");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "EmployeeCode",
|
||||
table: "Employees",
|
||||
type: "nvarchar(50)",
|
||||
maxLength: 50,
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "EmployeeCode",
|
||||
table: "Employees");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "Id",
|
||||
table: "Employees",
|
||||
type: "nvarchar(450)",
|
||||
nullable: false,
|
||||
oldClrType: typeof(int),
|
||||
oldType: "int")
|
||||
.OldAnnotation("SqlServer:Identity", "1, 1");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
// <auto-generated />
|
||||
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
|
||||
{
|
||||
/// <inheritdoc />
|
||||
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<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("BirthDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.Property<string>("EmployeeCode")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.Property<string>("OfficePhoneNumber")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.Property<string>("PreferredLanguage")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Employees");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DamageAssesment.Api.Employees.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class updatedemployee_id : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -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<Models.Employee> 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();
|
||||
}
|
||||
|
||||
|
@ -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;"
|
||||
}
|
||||
}
|
||||
|
@ -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<Models.Location> 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();
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;"
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;"
|
||||
}
|
||||
}
|
||||
|
@ -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<Db.SurveyResponse> SurveyResponses { get; set; }
|
||||
|
||||
|
@ -44,7 +44,7 @@ builder.Services.AddSwaggerGen(c =>
|
||||
});
|
||||
builder.Services.AddDbContext<SurveyResponseDbContext>(option =>
|
||||
{
|
||||
option.UseInMemoryDatabase("Responses");
|
||||
option.UseSqlServer("ResponsesConnection");
|
||||
});
|
||||
var app = builder.Build();
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;"
|
||||
}
|
||||
}
|
||||
|
@ -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 };
|
||||
|
||||
surveyDbContext.Surveys.Add(survey1);
|
||||
surveyDbContext.Surveys.Add(survey2);
|
||||
surveyDbContext.Surveys.Add(survey3);
|
||||
surveyDbContext.SaveChanges();
|
||||
|
||||
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.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 { 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" });
|
||||
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 { 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 = 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<Models.SurveyTranslation> GetSurveyTranslations(int id, IEnumerable<Models.SurveyTranslation> SurveyTranslation,string? language)
|
||||
// Method to get survey translations for a given survey ID and language
|
||||
public IEnumerable<Models.SurveyTranslation> GetSurveyTranslations(int id, IEnumerable<Models.SurveyTranslation> 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<Models.SurveyTranslation> 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<Models.MultiLanSurvey> Surveys, string ErrorMessage)> GetSurveysAsync(string language)
|
||||
{
|
||||
IEnumerable<Models.MultiLanSurvey> 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
|
||||
@ -159,7 +168,7 @@ namespace DamageAssesment.Api.Surveys.Providers
|
||||
|
||||
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<Db.Survey, Models.MultiLanSurvey>(_survey);
|
||||
@ -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
|
||||
{
|
||||
|
@ -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;"
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -35,13 +35,6 @@ services:
|
||||
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:
|
||||
|
Loading…
Reference in New Issue
Block a user