forked from MDCPS/DamageAssessment_Backend
		
	314: updated document multi language output format
This commit is contained in:
		| @ -7,7 +7,6 @@ using Microsoft.AspNetCore.Mvc; | ||||
|  | ||||
| namespace DamageAssesment.Api.Documents.Controllers | ||||
| { | ||||
|     [Route("api")] | ||||
|     [ApiController] | ||||
|     public class DocumentsController : ControllerBase | ||||
|     { | ||||
| @ -25,10 +24,13 @@ namespace DamageAssesment.Api.Documents.Controllers | ||||
|         /// <summary> | ||||
|         /// Get all documnets. | ||||
|         /// </summary> | ||||
|         [HttpGet("{language}/{LinkType}/documents")] | ||||
|         public async Task<IActionResult> GetDocumentsbyFormsandLanguageAsync(string language,string LinkType) | ||||
|         ///  | ||||
|         [Route("doculinks/{linktype:alpha}")] | ||||
|         [Route("doculinks/{linktype:alpha}/{language:alpha}")] | ||||
|         [HttpGet] | ||||
|         public async Task<IActionResult> GetDocumentsbyFormsandLanguageAsync(string linktype, string? language) | ||||
|         { | ||||
|             var result = await this.documentsProvider.GetDocumnetsByLinkAsync(language, LinkType); | ||||
|             var result = await this.documentsProvider.GetDocumnetsByLinkAsync(language, linktype); | ||||
|             if (result.IsSuccess) | ||||
|             { | ||||
|                 return Ok(result.documents); | ||||
| @ -38,23 +40,13 @@ namespace DamageAssesment.Api.Documents.Controllers | ||||
|         /// <summary> | ||||
|         /// Get all documnets. | ||||
|         /// </summary> | ||||
|         [HttpGet("{LinkType}/documents")] | ||||
|         public async Task<IActionResult> GetDocumentsbyFormAsync(string LinkType) | ||||
|         ///  | ||||
|         //[Route("doculinks/{language:alpha}")] | ||||
|         [Route("doculinks")] | ||||
|         [HttpGet] | ||||
|         public async Task<IActionResult> GetDocumentsAsync(string? language) | ||||
|         { | ||||
|             var result = await this.documentsProvider.GetDocumnetsByLinkAsync(null, LinkType); | ||||
|             if (result.IsSuccess) | ||||
|             { | ||||
|                 return Ok(result.documents); | ||||
|             } | ||||
|             return NoContent(); | ||||
|         } | ||||
|         /// <summary> | ||||
|         /// Get all documnets. | ||||
|         /// </summary> | ||||
|         [HttpGet("documents")] | ||||
|         public async Task<IActionResult> GetDocumentsAsync() | ||||
|         { | ||||
|             var result = await this.documentsProvider.GetDocumnetsAsync(); | ||||
|             var result = await this.documentsProvider.GetDocumnetsAsync(language); | ||||
|             if (result.IsSuccess) | ||||
|             { | ||||
|                 return Ok(result.documents); | ||||
| @ -65,10 +57,12 @@ namespace DamageAssesment.Api.Documents.Controllers | ||||
|         /// <summary> | ||||
|         /// Get a documnet by id. | ||||
|         /// </summary> | ||||
|         [HttpGet("documents/{id}")] | ||||
|         public async Task<IActionResult> GetDocumentAsync(int id) | ||||
|         [HttpGet] | ||||
|         [Route("doculinks/{id}")] | ||||
|         [Route("doculinks/{id}/{language:alpha}")] | ||||
|         public async Task<IActionResult> GetDocumentAsync(int id,string? language) | ||||
|         { | ||||
|             var result = await this.documentsProvider.GetDocumentAsync(id); | ||||
|             var result = await this.documentsProvider.GetDocumentAsync(id,language); | ||||
|             if (result.IsSuccess) | ||||
|             { | ||||
|                 return Ok(result.Document); | ||||
| @ -78,30 +72,32 @@ namespace DamageAssesment.Api.Documents.Controllers | ||||
|         /// <summary> | ||||
|         /// Upload new document. | ||||
|         /// </summary> | ||||
|         [HttpPut("documents")] | ||||
|         public async Task<IActionResult> UpdateDocument(DocumentInfo documentInfo) | ||||
|         [HttpPut] | ||||
|         [Route("doculinks/{id}")] | ||||
|         public async Task<IActionResult> UpdateDocument(int id,DocumentInfo documentInfo) | ||||
|         { | ||||
|             if (documentInfo != null) | ||||
|             { | ||||
|                 var dbdoc = await this.documentsProvider.GetDocumentAsync(documentInfo.Id); | ||||
|                 var dbdoc = await this.documentsProvider.GetDocumentByidAsync(id); | ||||
|                 if (dbdoc.IsSuccess) | ||||
|                 { | ||||
|                     Models.Document document = uploadService.UpdateDocuments(dbdoc.Document, documentInfo); | ||||
|                     var result = await this.documentsProvider.UpdateDocumentAsync(document); | ||||
|                     var result = await this.documentsProvider.UpdateDocumentAsync(id,document); | ||||
|                     if (result.IsSuccess) | ||||
|                     { | ||||
|                         return Ok(result.Document); | ||||
|                     } | ||||
|                     return NoContent(); | ||||
|                 } | ||||
|                 return NoContent(); | ||||
|                 return NotFound(); | ||||
|             } | ||||
|             return BadRequest(documentInfo); | ||||
|         } | ||||
|         /// <summary> | ||||
|         /// update existing document. | ||||
|         /// </summary> | ||||
|         [HttpPost("documents")] | ||||
|         [HttpPost] | ||||
|         [Route("doculinks")] | ||||
|         public async Task<IActionResult> CreateDocument(DocumentInfo documentInfo) | ||||
|         { | ||||
|             try | ||||
| @ -127,7 +123,8 @@ namespace DamageAssesment.Api.Documents.Controllers | ||||
|         /// <summary> | ||||
|         /// Delete documnet by id. | ||||
|         /// </summary> | ||||
|         [HttpDelete("documents/{id}")] | ||||
|         [HttpDelete] | ||||
|         [Route("doculinks/{id}")] | ||||
|         public async Task<IActionResult> DeleteDocument(int id) | ||||
|         { | ||||
|             // database soft delete | ||||
| @ -143,7 +140,8 @@ namespace DamageAssesment.Api.Documents.Controllers | ||||
|         /// <summary> | ||||
|         /// Get all document link type. | ||||
|         /// </summary> | ||||
|         [HttpGet("LinkTypes")] | ||||
|         [HttpGet] | ||||
|         [Route("doculinks/types")] | ||||
|         public async Task<IActionResult> GetLinkTypesAsync() | ||||
|         { | ||||
|             var result = await this.documentsProvider.GetLinkTypesAsync(); | ||||
| @ -156,7 +154,8 @@ namespace DamageAssesment.Api.Documents.Controllers | ||||
|         /// <summary> | ||||
|         /// Get a document link type by id. | ||||
|         /// </summary> | ||||
|         [HttpGet("LinkTypes/{id}")] | ||||
|         [HttpGet] | ||||
|         [Route("doculinks/types/{id}")] | ||||
|         public async Task<IActionResult> GetLinkTypeAsync(int id) | ||||
|         { | ||||
|             var result = await this.documentsProvider.GetLinkTypeAsync(id); | ||||
| @ -169,7 +168,8 @@ namespace DamageAssesment.Api.Documents.Controllers | ||||
|         /// <summary> | ||||
|         /// Update a existing document link type. | ||||
|         /// </summary> | ||||
|         [HttpPut("LinkTypes")] | ||||
|         [HttpPut] | ||||
|         [Route("doculinks/types")] | ||||
|         public async Task<IActionResult> UpdateLinkType(Models.LinkType linkType) | ||||
|         { | ||||
|             if (linkType != null) | ||||
| @ -189,7 +189,8 @@ namespace DamageAssesment.Api.Documents.Controllers | ||||
|         /// <summary> | ||||
|         /// Create a new document link type. | ||||
|         /// </summary> | ||||
|         [HttpPost("LinkTypes")] | ||||
|         [HttpPost] | ||||
|         [Route("doculinks/types")] | ||||
|         public async Task<IActionResult> CreateLinkType(Models.LinkType linkType) | ||||
|         { | ||||
|             if (linkType != null) | ||||
| @ -206,7 +207,8 @@ namespace DamageAssesment.Api.Documents.Controllers | ||||
|         /// <summary> | ||||
|         /// Delete a  existing document link type by id. | ||||
|         /// </summary> | ||||
|         [HttpDelete("LinkTypes/{id}")] | ||||
|         [HttpDelete] | ||||
|         [Route("doculinks/types/{id}")] | ||||
|         public async Task<IActionResult> DeleteLinkType(int id) | ||||
|         { | ||||
|             var result = await this.documentsProvider.DeleteLinkTypeAsync(id); | ||||
| @ -216,7 +218,5 @@ namespace DamageAssesment.Api.Documents.Controllers | ||||
|             } | ||||
|             return NotFound(); | ||||
|         } | ||||
|  | ||||
|  | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -4,12 +4,13 @@ namespace DamageAssesment.Api.Documents.Interfaces | ||||
| { | ||||
|     public interface IDocumentsProvider : ILinkTypesProvider | ||||
|     { | ||||
|         Task<(bool IsSuccess, Models.Document Document, string ErrorMessage)> GetDocumentAsync(int Id); | ||||
|         Task<(bool IsSuccess, IEnumerable<Models.Document> documents, string ErrorMessage)> GetDocumnetsAsync(); | ||||
|         Task<(bool IsSuccess, IEnumerable<Models.Document> documents, string ErrorMessage)> GetDocumnetsByLinkAsync(string Language,string LinkType); | ||||
|         Task<(bool IsSuccess, Models.Document Document, string ErrorMessage)> PostDocumentAsync(Models.Document Document); | ||||
|         Task<(bool IsSuccess, Models.Document Document, string ErrorMessage)> UpdateDocumentAsync(Models.Document Document); | ||||
|         Task<(bool IsSuccess, Models.Document Document, string ErrorMessage)> DeleteDocumentAsync(int Id); | ||||
|         Task<(bool IsSuccess, Models.MultiLanDocument Document, string ErrorMessage)> GetDocumentAsync(int id,string? language); | ||||
|         Task<(bool IsSuccess, Models.Document Document, string ErrorMessage)> GetDocumentByidAsync(int id); | ||||
|         Task<(bool IsSuccess, IEnumerable<Models.MultiLanDocument> documents, string ErrorMessage)> GetDocumnetsAsync(string? language); | ||||
|         Task<(bool IsSuccess, IEnumerable<Models.MultiLanDocument> documents, string ErrorMessage)> GetDocumnetsByLinkAsync(string? Language,string LinkType); | ||||
|         Task<(bool IsSuccess, Models.MultiLanDocument Document, string ErrorMessage)> PostDocumentAsync(Models.Document Document); | ||||
|         Task<(bool IsSuccess, Models.MultiLanDocument Document, string ErrorMessage)> UpdateDocumentAsync(int id,Models.Document Document); | ||||
|         Task<(bool IsSuccess, Models.MultiLanDocument Document, string ErrorMessage)> DeleteDocumentAsync(int id); | ||||
|         Task<(bool IsSuccess, int counter, string message)> GetDocumentCounter(); | ||||
|  | ||||
|  | ||||
|  | ||||
| @ -2,7 +2,16 @@ | ||||
|  | ||||
| namespace DamageAssesment.Api.Documents.Models | ||||
| { | ||||
|     public class Document | ||||
|     public class Document : BaseDocument | ||||
|     { | ||||
|         public List<DocumentsTranslation> documentsTranslations { get; set; } | ||||
|     } | ||||
|     public class MultiLanDocument:BaseDocument | ||||
|     { | ||||
|         public object titles { get; set; } | ||||
|         public object description { get; set; } | ||||
|     } | ||||
|     public class BaseDocument | ||||
|     { | ||||
|         public int Id { get; set; } | ||||
|  | ||||
| @ -14,6 +23,5 @@ namespace DamageAssesment.Api.Documents.Models | ||||
|         public bool IsActive { get; set; } | ||||
|         public DateTime dateCreated { get; set; } | ||||
|         public DateTime dateUpdated { get; set; } | ||||
|         public List<DocumentsTranslation> documentsTranslations { get; set; } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -6,6 +6,7 @@ namespace DamageAssesment.Api.Documents.Profiles | ||||
|     { | ||||
|         public DocumentProfile() | ||||
|         { | ||||
|             CreateMap<Db.Document, Models.MultiLanDocument>(); | ||||
|             CreateMap<Db.Document, Models.Document>(); | ||||
|             CreateMap<Models.Document, Db.Document>(); | ||||
|             CreateMap<Db.LinkType, Models.LinkType>(); | ||||
|  | ||||
| @ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.EntityFrameworkCore.Metadata.Internal; | ||||
| using System; | ||||
| using System.Diagnostics.Eventing.Reader; | ||||
| using System.Reflection.Metadata; | ||||
|  | ||||
| namespace DamageAssesment.Api.Documents.Providers | ||||
| { | ||||
| @ -54,7 +55,36 @@ namespace DamageAssesment.Api.Documents.Providers | ||||
|                 DocumentDbContext.SaveChanges(); | ||||
|             } | ||||
|         } | ||||
|         public async Task<(bool IsSuccess, IEnumerable<Models.Document> documents, string ErrorMessage)> GetDocumnetsByLinkAsync(string Language, string LinkType) | ||||
|         public List<Models.DocumentsTranslation> GetDocumentTranslations(int id, string? language) | ||||
|         { | ||||
|             List<Models.DocumentsTranslation> QuestionTranslations; | ||||
|             if (string.IsNullOrEmpty(language)) | ||||
|             { | ||||
|                 QuestionTranslations = mapper.Map<List<Db.DocumentsTranslation>, List<Models.DocumentsTranslation>>( | ||||
|                     DocumentDbContext.DocumentsTranslations.AsNoTracking().Where(a => a.DocumentId == id).ToList()); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 QuestionTranslations = mapper.Map<List<Db.DocumentsTranslation>, List<Models.DocumentsTranslation>>( | ||||
|                 DocumentDbContext.DocumentsTranslations.AsNoTracking().Where(a => a.DocumentId == id && a.Language == language).ToList()); | ||||
|             } | ||||
|             return QuestionTranslations; | ||||
|         } | ||||
|         public MultiLanDocument CreateMultiLanguageObject(List<Models.DocumentsTranslation> questions) | ||||
|         { | ||||
|             MultiLanDocument MultiLanguage = new MultiLanDocument(); | ||||
|             Dictionary<string, string> dicttitle = new Dictionary<string, string>(); | ||||
|             Dictionary<string, string> dictdesc = new Dictionary<string, string>(); | ||||
|             foreach (Models.DocumentsTranslation item in questions) | ||||
|             { | ||||
|                 dicttitle.Add(item.Language, item.title); | ||||
|                 dictdesc.Add(item.Language, item.description); | ||||
|             } | ||||
|             MultiLanguage.titles = dicttitle; | ||||
|             MultiLanguage.description = dictdesc; | ||||
|             return MultiLanguage; | ||||
|         } | ||||
|         public async Task<(bool IsSuccess, IEnumerable<Models.MultiLanDocument> documents, string ErrorMessage)> GetDocumnetsByLinkAsync(string? language, string? LinkType) | ||||
|         { | ||||
|  | ||||
|             try | ||||
| @ -68,15 +98,12 @@ namespace DamageAssesment.Api.Documents.Providers | ||||
|                      q.linkTypeId == (DocumentDbContext.LinkTypes.AsNoTracking().Where(a => a.TypeText.ToLower() == LinkType.ToLower()).Select(a => a.Id).FirstOrDefault())).ToListAsync(); | ||||
|                 if (documents != null) | ||||
|                 { | ||||
|                     var result = mapper.Map<IEnumerable<Db.Document>, IEnumerable<Models.Document>>(documents); | ||||
|                     var result = mapper.Map<List<Db.Document>, List<Models.MultiLanDocument>>(documents); | ||||
|                     foreach (var item in result) | ||||
|                     { | ||||
|                         if(!String.IsNullOrEmpty(Language)) | ||||
|                             item.documentsTranslations = mapper.Map<List<Db.DocumentsTranslation>, List<Models.DocumentsTranslation>>( | ||||
|                                     DocumentDbContext.DocumentsTranslations.Where(a => a.DocumentId == item.Id && (a.Language.ToLower() == Language.ToLower())).ToList()); | ||||
|                         else | ||||
|                         item.documentsTranslations = mapper.Map<List<Db.DocumentsTranslation>, List<Models.DocumentsTranslation>>( | ||||
|                                 DocumentDbContext.DocumentsTranslations.Where(a => a.DocumentId == item.Id).ToList()); | ||||
|                         var multilan = CreateMultiLanguageObject(GetDocumentTranslations(item.Id, language)); | ||||
|                         item.titles = multilan.titles; | ||||
|                         item.description = multilan.description; | ||||
|                     } | ||||
|                     return (true, result, null); | ||||
|                 } | ||||
| @ -89,7 +116,7 @@ namespace DamageAssesment.Api.Documents.Providers | ||||
|             } | ||||
|  | ||||
|         } | ||||
|         public async Task<(bool IsSuccess, IEnumerable<Models.Document> documents, string ErrorMessage)> GetDocumnetsAsync() | ||||
|         public async Task<(bool IsSuccess, IEnumerable<Models.MultiLanDocument> documents, string ErrorMessage)> GetDocumnetsAsync(string? language) | ||||
|         { | ||||
|  | ||||
|             try | ||||
| @ -99,11 +126,12 @@ namespace DamageAssesment.Api.Documents.Providers | ||||
|                 if (documents != null) | ||||
|                 { | ||||
|                     logger?.LogInformation($"{documents.Count} Document(s) found"); | ||||
|                     var result = mapper.Map<IEnumerable<Db.Document>, IEnumerable<Models.Document>>(documents); | ||||
|                     var result = mapper.Map<List<Db.Document>, List<Models.MultiLanDocument>>(documents); | ||||
|                     foreach (var item in result) | ||||
|                     { | ||||
|                         item.documentsTranslations = mapper.Map<List<Db.DocumentsTranslation>, List<Models.DocumentsTranslation>>( | ||||
|                                 DocumentDbContext.DocumentsTranslations.Where(a => a.DocumentId == item.Id).ToList()); | ||||
|                         var multilan = CreateMultiLanguageObject(GetDocumentTranslations(item.Id, language)); | ||||
|                         item.titles = multilan.titles; | ||||
|                         item.description = multilan.description; | ||||
|                     } | ||||
|                     return (true, result, null); | ||||
|                 } | ||||
| @ -116,16 +144,16 @@ namespace DamageAssesment.Api.Documents.Providers | ||||
|             } | ||||
|  | ||||
|         } | ||||
|         public async Task<(bool IsSuccess, Models.Document Document, string ErrorMessage)> GetDocumentAsync(int Id) | ||||
|         public async Task<(bool IsSuccess, Models.Document Document, string ErrorMessage)> GetDocumentByidAsync(int id) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger?.LogInformation("Query LinkType"); | ||||
|                 var Document = await DocumentDbContext.Documents.AsNoTracking().FirstOrDefaultAsync(q => q.Id == Id && q.IsActive); | ||||
|                 var Document = await DocumentDbContext.Documents.AsNoTracking().FirstOrDefaultAsync(q => q.Id == id && q.IsActive); | ||||
|                 if (Document != null) | ||||
|                 { | ||||
|                     logger?.LogInformation($"{Document} customer(s) found"); | ||||
|                     var result = mapper.Map<Db.Document, Models.Document>(Document); | ||||
|                     var result = mapper.Map<Db.Document, Models.Document>(Document);  | ||||
|                     result.documentsTranslations = mapper.Map<List<Db.DocumentsTranslation>, List<Models.DocumentsTranslation>>( | ||||
|                             DocumentDbContext.DocumentsTranslations.Where(a => a.DocumentId == result.Id).ToList()); | ||||
|                     return (true, result, null); | ||||
| @ -138,7 +166,30 @@ namespace DamageAssesment.Api.Documents.Providers | ||||
|                 return (false, null, ex.Message); | ||||
|             } | ||||
|         } | ||||
|         public async Task<(bool IsSuccess, Models.Document Document, string ErrorMessage)> PostDocumentAsync(Models.Document Document) | ||||
|         public async Task<(bool IsSuccess, Models.MultiLanDocument Document, string ErrorMessage)> GetDocumentAsync(int id,string? language) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 logger?.LogInformation("Query LinkType"); | ||||
|                 var Document = await DocumentDbContext.Documents.AsNoTracking().FirstOrDefaultAsync(q => q.Id == id && q.IsActive); | ||||
|                 if (Document != null) | ||||
|                 { | ||||
|                     logger?.LogInformation($"{Document} customer(s) found"); | ||||
|                     var result = mapper.Map<Db.Document, Models.MultiLanDocument>(Document); | ||||
|                     var multilan = CreateMultiLanguageObject(GetDocumentTranslations(result.Id, language)); | ||||
|                     result.titles = multilan.titles; | ||||
|                     result.description = multilan.description; | ||||
|                     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, Models.MultiLanDocument Document, string ErrorMessage)> PostDocumentAsync(Models.Document Document) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
| @ -149,8 +200,11 @@ namespace DamageAssesment.Api.Documents.Providers | ||||
|                 dbtranslation.ForEach(i => i.DocumentId = document.Id); | ||||
|                 DocumentDbContext.DocumentsTranslations.AddRange(dbtranslation); | ||||
|                 DocumentDbContext.SaveChanges(); | ||||
|                 Document.Id = document.Id; | ||||
|                 return (true, Document, null); | ||||
|                 var result = mapper.Map<Db.Document, Models.MultiLanDocument>(document); | ||||
|                 var multilan = CreateMultiLanguageObject(GetDocumentTranslations(document.Id, "")); | ||||
|                 result.titles = multilan.titles; | ||||
|                 result.description = multilan.description; | ||||
|                 return (true, result, null); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
| @ -159,15 +213,16 @@ namespace DamageAssesment.Api.Documents.Providers | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async Task<(bool IsSuccess, Models.Document Document, string ErrorMessage)> UpdateDocumentAsync(Models.Document Document) | ||||
|         public async Task<(bool IsSuccess, Models.MultiLanDocument Document, string ErrorMessage)> UpdateDocumentAsync(int id,Models.Document Document) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 if (Document != null) | ||||
|                 { | ||||
|                     var existing = DocumentDbContext.Documents.AsNoTracking().FirstOrDefault(x => x.Id == Document.Id); | ||||
|                     var existing = DocumentDbContext.Documents.AsNoTracking().FirstOrDefault(x => x.Id == id); | ||||
|                     if (existing != null) | ||||
|                     { | ||||
|                         Document.Id = existing.Id; | ||||
|                         var document = mapper.Map<Models.Document, Db.Document>(Document); | ||||
|                         DocumentDbContext.Documents.Update(document); | ||||
|                         DocumentDbContext.SaveChanges(); | ||||
| @ -176,7 +231,13 @@ namespace DamageAssesment.Api.Documents.Providers | ||||
|                             DocumentDbContext.DocumentsTranslations.RemoveRange(oldtranslations); | ||||
|                         var dbtranslation = mapper.Map<List<Models.DocumentsTranslation>, List<Db.DocumentsTranslation>>(Document.documentsTranslations); | ||||
|                         dbtranslation.ForEach(i => i.DocumentId = Document.Id); | ||||
|                         return (true, Document, "Successful"); | ||||
|                         DocumentDbContext.DocumentsTranslations.AddRange(dbtranslation); | ||||
|                         DocumentDbContext.SaveChanges(); | ||||
|                         var result = mapper.Map<Db.Document, Models.MultiLanDocument>(document); | ||||
|                         var multilan = CreateMultiLanguageObject(GetDocumentTranslations(document.Id, "")); | ||||
|                         result.titles = multilan.titles; | ||||
|                         result.description = multilan.description; | ||||
|                         return (true, result, "Successful"); | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
| @ -198,20 +259,24 @@ namespace DamageAssesment.Api.Documents.Providers | ||||
|                 return (false, null, ex.Message); | ||||
|             } | ||||
|         } | ||||
|         public async Task<(bool IsSuccess, Models.Document Document, string ErrorMessage)> DeleteDocumentAsync(int Id) | ||||
|         public async Task<(bool IsSuccess, Models.MultiLanDocument Document, string ErrorMessage)> DeleteDocumentAsync(int id) | ||||
|         { | ||||
|  | ||||
|             try | ||||
|             { | ||||
|                 Db.Document Document = DocumentDbContext.Documents.AsNoTracking().Where(a => a.Id == Id).FirstOrDefault(); | ||||
|                 Db.Document Document = DocumentDbContext.Documents.AsNoTracking().Where(a => a.Id == id).FirstOrDefault(); | ||||
|                 if (Document == null) | ||||
|                 { | ||||
|                     return (false, null, "Not Found"); | ||||
|                 } | ||||
|                 var result = mapper.Map<Db.Document, Models.MultiLanDocument>(Document); | ||||
|                 var multilan = CreateMultiLanguageObject(GetDocumentTranslations(Document.Id, "")); | ||||
|                 result.titles = multilan.titles; | ||||
|                 result.description = multilan.description; | ||||
|                 Document.IsActive = false; | ||||
|                 DocumentDbContext.Documents.Update(Document); | ||||
|                 DocumentDbContext.SaveChanges(); | ||||
|                 return (true, mapper.Map<Db.Document, Models.Document>(Document), $"DocumentId {Id} deleted Successfuly"); | ||||
|                 return (true, result, $"DocumentId {id} deleted Successfuly"); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
| @ -257,7 +322,6 @@ namespace DamageAssesment.Api.Documents.Providers | ||||
|             } | ||||
|  | ||||
|         } | ||||
|  | ||||
|         public async Task<(bool IsSuccess, Models.LinkType LinkType, string ErrorMessage)> GetLinkTypeAsync(int Id) | ||||
|         { | ||||
|             try | ||||
|  | ||||
		Reference in New Issue
	
	Block a user