doculink and attachments url changes

This commit is contained in:
Vijay Uppu 2023-12-04 09:16:05 -05:00
parent da51cc1a1e
commit deb9a823f0
12 changed files with 171 additions and 17 deletions

View File

@ -139,6 +139,30 @@ namespace DamageAssesment.Api.Attachments.Controllers
} }
} }
/// <summary> /// <summary>
/// download an existing attachment.
/// </summary>
[Authorize(Roles = "admin")]
[HttpGet("attachments/download/{id}")]
public async Task<IActionResult> downloadfile1(int id)
{
try
{
var result = await this.AttachmentProvider.GetDownloadAttachmentAsync(id);
if(!result.IsSuccess)
return NotFound();
byte[] fileContent = await UploadService.DownloadFile(result.Attachment.URI);
if (fileContent == null || fileContent.Length == 0)
return NotFound();
var contentType = "application/octet-stream";
return File(fileContent, contentType, result.Attachment.FileName);
}
catch (Exception ex)
{
// Handle the exception here or log it
return StatusCode(500, "An error occurred: " + ex.Message);
}
}
/// <summary>
/// Delete an existing attachment. /// Delete an existing attachment.
/// </summary> /// </summary>
[Authorize(Roles = "admin")] [Authorize(Roles = "admin")]

View File

@ -9,6 +9,7 @@ namespace DamageAssesment.Api.Attachments.Interfaces
Task<(bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage)> PostAttachmentAsync(List<Models.Attachment> Attachments); Task<(bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage)> PostAttachmentAsync(List<Models.Attachment> Attachments);
Task<(bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage)> PutAttachmentAsync(List<Models.Attachment> Attachments); Task<(bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage)> PutAttachmentAsync(List<Models.Attachment> Attachments);
Task<(bool IsSuccess, Models.Attachment Attachment, string Path)> DeleteAttachmentAsync(int Id); Task<(bool IsSuccess, Models.Attachment Attachment, string Path)> DeleteAttachmentAsync(int Id);
Task<(bool IsSuccess, Models.Attachment Attachment, string Path)> GetDownloadAttachmentAsync(int Id);
Task<(bool IsSuccess, int counter, string Path)> DeleteAttachmentsAsync(int responseId, int answerId); Task<(bool IsSuccess, int counter, string Path)> DeleteAttachmentsAsync(int responseId, int answerId);
Task<(bool IsSuccess, int counter, string Path)> DeleteBulkAttachmentsAsync(int responseId, List<int> answerIds); Task<(bool IsSuccess, int counter, string Path)> DeleteBulkAttachmentsAsync(int responseId, List<int> answerIds);
Task<(bool IsSuccess, int counter, string message)> GetAttachmentCounter(); Task<(bool IsSuccess, int counter, string message)> GetAttachmentCounter();

View File

@ -7,6 +7,7 @@ namespace DamageAssesment.Api.Attachments.Interfaces
List<Models.Attachment> UploadAttachment(int responseId,int answerId, int counter, List<IFormFile> postedFile); List<Models.Attachment> UploadAttachment(int responseId,int answerId, int counter, List<IFormFile> postedFile);
List<Models.Attachment> UploadAttachment(int responseId, int counter, List<AnswerInfo> answers); List<Models.Attachment> UploadAttachment(int responseId, int counter, List<AnswerInfo> answers);
public List<Models.Attachment> UpdateAttachments(int responseId, List<AnswerInfo> answers, IEnumerable<Models.Attachment> attachments); public List<Models.Attachment> UpdateAttachments(int responseId, List<AnswerInfo> answers, IEnumerable<Models.Attachment> attachments);
Task<byte[]> DownloadFile(string path);
void Deletefile(string path); void Deletefile(string path);
void Movefile(string path); void Movefile(string path);
} }

View File

@ -71,6 +71,7 @@ builder.Services.AddSwaggerGen(options =>
options.AddSecurityRequirement(securityRequirements); options.AddSecurityRequirement(securityRequirements);
}); });
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
builder.Services.AddScoped<IAttachmentsProvider, AttachmentsProvider>(); builder.Services.AddScoped<IAttachmentsProvider, AttachmentsProvider>();
builder.Services.AddScoped<IUploadService, UploadService>(); builder.Services.AddScoped<IUploadService, UploadService>();
builder.Services.AddScoped<IAzureBlobService,AzureBlobService>(); builder.Services.AddScoped<IAzureBlobService,AzureBlobService>();

