diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks.Test/MockData.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks.Test/MockData.cs index bd10e4b..07b1dc7 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() { @@ -91,6 +92,7 @@ namespace DamageAssesment.Api.DocuLinks.Test docName = "", Path = "www.google.com", IsAttachments = false, + Language = "en", CustomOrder = 1 }); return new Models.Doculink @@ -118,6 +120,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 035ae9b..915e0a4 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Db/DoculinkAttachments.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Db/DoculinkAttachments.cs @@ -14,5 +14,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/AzureBlobService.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/AzureBlobService.cs index 9931de2..2f9b87c 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/AzureBlobService.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/AzureBlobService.cs @@ -55,7 +55,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() @@ -104,7 +104,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() { diff --git a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/DoculinkProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/DoculinkProvider.cs index a4d1fcc..b0f0dcd 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/DoculinkProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.DocuLinks/Providers/DoculinkProvider.cs @@ -135,6 +135,54 @@ 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) + { + + 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 = 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); + } + 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) { @@ -156,8 +204,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); } return (true, result, null); } @@ -211,8 +258,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"); @@ -244,8 +290,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"); @@ -356,8 +401,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 0e71850..ca5159a 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, @@ -93,7 +93,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() {