From 902919074eef93816ae1f50144d1a8f68965660e Mon Sep 17 00:00:00 2001 From: Vijay Uppu <913468@dadeschools.net> Date: Thu, 30 Nov 2023 19:25:07 -0500 Subject: [PATCH] added multi language support for doculink attachments --- .../MockData.cs | 6 +++- .../Db/DoculinkAttachments.cs | 1 + .../Models/DoculinkAttachments.cs | 1 + .../Models/ReqDoculink.cs | 1 + .../Providers/DoculinkProvider.cs | 34 ++++++++++++------- .../Providers/UploadService.cs | 4 +-- 6 files changed, 31 insertions(+), 16 deletions(-) diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks.Test/MockData.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks.Test/MockData.cs index 843b4d3..0466fa8 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks.Test/MockData.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks.Test/MockData.cs @@ -32,7 +32,8 @@ namespace DamageAssesment.Api.DocuLinks.Test doclinksAttachments.Add(new DoculinkAttachments() { docName = "",Path="www.google.com", - IsAttachments=false,CustomOrder=1 + Language = "en", + IsAttachments =false,CustomOrder=1 }); list.Add(new DocuLinks.Models.ResDoculink() { @@ -74,6 +75,7 @@ namespace DamageAssesment.Api.DocuLinks.Test docName = "", Path = "www.google.com", IsAttachments = false, + Language = "en", CustomOrder = 1 }); list.Add(new DocuLinks.Models.ResDoculink() @@ -138,6 +140,7 @@ namespace DamageAssesment.Api.DocuLinks.Test docName = "", Path = "www.google.com", IsAttachments = false, + Language = "en", CustomOrder = 1 }); return new Models.Doculink @@ -165,6 +168,7 @@ namespace DamageAssesment.Api.DocuLinks.Test docName = "", Path = "www.google.com", IsAttachments = false, + Language = "en", CustomOrder = 1 }); List DocuLinks = new List(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Db/DoculinkAttachments.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Db/DoculinkAttachments.cs index b6eac5c..f277570 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Db/DoculinkAttachments.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Db/DoculinkAttachments.cs @@ -15,5 +15,6 @@ namespace DamageAssesment.Api.DocuLinks.Db public string Path { get; set; } public bool IsAttachments { get; set; } public int CustomOrder { get; set; } + public string Language { get; set; } } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Models/DoculinkAttachments.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Models/DoculinkAttachments.cs index ce87857..04a6970 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Models/DoculinkAttachments.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Models/DoculinkAttachments.cs @@ -8,6 +8,7 @@ namespace DamageAssesment.Api.DocuLinks.Models public string docName { get; set; } public string Path { get; set; } public bool IsAttachments { get; set; } + public string Language { get; set; } public int CustomOrder { get; set; } } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Models/ReqDoculink.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Models/ReqDoculink.cs index 0f2ea17..270a5f3 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Models/ReqDoculink.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Models/ReqDoculink.cs @@ -18,5 +18,6 @@ namespace DamageAssesment.Api.DocuLinks.Models public int CustomOrder { get; set; } public string url { get;set; } public bool IsAttachments { get; set; } + public string Language { get; set; } } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/DoculinkProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/DoculinkProvider.cs index 01ec9cf..749f200 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/DoculinkProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/DoculinkProvider.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Immutable; using System.Diagnostics.Eventing.Reader; using System.Reflection.Metadata; +using System.Runtime.CompilerServices; using System.Xml; using System.Xml.Linq; @@ -71,10 +72,10 @@ namespace DamageAssesment.Api.DocuLinks.Providers { linkTypeId = 1; - fileModel = new FileModel() { FileName = "Sample" + i, FileExtension = ".txt", FileContent = "c2FtcGxl", IsAttachments = true, CustomOrder = 1 }; + fileModel = new FileModel() { FileName = "Sample" + i, FileExtension = ".txt", FileContent = "c2FtcGxl", IsAttachments = true, CustomOrder = 1, Language = "en" }; } else - fileModel = new FileModel() { url = "www.google" + i + ".com", IsAttachments = false, CustomOrder = 1 }; + fileModel = new FileModel() { url = "www.google" + i + ".com", IsAttachments = false, CustomOrder = 1,Language="en" }; 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)); @@ -170,7 +171,19 @@ namespace DamageAssesment.Api.DocuLinks.Providers MultiLanguage = dicttitle; return MultiLanguage; } - + private List GetDocumentAttachment(int id,string? language) + { + if (string.IsNullOrEmpty(language)) + { + return mapper.Map, List>( + DocumentDbContext.DoclinksAttachments.AsNoTracking().Where(a => a.DocumentId == id).ToList()); + } + else + { + return mapper.Map, List>( + DocumentDbContext.DoclinksAttachments.AsNoTracking().Where(a => a.DocumentId == id && a.Language == language).ToList()); + } + } public async Task<(bool IsSuccess, IEnumerable documents, string ErrorMessage)> GetdocumentsByLinkTypeIdAsync(int? linkTypeId, string? language, bool? isactive) { @@ -192,8 +205,7 @@ namespace DamageAssesment.Api.DocuLinks.Providers 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()); + item.doclinksAttachments = GetDocumentAttachment(item.Id,language); } // List doculinks = result.GroupBy(a => a.linkTypeId).Select(a => new ResDoculinks() { linkTypeId = a.Key, doculinks = a.ToList() }).ToList(); return (true, result, null); @@ -228,8 +240,7 @@ namespace DamageAssesment.Api.DocuLinks.Providers 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()); + item.doclinksAttachments = GetDocumentAttachment(item.Id, language); } //List doculinks = result.GroupBy(a => a.linkTypeId).Select(a => new ResDoculinks() { linkTypeId = a.Key, doculinks = a.ToList() }).ToList(); return (true, result, null); @@ -284,8 +295,7 @@ namespace DamageAssesment.Api.DocuLinks.Providers result.documentsTranslations = mapper.Map, List>( DocumentDbContext.DocumentsTranslations.Where(a => a.DocumentId == result.Id).ToList()); - result.doclinksAttachments = mapper.Map, List>( - DocumentDbContext.DoclinksAttachments.AsNoTracking().Where(a => a.DocumentId == id).ToList()); + result.doclinksAttachments = GetDocumentAttachment(id, ""); return (true, result, null); } return (false, null, "Not found"); @@ -317,8 +327,7 @@ namespace DamageAssesment.Api.DocuLinks.Providers result.linktypes = CreateMultiLanguageLinkTypeObject(GetLinkTypeTranslations(result.linkTypeId, language)); result.titles = multilan.titles; result.description = multilan.description; - result.doclinksAttachments = mapper.Map, List>( - DocumentDbContext.DoclinksAttachments.AsNoTracking().Where(a => a.DocumentId == id).ToList()); + result.doclinksAttachments = GetDocumentAttachment(id, language); return (true, result, null); } return (false, null, "Not found"); @@ -429,8 +438,7 @@ namespace DamageAssesment.Api.DocuLinks.Providers result.titles = multilan.titles; result.description = multilan.description; result.linktypes = CreateMultiLanguageLinkTypeObject(GetLinkTypeTranslations(result.linkTypeId, "")); - result.doclinksAttachments = mapper.Map, List>( - DocumentDbContext.DoclinksAttachments.AsNoTracking().Where(a => a.DocumentId == id).ToList()); + result.doclinksAttachments = GetDocumentAttachment(id, ""); Document.IsActive = false; DocumentDbContext.Documents.Update(Document); DocumentDbContext.SaveChanges(); diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/UploadService.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/UploadService.cs index 807a2e0..b4c5b52 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/UploadService.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/UploadService.cs @@ -51,7 +51,7 @@ namespace DamageAssesment.Api.DocuLinks.Providers } else path = item.url; - attachments.Add(new Models.DoculinkAttachments { docName=UserfileName,Path=path,IsAttachments=item.IsAttachments,CustomOrder=item.CustomOrder }); + attachments.Add(new Models.DoculinkAttachments { docName=UserfileName,Path=path,IsAttachments=item.IsAttachments,CustomOrder=item.CustomOrder,Language=item.Language }); } } Documents=new Models.Doculink (){ linkTypeId = documentInfo.linkTypeId, @@ -92,7 +92,7 @@ namespace DamageAssesment.Api.DocuLinks.Providers } else path = item.url; - attachments.Add(new Models.DoculinkAttachments { docName = UserfileName, Path = path,IsAttachments=item.IsAttachments,CustomOrder=item.CustomOrder }); + attachments.Add(new Models.DoculinkAttachments { docName = UserfileName, Path = path,IsAttachments=item.IsAttachments,CustomOrder=item.CustomOrder,Language=item.Language }); } Models.Doculink Documents = new Models.Doculink() {