View File

@ -13,25 +13,33 @@ namespace DamageAssesment.Api.Attachments.Providers
private AttachmentsDbContext AttachmentDbContext; private AttachmentsDbContext AttachmentDbContext;
private ILogger<AttachmentsProvider> logger; private ILogger<AttachmentsProvider> logger;
private IUploadService uploadservice; private IUploadService uploadservice;
private IMapper mapper; private IMapper mapper;
private readonly IHttpContextAccessor httpContextAccessor;
public AttachmentsProvider(AttachmentsDbContext AttachmentDbContext, ILogger<AttachmentsProvider> logger, IMapper mapper,IUploadService uploadservice) private string baseUrl;
public AttachmentsProvider(AttachmentsDbContext AttachmentDbContext, ILogger<AttachmentsProvider> logger, IMapper mapper,IUploadService uploadservice, IHttpContextAccessor httpContextAccessor)
{ {
this.AttachmentDbContext = AttachmentDbContext; this.AttachmentDbContext = AttachmentDbContext;
this.logger = logger; this.logger = logger;
this.mapper = mapper; this.mapper = mapper;
this.uploadservice = uploadservice; this.uploadservice = uploadservice;
this.httpContextAccessor = httpContextAccessor;
baseUrl = $"{httpContextAccessor.HttpContext.Request.Scheme}://{httpContextAccessor.HttpContext.Request.Host}";
baseUrl = baseUrl + "/attachments/download";
//SeedData(); //SeedData();
} }
public async Task<(bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage)> GetAttachmentsAsync() public async Task<(bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage)> GetAttachmentsAsync()
{ {
try try
{ {
logger?.LogInformation("Query Question"); logger?.LogInformation("Query Question");
var Attachment = await AttachmentDbContext.Attachments.AsNoTracking().Where(a => !a.IsDeleted).ToListAsync(); var Attachment = await AttachmentDbContext.Attachments.AsNoTracking().Where(a => !a.IsDeleted).ToListAsync();
if (Attachment != null) if (Attachment != null)
{ {
foreach (var attachment in Attachment)
{
attachment.URI = $"{baseUrl}/{attachment.Id}";
}
logger?.LogInformation($"{Attachment.Count} Attachments(s) found"); logger?.LogInformation($"{Attachment.Count} Attachments(s) found");
var result = mapper.Map<IEnumerable<Db.Attachment>, IEnumerable<Models.Attachment>>(Attachment); var result = mapper.Map<IEnumerable<Db.Attachment>, IEnumerable<Models.Attachment>>(Attachment);
return (true, result, null); return (true, result, null);
@ -54,6 +62,7 @@ namespace DamageAssesment.Api.Attachments.Providers
if (Attachment != null) if (Attachment != null)
{ {
logger?.LogInformation($"{Attachment} customer(s) found"); logger?.LogInformation($"{Attachment} customer(s) found");
Attachment.URI = $"{baseUrl}/{Attachment.Id}";
var result = mapper.Map<Db.Attachment, Models.Attachment>(Attachment); var result = mapper.Map<Db.Attachment, Models.Attachment>(Attachment);
return (true, result, null); return (true, result, null);
} }
@ -73,6 +82,10 @@ namespace DamageAssesment.Api.Attachments.Providers
List<Db.Attachment> attachments = mapper.Map<List<Models.Attachment>, List<Db.Attachment>>(Attachments); List<Db.Attachment> attachments = mapper.Map<List<Models.Attachment>, List<Db.Attachment>>(Attachments);
AttachmentDbContext.Attachments.AddRange(attachments); AttachmentDbContext.Attachments.AddRange(attachments);
await AttachmentDbContext.SaveChangesAsync(); await AttachmentDbContext.SaveChangesAsync();
foreach (var attachment in attachments)
{
attachment.URI = $"{baseUrl}/{attachment.Id}";
}
var result = mapper.Map<IEnumerable<Db.Attachment>, IEnumerable<Models.Attachment>>(attachments); var result = mapper.Map<IEnumerable<Db.Attachment>, IEnumerable<Models.Attachment>>(attachments);
return (true, result, null); return (true, result, null);
} }
@ -91,6 +104,10 @@ namespace DamageAssesment.Api.Attachments.Providers
List<Db.Attachment> attachments = mapper.Map<List<Models.Attachment>, List<Db.Attachment>>(Attachments); List<Db.Attachment> attachments = mapper.Map<List<Models.Attachment>, List<Db.Attachment>>(Attachments);
AttachmentDbContext.Attachments.UpdateRange(attachments); AttachmentDbContext.Attachments.UpdateRange(attachments);
await AttachmentDbContext.SaveChangesAsync(); await AttachmentDbContext.SaveChangesAsync();
foreach (var attachment in attachments)
{
attachment.URI = $"{baseUrl}/{attachment.Id}";
}
var result = mapper.Map<IEnumerable<Db.Attachment>, IEnumerable<Models.Attachment>>(attachments); var result = mapper.Map<IEnumerable<Db.Attachment>, IEnumerable<Models.Attachment>>(attachments);
return (true, result, null); return (true, result, null);
} }
@ -197,6 +214,24 @@ namespace DamageAssesment.Api.Attachments.Providers
{ {
return AttachmentDbContext.Attachments.AsNoTracking().Count(e => e.Id == id && !e.IsDeleted) > 0; return AttachmentDbContext.Attachments.AsNoTracking().Count(e => e.Id == id && !e.IsDeleted) > 0;
} }
public async Task<(bool IsSuccess, Models.Attachment Attachment, string Path)> GetDownloadAttachmentAsync(int Id)
{
try
{
Db.Attachment Attachment = AttachmentDbContext.Attachments.Where(a => a.Id == Id).AsNoTracking().FirstOrDefault();
if (Attachment == null)
{
return (false, null, "Not Found");
}
return (true, mapper.Map<Db.Attachment, Models.Attachment>(Attachment), $"Attachment {Id}");
}
catch (Exception ex)
{
logger?.LogError(ex.ToString());
return (false, null, ex.Message);
}
}
private void SeedData() private void SeedData()
{ {

View File

@ -24,6 +24,23 @@ namespace DamageAssesment.Api.Attachments.Providers
uploadpath = configuration.GetValue<string>("Fileupload:folderpath"); uploadpath = configuration.GetValue<string>("Fileupload:folderpath");
Deletepath = configuration.GetValue<string>("Fileupload:Deletepath"); Deletepath = configuration.GetValue<string>("Fileupload:Deletepath");
} }
public async Task<byte[]> DownloadFile(string path)
{
try
{
if (System.IO.File.Exists(path))
{
return await System.IO.File.ReadAllBytesAsync(path);
}
return null; // File not found
}
catch (Exception ex)
{
// Handle or log the exception as needed
throw;
}
}
public List<Models.Attachment> UploadAttachment(int responseId,int answerId,int counter, List<IFormFile> postedFile) public List<Models.Attachment> UploadAttachment(int responseId,int answerId,int counter, List<IFormFile> postedFile)
{ {
var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), uploadpath); var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), uploadpath);
@ -89,7 +106,7 @@ namespace DamageAssesment.Api.Attachments.Providers
{ {
counter++; counter++;
var UserfileName = Path.GetFileName(file.FileName); var UserfileName = Path.GetFileName(file.FileName+ file.FileExtension);
var fileName = String.Format("Attachment_{0}{1}", counter, file.FileExtension); var fileName = String.Format("Attachment_{0}{1}", counter, file.FileExtension);
var dbPath = Path.Combine(fullDirectoryPath, fileName); var dbPath = Path.Combine(fullDirectoryPath, fileName);
File.WriteAllBytes(dbPath, Convert.FromBase64String(file.FileContent)); File.WriteAllBytes(dbPath, Convert.FromBase64String(file.FileContent));
@ -126,7 +143,7 @@ namespace DamageAssesment.Api.Attachments.Providers
foreach (var file in item.postedFiles) foreach (var file in item.postedFiles)
{ {
Models.Attachment attachment= attachments.Where(a=>a.Id == file.AttachmentId).FirstOrDefault(); Models.Attachment attachment= attachments.Where(a=>a.Id == file.AttachmentId).FirstOrDefault();
var UserfileName = Path.GetFileName(file.FileName); var UserfileName = Path.GetFileName(file.FileName + file.FileExtension);
var fileName = String.Format("Attachment_{0}{1}", attachment?.Id, file.FileExtension); var fileName = String.Format("Attachment_{0}{1}", attachment?.Id, file.FileExtension);
var dbPath = Path.Combine(fullDirectoryPath, fileName); var dbPath = Path.Combine(fullDirectoryPath, fileName);
File.WriteAllBytes(dbPath, Convert.FromBase64String(file.FileContent)); File.WriteAllBytes(dbPath, Convert.FromBase64String(file.FileContent));

View File

@ -111,7 +111,31 @@ namespace DamageAssesment.Api.DocuLinks.Controllers
return NotFound(); return NotFound();
} }
/// <summary> /// <summary>
/// Get all documents. /// download an existing attachment.
/// </summary>
[Authorize(Roles = "admin")]
[HttpGet("doculinks/download/{id}")]
public async Task<IActionResult> downloadfile1(int id)
{
try
{
var result = await this.documentsProvider.GetDownloadAttachmentAsync(id);
if (!result.IsSuccess)
return NotFound();
byte[] fileContent = await uploadService.DownloadFile(result.DoculinkAttachments.Path);
if (fileContent == null || fileContent.Length == 0)
return NotFound();
var contentType = "application/octet-stream";
return File(fileContent, contentType, result.DoculinkAttachments.docName);
}
catch (Exception ex)
{
// Handle the exception here or log it
return StatusCode(500, "An error occurred: " + ex.Message);
}
}
/// <summary>
/// Get all Doculink.
/// </summary> /// </summary>
[Authorize(Roles = "admin")] [Authorize(Roles = "admin")]

View File

@ -12,6 +12,7 @@ namespace DamageAssesment.Api.DocuLinks.Interfaces
Task<(bool IsSuccess, Models.ResDoculink Document, string ErrorMessage)> PostDocumentAsync(Models.Doculink Document); 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)> UpdateDocumentAsync(int id, Models.Doculink Document);
Task<(bool IsSuccess, Models.ResDoculink Document, string ErrorMessage)> DeleteDocumentAsync(int id); Task<(bool IsSuccess, Models.ResDoculink Document, string ErrorMessage)> DeleteDocumentAsync(int id);
Task<(bool IsSuccess, Models.DoculinkAttachments DoculinkAttachments, string Path)> GetDownloadAttachmentAsync(int id);
Task<(bool IsSuccess, int counter, string message)> GetDocumentCounter(); Task<(bool IsSuccess, int counter, string message)> GetDocumentCounter();

View File

@ -7,6 +7,7 @@ namespace DamageAssesment.Api.DocuLinks.Interfaces
Models.Doculink UploadDocument( int counter, ReqDoculink documentInfo); Models.Doculink UploadDocument( int counter, ReqDoculink documentInfo);
public Models.Doculink UpdateDocuments(int counter, Models.Doculink document, ReqDoculink documentInfo); public Models.Doculink UpdateDocuments(int counter, Models.Doculink document, ReqDoculink documentInfo);
void Deletefile(string path); void Deletefile(string path);
Task<byte[]> DownloadFile(string path);
void Movefile(string path); void Movefile(string path);
} }
} }

