From c7a2dc5910803030eb4baf4d8efdcae604ff46f2 Mon Sep 17 00:00:00 2001 From: uppuv Date: Fri, 6 Oct 2023 15:53:09 -0400 Subject: [PATCH 1/4] seed changes for doculinks --- .../Providers/DoculinkProvider.cs | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/DoculinkProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/DoculinkProvider.cs index cf8bcfe..64fd608 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/DoculinkProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/DoculinkProvider.cs @@ -63,13 +63,15 @@ 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 } }; - Db.DoculinkTranslation documents = new Db.DoculinkTranslation { DocumentId = i, title = "Test"+i, description = "ss"+i, Language = "en" }; + FileModel fileModel = new FileModel(); + if (i<3) + 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 = i, 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); @@ -77,6 +79,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) { From 71d4b524e7d5779c7d164ab4728de683b29b61ab Mon Sep 17 00:00:00 2001 From: uppuv Date: Mon, 9 Oct 2023 13:29:01 -0400 Subject: [PATCH 2/4] doculinks changes for grouping --- .../DoculinkServiceTest.cs | 34 ++++++++++-- .../MockData.cs | 49 ++++++++++++++++- .../Controllers/DoculinkController.cs | 16 +++++- .../Interfaces/IDoculinkProvider.cs | 3 +- .../Models/Doculink.cs | 5 ++ .../Providers/DoculinkProvider.cs | 55 +++++++++++++++++-- 6 files changed, 150 insertions(+), 12 deletions(-) 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/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/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 64fd608..28e8664 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,12 +65,17 @@ namespace DamageAssesment.Api.DocuLinks.Providers int counter = 0; for (int i = 1; i <= 4; i++) { + int linkTypeId = 2; FileModel fileModel = new FileModel(); - if (i<3) - fileModel = new FileModel() { FileName="Sample"+i,FileExtension=".txt",FileContent= "c2FtcGxl", IsAttachments = true, CustomOrder = 1 }; + 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 = i, CustomOrder = i, Files = new List() { fileModel } }; + 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(); @@ -163,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 @@ -187,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"); } From cb3c7f8f6af3e7992af41d6c22566c5c875c242e Mon Sep 17 00:00:00 2001 From: uppuv Date: Fri, 13 Oct 2023 13:21:33 -0400 Subject: [PATCH 3/4] added muilti language return format for question categories for question by survey --- .../appsettings.Development.json | 8 -------- .../appsettings.Development.json | 8 -------- .../appsettings.Development.json | 8 -------- .../appsettings.Development.json | 8 -------- .../appsettings.Development.json | 8 -------- .../Models/SurveyQuestion.cs | 1 + .../Providers/QuestionsProvider.cs | 1 + .../appsettings.Development.json | 8 -------- .../appsettings.Development.json | 8 -------- 9 files changed, 2 insertions(+), 56 deletions(-) delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.Answers/appsettings.Development.json delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.Attachments/appsettings.Development.json delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.DocuLinks/appsettings.Development.json delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.Employees/appsettings.Development.json delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.Locations/appsettings.Development.json delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.Questions/appsettings.Development.json delete mode 100644 DamageAssesmentApi/DamageAssesment.Api.Surveys/appsettings.Development.json diff --git a/DamageAssesmentApi/DamageAssesment.Api.Answers/appsettings.Development.json b/DamageAssesmentApi/DamageAssesment.Api.Answers/appsettings.Development.json deleted file mode 100644 index 0c208ae..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.Answers/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Attachments/appsettings.Development.json b/DamageAssesmentApi/DamageAssesment.Api.Attachments/appsettings.Development.json deleted file mode 100644 index 0c208ae..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.Attachments/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/appsettings.Development.json b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/appsettings.Development.json deleted file mode 100644 index 0c208ae..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Employees/appsettings.Development.json b/DamageAssesmentApi/DamageAssesment.Api.Employees/appsettings.Development.json deleted file mode 100644 index 0c208ae..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.Employees/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Locations/appsettings.Development.json b/DamageAssesmentApi/DamageAssesment.Api.Locations/appsettings.Development.json deleted file mode 100644 index 0c208ae..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.Locations/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/Models/SurveyQuestion.cs b/DamageAssesmentApi/DamageAssesment.Api.Questions/Models/SurveyQuestion.cs index 8f4fd7b..b7ce8d1 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Questions/Models/SurveyQuestion.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Questions/Models/SurveyQuestion.cs @@ -5,6 +5,7 @@ public int CategoryId { get; set; } public string IconName { get; set; } public string IconLibrary { get; set; } + public object CategoryNames { get; set; } public List QuestionsText { get; set; } } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs index 5a010fa..45f6ecf 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs @@ -314,6 +314,7 @@ namespace DamageAssesment.Api.Questions.Providers CategoryId = item.Id, IconLibrary = item.IconLibrary, IconName = item.IconName, + CategoryNames= CreateCategoryMultiLanguageObject(GetCategoryTranslations(item.Id, language)), QuestionsText = GetSurveyQuestion(mapper.Map, List>(questions.Where(a => a.CategoryId == item.Id).ToList()), language) }); } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/appsettings.Development.json b/DamageAssesmentApi/DamageAssesment.Api.Questions/appsettings.Development.json deleted file mode 100644 index 0c208ae..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.Questions/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/DamageAssesmentApi/DamageAssesment.Api.Surveys/appsettings.Development.json b/DamageAssesmentApi/DamageAssesment.Api.Surveys/appsettings.Development.json deleted file mode 100644 index 0c208ae..0000000 --- a/DamageAssesmentApi/DamageAssesment.Api.Surveys/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} From 2182b9a6b38d0e8533c2197579d3c3a63db5f3a2 Mon Sep 17 00:00:00 2001 From: uppuv Date: Mon, 23 Oct 2023 11:39:56 -0400 Subject: [PATCH 4/4] added status field in survey micro service --- .../Models/Survey.cs | 7 +++++++ .../Providers/SurveysProvider.cs | 21 +++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Models/Survey.cs b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Models/Survey.cs index 25f5405..38fa72a 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Models/Survey.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Models/Survey.cs @@ -2,9 +2,16 @@ namespace DamageAssesment.Api.Surveys.Models { + public enum SurveyStatus + { + PENDING, + ACTIVE, + INACTIVE + } public class MultiLanSurvey : BaseSurvey { public object Titles { get; set; } + public string Status { get; set; } } public class Survey : BaseSurvey { diff --git a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Providers/SurveysProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Providers/SurveysProvider.cs index 3332f6d..bb44cf2 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Providers/SurveysProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Providers/SurveysProvider.cs @@ -26,9 +26,9 @@ namespace DamageAssesment.Api.Surveys.Providers { if (!surveyDbContext.Surveys.Any()) { - 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 = true, StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(90), CreatedDate = DateTime.Now }; + var survey1 = new Db.Survey { IsEnabled = true, StartDate = DateTime.Now.AddDays(10), EndDate = DateTime.Now.AddDays(90), CreatedDate = DateTime.Now }; + var survey2 = new Db.Survey { IsEnabled = true, StartDate = DateTime.Now.AddDays(-10), EndDate = DateTime.Now.AddDays(90), CreatedDate = DateTime.Now.AddDays(-10) }; + var survey3 = new Db.Survey { IsEnabled = true, StartDate = DateTime.Now.AddDays(-100), EndDate = DateTime.Now.AddDays(-10), CreatedDate = DateTime.Now.AddDays(-100) }; surveyDbContext.Surveys.Add(survey1); surveyDbContext.Surveys.Add(survey2); @@ -85,7 +85,15 @@ namespace DamageAssesment.Api.Surveys.Providers MultiLanguage = dict; return MultiLanguage; } - + public string GetStatus(DateTime StartDate,DateTime EndDate) + { + if (StartDate > DateTime.Now) + return SurveyStatus.PENDING.ToString(); + else if (StartDate <= DateTime.Now && EndDate > DateTime.Now) + return SurveyStatus.ACTIVE.ToString(); + else + return SurveyStatus.INACTIVE.ToString(); + } // Method to get surveys asynchronously with multi-language support public async Task<(bool IsSuccess, IEnumerable Surveys, string ErrorMessage)> GetSurveysAsync(string language) { @@ -105,6 +113,7 @@ namespace DamageAssesment.Api.Surveys.Providers EndDate = s.EndDate, IsEnabled = s.IsEnabled, CreatedDate = s.CreatedDate, + Status= GetStatus(s.StartDate,s.EndDate), Titles = CreateMultiLanguageObject(GetSurveyTranslations(s.Id, null, language)) }; @@ -139,6 +148,7 @@ namespace DamageAssesment.Api.Surveys.Providers EndDate = survey.EndDate, IsEnabled = survey.IsEnabled, CreatedDate = survey.CreatedDate, + Status = GetStatus(survey.StartDate, survey.EndDate), Titles = CreateMultiLanguageObject(GetSurveyTranslations(survey.Id, null, language)) }; logger?.LogInformation($"Survey Id: {id} found"); @@ -172,6 +182,7 @@ namespace DamageAssesment.Api.Surveys.Providers } await surveyDbContext.SaveChangesAsync(); var result = mapper.Map(_survey); + result.Status = GetStatus(_survey.StartDate, _survey.EndDate); result.Titles = CreateMultiLanguageObject(GetSurveyTranslations(_survey.Id, survey.Titles, "")); return (true, result, "Successful"); } @@ -216,6 +227,7 @@ namespace DamageAssesment.Api.Surveys.Providers await surveyDbContext.SaveChangesAsync(); var result = mapper.Map(_survey); + result.Status = GetStatus(_survey.StartDate, _survey.EndDate); result.Titles = CreateMultiLanguageObject(GetSurveyTranslations(_survey.Id, survey.Titles, "")); return (true, result, "Successful"); } @@ -248,6 +260,7 @@ namespace DamageAssesment.Api.Surveys.Providers if (survey != null) { var result = mapper.Map(survey); + result.Status = GetStatus(survey.StartDate, survey.EndDate); result.Titles = CreateMultiLanguageObject(GetSurveyTranslations(survey.Id, null, "")); surveyDbContext.Surveys.Remove(survey); await surveyDbContext.SaveChangesAsync();