View File

@ -69,6 +69,7 @@ builder.Services.AddSwaggerGen(options =>
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(); builder.Services.AddSwaggerGen();
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
builder.Services.AddScoped<IDoculinkProvider, DoculinkProvider>(); builder.Services.AddScoped<IDoculinkProvider, DoculinkProvider>();
builder.Services.AddScoped<IUploadService, UploadService>(); builder.Services.AddScoped<IUploadService, UploadService>();
builder.Services.AddScoped<IAzureBlobService, AzureBlobService>(); builder.Services.AddScoped<IAzureBlobService, AzureBlobService>();

View File

@ -2,10 +2,12 @@
using DamageAssesment.Api.DocuLinks.Db; using DamageAssesment.Api.DocuLinks.Db;
using DamageAssesment.Api.DocuLinks.Interfaces; using DamageAssesment.Api.DocuLinks.Interfaces;
using DamageAssesment.Api.DocuLinks.Models; using DamageAssesment.Api.DocuLinks.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System; using System;
using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Diagnostics.Eventing.Reader; using System.Diagnostics.Eventing.Reader;
using System.Reflection.Metadata; using System.Reflection.Metadata;
@ -24,13 +26,18 @@ namespace DamageAssesment.Api.DocuLinks.Providers
private IUploadService uploadservice; private IUploadService uploadservice;
private IAzureBlobService azureBlobService; private IAzureBlobService azureBlobService;
private IMapper mapper; private IMapper mapper;
private readonly IHttpContextAccessor httpContextAccessor;
private string baseUrl;
public DoculinkProvider(DoculinkDbContext DocumentDbContext, ILogger<DoculinkProvider> logger, IMapper mapper, IUploadService uploadservice, IAzureBlobService azureBlobService) public DoculinkProvider(DoculinkDbContext DocumentDbContext, ILogger<DoculinkProvider> logger, IMapper mapper, IUploadService uploadservice, IAzureBlobService azureBlobService, IHttpContextAccessor httpContextAccessor)
{ {
this.DocumentDbContext = DocumentDbContext; this.DocumentDbContext = DocumentDbContext;
this.logger = logger; this.logger = logger;
this.mapper = mapper; this.mapper = mapper;
this.uploadservice = uploadservice; this.uploadservice = uploadservice;
this.httpContextAccessor = httpContextAccessor;
baseUrl = $"{httpContextAccessor.HttpContext.Request.Scheme}://{httpContextAccessor.HttpContext.Request.Host}";
baseUrl = baseUrl + "/doculinks/download";
this.azureBlobService = azureBlobService; this.azureBlobService = azureBlobService;
//SeedData(); //SeedData();
} }
@ -175,15 +182,38 @@ namespace DamageAssesment.Api.DocuLinks.Providers
} }
private List<Models.DoculinkAttachments> GetDocumentAttachment(int id,string? language) private List<Models.DoculinkAttachments> GetDocumentAttachment(int id,string? language)
{ {
List<Db.DoculinkAttachments> doculinkAttachments = null;
if (string.IsNullOrEmpty(language)) if (string.IsNullOrEmpty(language))
{ {
return mapper.Map<List<Db.DoculinkAttachments>, List<Models.DoculinkAttachments>>( doculinkAttachments = DocumentDbContext.DoclinksAttachments.AsNoTracking().Where(a => a.DocumentId == id).ToList();
DocumentDbContext.DoclinksAttachments.AsNoTracking().Where(a => a.DocumentId == id).ToList());
} }
else else
{ {
return mapper.Map<List<Db.DoculinkAttachments>, List<Models.DoculinkAttachments>>( doculinkAttachments = DocumentDbContext.DoclinksAttachments.AsNoTracking().Where(a => a.DocumentId == id && a.Language == language).ToList();
DocumentDbContext.DoclinksAttachments.AsNoTracking().Where(a => a.DocumentId == id && a.Language == language).ToList()); }
foreach (var attachment in doculinkAttachments)
{
if (attachment.IsAttachments)
attachment.Path = $"{baseUrl}/{attachment.Id}";
}
return mapper.Map<List<Db.DoculinkAttachments>, List<Models.DoculinkAttachments>>(doculinkAttachments);
}
public async Task<(bool IsSuccess, Models.DoculinkAttachments DoculinkAttachments, string Path)> GetDownloadAttachmentAsync(int id)
{
try
{
Db.DoculinkAttachments Attachment = DocumentDbContext.DoclinksAttachments.AsNoTracking().Where(a => a.Id == id).AsNoTracking().FirstOrDefault();
if (Attachment == null)
{
return (false, null, "Not Found");
}
return (true, mapper.Map<Db.DoculinkAttachments, Models.DoculinkAttachments>(Attachment), $"Attachment {id}");
}
catch (Exception ex)
{
logger?.LogError(ex.ToString());
return (false, null, ex.Message);
} }
} }
public async Task<(bool IsSuccess, IEnumerable<Models.ResDoculink> documents, string ErrorMessage)> GetdocumentsByLinkTypeIdAsync(int? linkTypeId, string? language, bool? isactive) public async Task<(bool IsSuccess, IEnumerable<Models.ResDoculink> documents, string ErrorMessage)> GetdocumentsByLinkTypeIdAsync(int? linkTypeId, string? language, bool? isactive)
@ -360,7 +390,7 @@ namespace DamageAssesment.Api.DocuLinks.Providers
result.linktypes = CreateMultiLanguageLinkTypeObject(GetLinkTypeTranslations(Document.linkTypeId, "")); result.linktypes = CreateMultiLanguageLinkTypeObject(GetLinkTypeTranslations(Document.linkTypeId, ""));
result.titles = multilan.titles; result.titles = multilan.titles;
result.description = multilan.description; result.description = multilan.description;
result.doclinksAttachments = Document.doclinksAttachments; result.doclinksAttachments = GetDocumentAttachment(document.Id,"");
return (true, result, null); return (true, result, null);
} }
catch (Exception ex) catch (Exception ex)
@ -402,7 +432,7 @@ namespace DamageAssesment.Api.DocuLinks.Providers
result.linktypes = CreateMultiLanguageLinkTypeObject(GetLinkTypeTranslations(document.linkTypeId, "")); result.linktypes = CreateMultiLanguageLinkTypeObject(GetLinkTypeTranslations(document.linkTypeId, ""));
result.titles = multilan.titles; result.titles = multilan.titles;
result.description = multilan.description; result.description = multilan.description;
result.doclinksAttachments = Document.doclinksAttachments; result.doclinksAttachments = GetDocumentAttachment(document.Id, "");
return (true, result, "Successful"); return (true, result, "Successful");
} }
else else
@ -440,7 +470,8 @@ namespace DamageAssesment.Api.DocuLinks.Providers
result.titles = multilan.titles; result.titles = multilan.titles;
result.description = multilan.description; result.description = multilan.description;
result.linktypes = CreateMultiLanguageLinkTypeObject(GetLinkTypeTranslations(result.linkTypeId, "")); result.linktypes = CreateMultiLanguageLinkTypeObject(GetLinkTypeTranslations(result.linkTypeId, ""));
result.doclinksAttachments = GetDocumentAttachment(id, ""); result.doclinksAttachments = mapper.Map<List<Db.DoculinkAttachments>, List<Models.DoculinkAttachments>>(
DocumentDbContext.DoclinksAttachments.AsNoTracking().Where(a => a.DocumentId == id).ToList());
Document.IsActive = false; Document.IsActive = false;
DocumentDbContext.Documents.Update(Document); DocumentDbContext.Documents.Update(Document);
DocumentDbContext.SaveChanges(); DocumentDbContext.SaveChanges();

View File

@ -25,6 +25,23 @@ namespace DamageAssesment.Api.DocuLinks.Providers
uploadpath = configuration.GetValue<string>("Fileupload:folderpath"); uploadpath = configuration.GetValue<string>("Fileupload:folderpath");
Deletepath = configuration.GetValue<string>("Fileupload:Deletepath"); Deletepath = configuration.GetValue<string>("Fileupload:Deletepath");
} }
public async Task<byte[]> DownloadFile(string path)
{
try
{
if (System.IO.File.Exists(path))
{
return await System.IO.File.ReadAllBytesAsync(path);
}
return null; // File not found
}
catch (Exception ex)
{
// Handle or log the exception as needed
throw;
}
}
public Models.Doculink UploadDocument(int counter, ReqDoculink documentInfo) public Models.Doculink UploadDocument(int counter, ReqDoculink documentInfo)
{ {
@ -44,7 +61,7 @@ namespace DamageAssesment.Api.DocuLinks.Providers
counter++; counter++;
if (item.IsAttachments) if (item.IsAttachments)
{ {
UserfileName = Path.GetFileName(item.FileName); UserfileName = Path.GetFileName(item.FileName + item.FileExtension);
var fileName = String.Format("Document_{0}{1}", counter, item.FileExtension); var fileName = String.Format("Document_{0}{1}", counter, item.FileExtension);
path = Path.Combine(fullDirectoryPath, fileName); path = Path.Combine(fullDirectoryPath, fileName);
File.WriteAllBytes(path, Convert.FromBase64String(item.FileContent)); File.WriteAllBytes(path, Convert.FromBase64String(item.FileContent));
@ -85,7 +102,7 @@ namespace DamageAssesment.Api.DocuLinks.Providers
{ {
if (item.IsAttachments) if (item.IsAttachments)
{ {
UserfileName = Path.GetFileName(item.FileName); UserfileName = Path.GetFileName(item.FileName+item.FileExtension);
var fileName = String.Format("Document_{0}_{1}{2}", document.Id, counter1, item.FileExtension); var fileName = String.Format("Document_{0}_{1}{2}", document.Id, counter1, item.FileExtension);
path = Path.Combine(fullDirectoryPath, fileName); path = Path.Combine(fullDirectoryPath, fileName);
File.WriteAllBytes(path, Convert.FromBase64String(item.FileContent)); File.WriteAllBytes(path, Convert.FromBase64String(item.FileContent));