forked from MDCPS/DamageAssessment_Backend
Compare commits
13 Commits
user-acces
...
docker-Azu
Author | SHA1 | Date | |
---|---|---|---|
48af2f3623 | |||
4885311290 | |||
cc9619e92e | |||
bbe8008fc2 | |||
027097d12d | |||
f79fd71fea | |||
26096f108a | |||
4eb8f84d5b | |||
15acd00959 | |||
46520c7e62 | |||
f6387fc371 | |||
4ebd40108d | |||
77816605d1 |
@ -11,7 +11,7 @@
|
|||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
//"AnswerConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
//"AnswerConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
||||||
"AnswerConnection": "Server=207.180.248.35;Database=da_survey_dev;User Id=sa;Password=YourStrongPassw0rd;TrustServerCertificate=True;"
|
"AnswerConnection": "Server=tcp:da-dev.database.windows.net,1433;Initial Catalog=da-dev-db;Encrypt=True;User ID=admin-dev;Password=b3tgRABw8LGE75k;TrustServerCertificate=False;Connection Timeout=30;"
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ namespace DamageAssesment.Api.Attachments.Test
|
|||||||
public async Task GetAttachmentsAsync_ShouldReturnStatusCode200()
|
public async Task GetAttachmentsAsync_ShouldReturnStatusCode200()
|
||||||
{
|
{
|
||||||
var mockAttachmentService = new Mock<IAttachmentsProvider>();
|
var mockAttachmentService = new Mock<IAttachmentsProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await MockData.getOkResponse();
|
var mockResponse = await MockData.getOkResponse();
|
||||||
mockAttachmentService.Setup(service => service.GetAttachmentsAsync()).ReturnsAsync(mockResponse);
|
mockAttachmentService.Setup(service => service.GetAttachmentsAsync()).ReturnsAsync(mockResponse);
|
||||||
var AttachmentProvider = new AttachmentsController(mockAttachmentService.Object, mockUploadService.Object);
|
var AttachmentProvider = new AttachmentsController(mockAttachmentService.Object, mockUploadService.Object);
|
||||||
@ -33,7 +33,7 @@ namespace DamageAssesment.Api.Attachments.Test
|
|||||||
public async Task GetAttachmentsAsync_ShouldReturnStatusCode204()
|
public async Task GetAttachmentsAsync_ShouldReturnStatusCode204()
|
||||||
{
|
{
|
||||||
var mockAttachmentService = new Mock<IAttachmentsProvider>();
|
var mockAttachmentService = new Mock<IAttachmentsProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await MockData.getNoContentResponse();
|
var mockResponse = await MockData.getNoContentResponse();
|
||||||
mockAttachmentService.Setup(service => service.GetAttachmentsAsync()).ReturnsAsync(mockResponse);
|
mockAttachmentService.Setup(service => service.GetAttachmentsAsync()).ReturnsAsync(mockResponse);
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ namespace DamageAssesment.Api.Attachments.Test
|
|||||||
public async Task GetAttachmentAsync_ShouldReturnStatusCode200()
|
public async Task GetAttachmentAsync_ShouldReturnStatusCode200()
|
||||||
{
|
{
|
||||||
var mockAttachmentService = new Mock<IAttachmentsProvider>();
|
var mockAttachmentService = new Mock<IAttachmentsProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await MockData.getOkResponse(1);
|
var mockResponse = await MockData.getOkResponse(1);
|
||||||
mockAttachmentService.Setup(service => service.GetAttachmentByIdAsync(1)).ReturnsAsync(mockResponse);
|
mockAttachmentService.Setup(service => service.GetAttachmentByIdAsync(1)).ReturnsAsync(mockResponse);
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ namespace DamageAssesment.Api.Attachments.Test
|
|||||||
public async Task GetAttachmentAsync_ShouldReturnStatusCode404()
|
public async Task GetAttachmentAsync_ShouldReturnStatusCode404()
|
||||||
{
|
{
|
||||||
var mockAttachmentService = new Mock<IAttachmentsProvider>();
|
var mockAttachmentService = new Mock<IAttachmentsProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await MockData.getNotFoundResponse();
|
var mockResponse = await MockData.getNotFoundResponse();
|
||||||
mockAttachmentService.Setup(service => service.GetAttachmentByIdAsync(99)).ReturnsAsync(mockResponse);
|
mockAttachmentService.Setup(service => service.GetAttachmentByIdAsync(99)).ReturnsAsync(mockResponse);
|
||||||
var AttachmentProvider = new AttachmentsController(mockAttachmentService.Object, mockUploadService.Object);
|
var AttachmentProvider = new AttachmentsController(mockAttachmentService.Object, mockUploadService.Object);
|
||||||
@ -73,7 +73,7 @@ namespace DamageAssesment.Api.Attachments.Test
|
|||||||
public async Task PostAttachmentAsync_ShouldReturnStatusCode200()
|
public async Task PostAttachmentAsync_ShouldReturnStatusCode200()
|
||||||
{
|
{
|
||||||
var mockAttachmentService = new Mock<IAttachmentsProvider>();
|
var mockAttachmentService = new Mock<IAttachmentsProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await MockData.getOkResponse();
|
var mockResponse = await MockData.getOkResponse();
|
||||||
var AttachmentResponse = await MockData.GetAttachmentInfo(0);
|
var AttachmentResponse = await MockData.GetAttachmentInfo(0);
|
||||||
var mockInputAttachment = await MockData.getInputAttachmentData();
|
var mockInputAttachment = await MockData.getInputAttachmentData();
|
||||||
@ -89,7 +89,7 @@ namespace DamageAssesment.Api.Attachments.Test
|
|||||||
public async Task PostAttachmentAsync_ShouldReturnStatusCode400()
|
public async Task PostAttachmentAsync_ShouldReturnStatusCode400()
|
||||||
{
|
{
|
||||||
var mockAttachmentService = new Mock<IAttachmentsProvider>();
|
var mockAttachmentService = new Mock<IAttachmentsProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockInputAttachment = await MockData.getInputAttachmentData();
|
var mockInputAttachment = await MockData.getInputAttachmentData();
|
||||||
var mockResponse = await MockData.getBadRequestResponse();
|
var mockResponse = await MockData.getBadRequestResponse();
|
||||||
mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).ReturnsAsync(mockResponse);
|
mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).ReturnsAsync(mockResponse);
|
||||||
@ -105,7 +105,7 @@ namespace DamageAssesment.Api.Attachments.Test
|
|||||||
public async Task PutAttachmentAsync_ShouldReturnStatusCode200()
|
public async Task PutAttachmentAsync_ShouldReturnStatusCode200()
|
||||||
{
|
{
|
||||||
var mockAttachmentService = new Mock<IAttachmentsProvider>();
|
var mockAttachmentService = new Mock<IAttachmentsProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await MockData.getOkResponse();
|
var mockResponse = await MockData.getOkResponse();
|
||||||
var AttachmentResponse = await MockData.GetAttachmentInfo(1);
|
var AttachmentResponse = await MockData.GetAttachmentInfo(1);
|
||||||
var mockInputAttachment = await MockData.getInputAttachmentData();
|
var mockInputAttachment = await MockData.getInputAttachmentData();
|
||||||
@ -121,7 +121,7 @@ namespace DamageAssesment.Api.Attachments.Test
|
|||||||
public async Task PutAttachmentAsync_ShouldReturnStatusCode400()
|
public async Task PutAttachmentAsync_ShouldReturnStatusCode400()
|
||||||
{
|
{
|
||||||
var mockAttachmentService = new Mock<IAttachmentsProvider>();
|
var mockAttachmentService = new Mock<IAttachmentsProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockInputAttachment = await MockData.getInputAttachmentData();
|
var mockInputAttachment = await MockData.getInputAttachmentData();
|
||||||
var mockResponse = await MockData.getBadRequestResponse();
|
var mockResponse = await MockData.getBadRequestResponse();
|
||||||
mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).ReturnsAsync(mockResponse);
|
mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).ReturnsAsync(mockResponse);
|
||||||
@ -136,7 +136,7 @@ namespace DamageAssesment.Api.Attachments.Test
|
|||||||
public async Task DeleteAttachmentAsync_ShouldReturnStatusCode200()
|
public async Task DeleteAttachmentAsync_ShouldReturnStatusCode200()
|
||||||
{
|
{
|
||||||
var mockAttachmentService = new Mock<IAttachmentsProvider>();
|
var mockAttachmentService = new Mock<IAttachmentsProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await MockData.getOkResponse(1);
|
var mockResponse = await MockData.getOkResponse(1);
|
||||||
mockAttachmentService.Setup(service => service.DeleteAttachmentAsync(1)).ReturnsAsync(mockResponse);
|
mockAttachmentService.Setup(service => service.DeleteAttachmentAsync(1)).ReturnsAsync(mockResponse);
|
||||||
mockUploadService.Setup(service => service.Deletefile(""));
|
mockUploadService.Setup(service => service.Deletefile(""));
|
||||||
@ -150,7 +150,7 @@ namespace DamageAssesment.Api.Attachments.Test
|
|||||||
public async Task DeleteAttachmentAsync_ShouldReturnStatusCode404()
|
public async Task DeleteAttachmentAsync_ShouldReturnStatusCode404()
|
||||||
{
|
{
|
||||||
var mockAttachmentService = new Mock<IAttachmentsProvider>();
|
var mockAttachmentService = new Mock<IAttachmentsProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await MockData.getNotFoundResponse();
|
var mockResponse = await MockData.getNotFoundResponse();
|
||||||
mockAttachmentService.Setup(service => service.DeleteAttachmentAsync(1)).ReturnsAsync(mockResponse);
|
mockAttachmentService.Setup(service => service.DeleteAttachmentAsync(1)).ReturnsAsync(mockResponse);
|
||||||
var AttachmentProvider = new AttachmentsController(mockAttachmentService.Object, mockUploadService.Object);
|
var AttachmentProvider = new AttachmentsController(mockAttachmentService.Object, mockUploadService.Object);
|
||||||
|
@ -15,10 +15,10 @@ namespace DamageAssesment.Api.Attachments.Controllers
|
|||||||
private IUploadService UploadService;
|
private IUploadService UploadService;
|
||||||
private IAzureBlobService azureBlobService;
|
private IAzureBlobService azureBlobService;
|
||||||
|
|
||||||
public AttachmentsController(IAttachmentsProvider AttachmentsProvider, IUploadService UploadService)
|
public AttachmentsController(IAttachmentsProvider AttachmentsProvider, IAzureBlobService azureBlobService)
|
||||||
{
|
{
|
||||||
this.AttachmentProvider = AttachmentsProvider;
|
this.AttachmentProvider = AttachmentsProvider;
|
||||||
this.UploadService = UploadService;
|
this.azureBlobService = azureBlobService;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get all attachments.
|
/// Get all attachments.
|
||||||
@ -92,7 +92,7 @@ namespace DamageAssesment.Api.Attachments.Controllers
|
|||||||
if (attachmentInfo.Answers.Count > 0)
|
if (attachmentInfo.Answers.Count > 0)
|
||||||
{
|
{
|
||||||
var Attachments = await this.AttachmentProvider.GetAttachmentCounter();
|
var Attachments = await this.AttachmentProvider.GetAttachmentCounter();
|
||||||
List<Models.Attachment> attachments = UploadService.UploadAttachment(attachmentInfo.ResponseId, Attachments.counter, attachmentInfo.Answers);
|
List<Models.Attachment> attachments = await azureBlobService.UploadAttachment(attachmentInfo.ResponseId, Attachments.counter, attachmentInfo.Answers);
|
||||||
var result = await this.AttachmentProvider.PostAttachmentAsync(attachments);
|
var result = await this.AttachmentProvider.PostAttachmentAsync(attachments);
|
||||||
if (result.IsSuccess)
|
if (result.IsSuccess)
|
||||||
{
|
{
|
||||||
@ -121,7 +121,7 @@ namespace DamageAssesment.Api.Attachments.Controllers
|
|||||||
var res = await this.AttachmentProvider.GetAttachmentInfo(attachmentInfo.Answers);
|
var res = await this.AttachmentProvider.GetAttachmentInfo(attachmentInfo.Answers);
|
||||||
if (res.IsSuccess)
|
if (res.IsSuccess)
|
||||||
{
|
{
|
||||||
List<Models.Attachment> attachments = UploadService.UpdateAttachments(attachmentInfo.ResponseId, attachmentInfo.Answers, res.Attachments);
|
List<Models.Attachment> attachments = await azureBlobService.UpdateAttachments(attachmentInfo.ResponseId, attachmentInfo.Answers, res.Attachments);
|
||||||
var result = await this.AttachmentProvider.PutAttachmentAsync(attachments);
|
var result = await this.AttachmentProvider.PutAttachmentAsync(attachments);
|
||||||
if (result.IsSuccess)
|
if (result.IsSuccess)
|
||||||
{
|
{
|
||||||
@ -139,81 +139,6 @@ namespace DamageAssesment.Api.Attachments.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// download an existing attachment.
|
|
||||||
/// </summary>
|
|
||||||
[Authorize(Roles = "admin")]
|
|
||||||
[HttpGet("attachments/download/{id}")]
|
|
||||||
public async Task<IActionResult> downloadfile(int id)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var result = await this.AttachmentProvider.GetDownloadAttachmentAsync(id);
|
|
||||||
if (!result.IsSuccess)
|
|
||||||
return NotFound();
|
|
||||||
string path = await UploadService.GetFile(result.Attachment.URI);
|
|
||||||
if (path == null)
|
|
||||||
return NotFound();
|
|
||||||
var contentType = GetContentType(result.Attachment.FileName);
|
|
||||||
if (contentType == "application/octet-stream")
|
|
||||||
return PhysicalFile(path, contentType, result.Attachment.FileName);
|
|
||||||
return PhysicalFile(path, contentType, enableRangeProcessing: true);// result.Attachment.FileName);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
// Handle the exception here or log it
|
|
||||||
return StatusCode(500, "An error occurred: " + ex.Message);
|
|
||||||
}
|
|
||||||
//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);
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
private string GetContentType(string fileName)
|
|
||||||
{
|
|
||||||
// You can add more content types based on the file extensions
|
|
||||||
switch (Path.GetExtension(fileName).ToLower())
|
|
||||||
{
|
|
||||||
//case ".txt":
|
|
||||||
// return "text/plain";
|
|
||||||
case ".jpg":
|
|
||||||
case ".jpeg":
|
|
||||||
return "image/jpeg";
|
|
||||||
case ".png":
|
|
||||||
return "image/png";
|
|
||||||
case ".gif":
|
|
||||||
return "image/gif";
|
|
||||||
case ".bmp":
|
|
||||||
return "image/bmp";
|
|
||||||
case ".webp":
|
|
||||||
return "image/webp";
|
|
||||||
case ".csv":
|
|
||||||
return "text/csv";
|
|
||||||
case ".pdf":
|
|
||||||
return "application/pdf";
|
|
||||||
case ".docx":
|
|
||||||
case ".doc":
|
|
||||||
return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
||||||
case ".xlsx":
|
|
||||||
case ".xls":
|
|
||||||
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
||||||
// Add more cases as needed
|
|
||||||
default:
|
|
||||||
return "application/octet-stream";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Delete an existing attachment.
|
/// Delete an existing attachment.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Authorize(Roles = "admin")]
|
[Authorize(Roles = "admin")]
|
||||||
@ -225,7 +150,7 @@ namespace DamageAssesment.Api.Attachments.Controllers
|
|||||||
if (result.IsSuccess)
|
if (result.IsSuccess)
|
||||||
{
|
{
|
||||||
// deleting file from folder
|
// deleting file from folder
|
||||||
UploadService.Movefile(result.Attachment.URI);
|
azureBlobService.Movefile(result.Attachment.URI);
|
||||||
return Ok(result.Attachment);
|
return Ok(result.Attachment);
|
||||||
}
|
}
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
@ -9,7 +9,6 @@ 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();
|
||||||
|
@ -7,8 +7,6 @@ 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);
|
|
||||||
Task<string> GetFile(string path);
|
|
||||||
void Deletefile(string path);
|
void Deletefile(string path);
|
||||||
void Movefile(string path);
|
void Movefile(string path);
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,6 @@ 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>();
|
||||||
|
@ -14,17 +14,13 @@ namespace DamageAssesment.Api.Attachments.Providers
|
|||||||
private ILogger<AttachmentsProvider> logger;
|
private ILogger<AttachmentsProvider> logger;
|
||||||
private IUploadService uploadservice;
|
private IUploadService uploadservice;
|
||||||
private IMapper mapper;
|
private IMapper mapper;
|
||||||
private readonly IHttpContextAccessor httpContextAccessor;
|
|
||||||
private string baseUrl;
|
public AttachmentsProvider(AttachmentsDbContext AttachmentDbContext, ILogger<AttachmentsProvider> logger, IMapper mapper,IUploadService uploadservice)
|
||||||
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()
|
||||||
@ -36,10 +32,6 @@ namespace DamageAssesment.Api.Attachments.Providers
|
|||||||
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);
|
||||||
@ -62,7 +54,6 @@ 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);
|
||||||
}
|
}
|
||||||
@ -82,10 +73,6 @@ 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);
|
||||||
}
|
}
|
||||||
@ -104,10 +91,6 @@ 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);
|
||||||
}
|
}
|
||||||
@ -214,24 +197,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -24,41 +24,6 @@ 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<string> GetFile(string path)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (System.IO.File.Exists(path))
|
|
||||||
{
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null; // File not found
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
// Handle or log the exception as needed
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
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);
|
||||||
@ -124,7 +89,7 @@ namespace DamageAssesment.Api.Attachments.Providers
|
|||||||
{
|
{
|
||||||
counter++;
|
counter++;
|
||||||
|
|
||||||
var UserfileName = Path.GetFileName(file.FileName+ file.FileExtension);
|
var UserfileName = Path.GetFileName(file.FileName);
|
||||||
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));
|
||||||
@ -161,7 +126,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 + file.FileExtension);
|
var UserfileName = Path.GetFileName(file.FileName);
|
||||||
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));
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
},
|
},
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
//"AttachmentConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
//"AttachmentConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
||||||
"AttachmentConnection": "Server=207.180.248.35;Database=da_survey_dev;User Id=sa;Password=YourStrongPassw0rd;TrustServerCertificate=True;"
|
"AttachmentConnection": "Server=tcp:da-dev.database.windows.net,1433;Initial Catalog=da-dev-db;Encrypt=True;User ID=admin-dev;Password=b3tgRABw8LGE75k;TrustServerCertificate=False;Connection Timeout=30;"
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task GetDocumentsLanguageAsync_ShouldReturnStatusCode204()
|
public async Task GetDocumentsLanguageAsync_ShouldReturnStatusCode204()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await MockData.getNoContentResponse();
|
var mockResponse = await MockData.getNoContentResponse();
|
||||||
mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms", "en", null)).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms", "en", null)).ReturnsAsync(mockResponse);
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task GetDocumentsLinkTypeAsync_ShouldReturnStatusCode204()
|
public async Task GetDocumentsLinkTypeAsync_ShouldReturnStatusCode204()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await MockData.getNoContentResponse();
|
var mockResponse = await MockData.getNoContentResponse();
|
||||||
mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms", "en", true)).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms", "en", true)).ReturnsAsync(mockResponse);
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task GetDocumentsAsync_ShouldReturnStatusCode200()
|
public async Task GetDocumentsAsync_ShouldReturnStatusCode200()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await MockData.getOkResponses();
|
var mockResponse = await MockData.getOkResponses();
|
||||||
mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms", "en", null)).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms", "en", null)).ReturnsAsync(mockResponse);
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task GetActiveDocumentsAsync_ShouldReturnStatusCode200()
|
public async Task GetActiveDocumentsAsync_ShouldReturnStatusCode200()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await MockData.getOkResponses();
|
var mockResponse = await MockData.getOkResponses();
|
||||||
mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms", "en", true)).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.GetdocumentsByLinkAsync("forms", "en", true)).ReturnsAsync(mockResponse);
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task GetActiveDocumentsLinkTypeIdAsync_ShouldReturnStatusCode200()
|
public async Task GetActiveDocumentsLinkTypeIdAsync_ShouldReturnStatusCode200()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await MockData.getOkResponses();
|
var mockResponse = await MockData.getOkResponses();
|
||||||
mockDocumentService.Setup(service => service.GetdocumentsByLinkTypeIdAsync(null, "en", true)).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.GetdocumentsByLinkTypeIdAsync(null, "en", true)).ReturnsAsync(mockResponse);
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task GetDocumentsLinkTypeIdAsync_ShouldReturnStatusCode204()
|
public async Task GetDocumentsLinkTypeIdAsync_ShouldReturnStatusCode204()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await MockData.getNoContentResponse();
|
var mockResponse = await MockData.getNoContentResponse();
|
||||||
mockDocumentService.Setup(service => service.GetdocumentsByLinkTypeIdAsync(null, "en", true)).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.GetdocumentsByLinkTypeIdAsync(null, "en", true)).ReturnsAsync(mockResponse);
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task GetDocumentAsync_ShouldReturnStatusCode200()
|
public async Task GetDocumentAsync_ShouldReturnStatusCode200()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await MockData.getOkResponse(1);
|
var mockResponse = await MockData.getOkResponse(1);
|
||||||
mockDocumentService.Setup(service => service.GetDocumentAsync(1, "forms", "en")).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.GetDocumentAsync(1, "forms", "en")).ReturnsAsync(mockResponse);
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task GetDocumentAsync_ShouldReturnStatusCode404()
|
public async Task GetDocumentAsync_ShouldReturnStatusCode404()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await MockData.getNotFoundResponse();
|
var mockResponse = await MockData.getNotFoundResponse();
|
||||||
mockDocumentService.Setup(service => service.GetDocumentAsync(99, "forms", "en")).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.GetDocumentAsync(99, "forms", "en")).ReturnsAsync(mockResponse);
|
||||||
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
||||||
@ -120,7 +120,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task PostDocumentAsync_ShouldReturnStatusCode200()
|
public async Task PostDocumentAsync_ShouldReturnStatusCode200()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await MockData.getOkResponse(1);
|
var mockResponse = await MockData.getOkResponse(1);
|
||||||
var mockInputDocument = await MockData.getInputDocumentData();
|
var mockInputDocument = await MockData.getInputDocumentData();
|
||||||
var DocumentResponse = await MockData.GetDocuLinksInfo(0);
|
var DocumentResponse = await MockData.GetDocuLinksInfo(0);
|
||||||
@ -135,7 +135,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task PostDocumentAsync_ShouldReturnStatusCode400()
|
public async Task PostDocumentAsync_ShouldReturnStatusCode400()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockInputDocument = await MockData.getInputDocumentData();
|
var mockInputDocument = await MockData.getInputDocumentData();
|
||||||
var mockResponse = await MockData.getBadRequestResponse();
|
var mockResponse = await MockData.getBadRequestResponse();
|
||||||
ReqDoculink documentInfo = null;
|
ReqDoculink documentInfo = null;
|
||||||
@ -150,7 +150,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task PutDocumentAsync_ShouldReturnStatusCode200()
|
public async Task PutDocumentAsync_ShouldReturnStatusCode200()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await MockData.getOkResponse(1);
|
var mockResponse = await MockData.getOkResponse(1);
|
||||||
var mockInputDocument = await MockData.getInputDocumentData();
|
var mockInputDocument = await MockData.getInputDocumentData();
|
||||||
var DocumentResponse = await MockData.GetDocuLinksInfo(1);
|
var DocumentResponse = await MockData.GetDocuLinksInfo(1);
|
||||||
@ -165,7 +165,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task PutDocumentAsync_ShouldReturnStatusCode400()
|
public async Task PutDocumentAsync_ShouldReturnStatusCode400()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await MockData.getBadRequestResponse();
|
var mockResponse = await MockData.getBadRequestResponse();
|
||||||
var mockInputDocument = await MockData.getInputDocumentData();
|
var mockInputDocument = await MockData.getInputDocumentData();
|
||||||
mockDocumentService.Setup(service => service.UpdateDocumentAsync(99, mockInputDocument)).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.UpdateDocumentAsync(99, mockInputDocument)).ReturnsAsync(mockResponse);
|
||||||
@ -178,7 +178,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task DeleteDocumentAsync_ShouldReturnStatusCode200()
|
public async Task DeleteDocumentAsync_ShouldReturnStatusCode200()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await MockData.getOkResponse(1);
|
var mockResponse = await MockData.getOkResponse(1);
|
||||||
mockDocumentService.Setup(service => service.DeleteDocumentAsync(1)).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.DeleteDocumentAsync(1)).ReturnsAsync(mockResponse);
|
||||||
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
||||||
@ -190,36 +190,14 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task DeleteDocumentAsync_ShouldReturnStatusCode404()
|
public async Task DeleteDocumentAsync_ShouldReturnStatusCode404()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await MockData.getNotFoundResponse();
|
var mockResponse = await MockData.getNotFoundResponse();
|
||||||
mockDocumentService.Setup(service => service.DeleteDocumentAsync(1)).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.DeleteDocumentAsync(1)).ReturnsAsync(mockResponse);
|
||||||
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
||||||
var result = (NotFoundResult)await DocumentProvider.DeleteDocument(1);
|
var result = (NotFoundResult)await DocumentProvider.DeleteDocument(1);
|
||||||
Assert.Equal(404, result.StatusCode);
|
Assert.Equal(404, result.StatusCode);
|
||||||
}
|
}
|
||||||
[Fact(DisplayName = "Update Document IsActive- Ok case")]
|
|
||||||
public async Task UpdateDocumentAsync_ShouldReturnStatusCode200()
|
|
||||||
{
|
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
|
||||||
var mockResponse = await MockData.getOkResponse(1);
|
|
||||||
mockDocumentService.Setup(service => service.UpdateDocumentAsync(1,true)).ReturnsAsync(mockResponse);
|
|
||||||
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
|
||||||
var result = (OkObjectResult)await DocumentProvider.UpdateIsActiveDocument(1,true);
|
|
||||||
|
|
||||||
Assert.Equal(200, result.StatusCode);
|
|
||||||
}
|
|
||||||
[Fact(DisplayName = "Update Document IsActive - NotFound case")]
|
|
||||||
public async Task UpdateDocumentAsync_ShouldReturnStatusCode404()
|
|
||||||
{
|
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
|
||||||
var mockResponse = await MockData.getNotFoundResponse();
|
|
||||||
mockDocumentService.Setup(service => service.UpdateDocumentAsync(1,true)).ReturnsAsync(mockResponse);
|
|
||||||
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
|
||||||
var result = (NotFoundResult)await DocumentProvider.UpdateIsActiveDocument(1,true);
|
|
||||||
Assert.Equal(404, result.StatusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Link Type Test cases
|
// Link Type Test cases
|
||||||
|
|
||||||
@ -228,7 +206,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task GetDocumentCategoriesAsync_ShouldReturnStatusCode200()
|
public async Task GetDocumentCategoriesAsync_ShouldReturnStatusCode200()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await LinkTypeMockData.getOkResponse();
|
var mockResponse = await LinkTypeMockData.getOkResponse();
|
||||||
mockDocumentService.Setup(service => service.GetLinkTypesAsync("en")).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.GetLinkTypesAsync("en")).ReturnsAsync(mockResponse);
|
||||||
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
||||||
@ -241,7 +219,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task GetDocumentCategoriesAsync_ShouldReturnStatusCode204()
|
public async Task GetDocumentCategoriesAsync_ShouldReturnStatusCode204()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await LinkTypeMockData.getNoContentResponse();
|
var mockResponse = await LinkTypeMockData.getNoContentResponse();
|
||||||
mockDocumentService.Setup(service => service.GetLinkTypesAsync("en")).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.GetLinkTypesAsync("en")).ReturnsAsync(mockResponse);
|
||||||
|
|
||||||
@ -255,7 +233,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task GetDocumentcategoryAsync_ShouldReturnStatusCode200()
|
public async Task GetDocumentcategoryAsync_ShouldReturnStatusCode200()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await LinkTypeMockData.getOkResponse(1);
|
var mockResponse = await LinkTypeMockData.getOkResponse(1);
|
||||||
mockDocumentService.Setup(service => service.GetLinkTypeAsync(1, "en")).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.GetLinkTypeAsync(1, "en")).ReturnsAsync(mockResponse);
|
||||||
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
var DocumentProvider = new DoculinkController(mockDocumentService.Object, mockUploadService.Object);
|
||||||
@ -268,7 +246,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task GetDocumentcategoryAsync_ShouldReturnStatusCode404()
|
public async Task GetDocumentcategoryAsync_ShouldReturnStatusCode404()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await LinkTypeMockData.getNotFoundResponse();
|
var mockResponse = await LinkTypeMockData.getNotFoundResponse();
|
||||||
mockDocumentService.Setup(service => service.GetLinkTypeAsync(99, "en")).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.GetLinkTypeAsync(99, "en")).ReturnsAsync(mockResponse);
|
||||||
|
|
||||||
@ -281,7 +259,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task PostDocumentcategoryAsync_ShouldReturnStatusCode200()
|
public async Task PostDocumentcategoryAsync_ShouldReturnStatusCode200()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await LinkTypeMockData.getOkResponse(1);
|
var mockResponse = await LinkTypeMockData.getOkResponse(1);
|
||||||
var mockInputDocument = await LinkTypeMockData.getInputLinkData(0);
|
var mockInputDocument = await LinkTypeMockData.getInputLinkData(0);
|
||||||
mockDocumentService.Setup(service => service.PostLinkTypeAsync(mockInputDocument)).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.PostLinkTypeAsync(mockInputDocument)).ReturnsAsync(mockResponse);
|
||||||
@ -295,7 +273,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task PostDocumentcategoryAsync_ShouldReturnStatusCode400()
|
public async Task PostDocumentcategoryAsync_ShouldReturnStatusCode400()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockInputDocument = await LinkTypeMockData.getInputLinkData(99);
|
var mockInputDocument = await LinkTypeMockData.getInputLinkData(99);
|
||||||
var mockResponse = await LinkTypeMockData.getBadRequestResponse();
|
var mockResponse = await LinkTypeMockData.getBadRequestResponse();
|
||||||
mockDocumentService.Setup(service => service.PostLinkTypeAsync(mockInputDocument)).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.PostLinkTypeAsync(mockInputDocument)).ReturnsAsync(mockResponse);
|
||||||
@ -309,7 +287,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task PutDocumentcategoryAsync_ShouldReturnStatusCode200()
|
public async Task PutDocumentcategoryAsync_ShouldReturnStatusCode200()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await LinkTypeMockData.getOkResponse(1);
|
var mockResponse = await LinkTypeMockData.getOkResponse(1);
|
||||||
var mockInputDocument = await LinkTypeMockData.getInputLinkData(1);
|
var mockInputDocument = await LinkTypeMockData.getInputLinkData(1);
|
||||||
mockDocumentService.Setup(service => service.UpdateLinkTypeAsync(1, mockInputDocument)).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.UpdateLinkTypeAsync(1, mockInputDocument)).ReturnsAsync(mockResponse);
|
||||||
@ -323,7 +301,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task PutDocumentcategoryAsync_ShouldReturnStatusCode404()
|
public async Task PutDocumentcategoryAsync_ShouldReturnStatusCode404()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await LinkTypeMockData.getNotFoundResponse();
|
var mockResponse = await LinkTypeMockData.getNotFoundResponse();
|
||||||
var mockInputDocument = await LinkTypeMockData.getInputLinkData(99);
|
var mockInputDocument = await LinkTypeMockData.getInputLinkData(99);
|
||||||
mockDocumentService.Setup(service => service.UpdateLinkTypeAsync(99, mockInputDocument)).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.UpdateLinkTypeAsync(99, mockInputDocument)).ReturnsAsync(mockResponse);
|
||||||
@ -337,7 +315,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task PutDocumentcategoryAsync_ShouldReturnStatusCode400()
|
public async Task PutDocumentcategoryAsync_ShouldReturnStatusCode400()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await LinkTypeMockData.getBadRequestResponse();
|
var mockResponse = await LinkTypeMockData.getBadRequestResponse();
|
||||||
var mockInputDocument = await LinkTypeMockData.getInputLinkData(1);
|
var mockInputDocument = await LinkTypeMockData.getInputLinkData(1);
|
||||||
mockDocumentService.Setup(service => service.UpdateLinkTypeAsync(1, mockInputDocument)).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.UpdateLinkTypeAsync(1, mockInputDocument)).ReturnsAsync(mockResponse);
|
||||||
@ -351,7 +329,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task DeleteDocumentcategoryAsync_ShouldReturnStatusCode200()
|
public async Task DeleteDocumentcategoryAsync_ShouldReturnStatusCode200()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await LinkTypeMockData.getOkResponse(1);
|
var mockResponse = await LinkTypeMockData.getOkResponse(1);
|
||||||
|
|
||||||
mockDocumentService.Setup(service => service.DeleteLinkTypeAsync(1)).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.DeleteLinkTypeAsync(1)).ReturnsAsync(mockResponse);
|
||||||
@ -364,7 +342,7 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
public async Task DeleteDocumentcategoryAsync_ShouldReturnStatusCode404()
|
public async Task DeleteDocumentcategoryAsync_ShouldReturnStatusCode404()
|
||||||
{
|
{
|
||||||
var mockDocumentService = new Mock<IDoculinkProvider>();
|
var mockDocumentService = new Mock<IDoculinkProvider>();
|
||||||
var mockUploadService = new Mock<IUploadService>();
|
var mockUploadService = new Mock<IAzureBlobService>();
|
||||||
var mockResponse = await LinkTypeMockData.getNotFoundResponse();
|
var mockResponse = await LinkTypeMockData.getNotFoundResponse();
|
||||||
mockDocumentService.Setup(service => service.DeleteLinkTypeAsync(1)).ReturnsAsync(mockResponse);
|
mockDocumentService.Setup(service => service.DeleteLinkTypeAsync(1)).ReturnsAsync(mockResponse);
|
||||||
|
|
||||||
|
@ -31,9 +31,11 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
List<DoculinkAttachments> doclinksAttachments = new List<DoculinkAttachments>();
|
List<DoculinkAttachments> doclinksAttachments = new List<DoculinkAttachments>();
|
||||||
doclinksAttachments.Add(new DoculinkAttachments()
|
doclinksAttachments.Add(new DoculinkAttachments()
|
||||||
{
|
{
|
||||||
docName = "",Path="www.google.com",
|
docName = "",
|
||||||
|
Path = "www.google.com",
|
||||||
|
IsAttachments = false,
|
||||||
Language = "en",
|
Language = "en",
|
||||||
IsAttachments =false,CustomOrder=1
|
CustomOrder = 1
|
||||||
});
|
});
|
||||||
list.Add(new DocuLinks.Models.ResDoculink()
|
list.Add(new DocuLinks.Models.ResDoculink()
|
||||||
{
|
{
|
||||||
@ -75,7 +77,6 @@ namespace DamageAssesment.Api.DocuLinks.Test
|
|||||||
docName = "",
|
docName = "",
|
||||||
Path = "www.google.com",
|
Path = "www.google.com",
|
||||||
IsAttachments = false,
|
IsAttachments = false,
|
||||||
Language = "en",
|
|
||||||
CustomOrder = 1
|
CustomOrder = 1
|
||||||
});
|
});
|
||||||
list.Add(new DocuLinks.Models.ResDoculink()
|
list.Add(new DocuLinks.Models.ResDoculink()
|
||||||
|
@ -15,11 +15,11 @@ namespace DamageAssesment.Api.DocuLinks.Controllers
|
|||||||
private readonly IUploadService uploadService;
|
private readonly IUploadService uploadService;
|
||||||
private readonly IAzureBlobService azureBlobService;
|
private readonly IAzureBlobService azureBlobService;
|
||||||
|
|
||||||
public DoculinkController(IDoculinkProvider documentsProvider, IUploadService uploadService)
|
public DoculinkController(IDoculinkProvider documentsProvider, IAzureBlobService azureBlobService)
|
||||||
{
|
{
|
||||||
|
|
||||||
this.documentsProvider = documentsProvider;
|
this.documentsProvider = documentsProvider;
|
||||||
this.uploadService = uploadService;
|
this.azureBlobService = azureBlobService;
|
||||||
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -111,82 +111,7 @@ namespace DamageAssesment.Api.DocuLinks.Controllers
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// download an existing attachment.
|
/// Get all documents.
|
||||||
/// </summary>
|
|
||||||
[Authorize(Roles = "admin")]
|
|
||||||
[HttpGet("doculinks/download/{id}")]
|
|
||||||
public async Task<IActionResult> downloadfile(int id)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var result = await this.documentsProvider.GetDownloadAttachmentAsync(id);
|
|
||||||
if (!result.IsSuccess)
|
|
||||||
return NotFound();
|
|
||||||
string path = await uploadService.GetFile(result.DoculinkAttachments.Path);
|
|
||||||
if (path == null)
|
|
||||||
return NotFound();
|
|
||||||
var contentType = GetContentType(result.DoculinkAttachments.docName);
|
|
||||||
if (contentType == "application/octet-stream")
|
|
||||||
return PhysicalFile(path, contentType, result.DoculinkAttachments.docName);
|
|
||||||
return PhysicalFile(path, contentType, enableRangeProcessing: true);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
// Handle the exception here or log it
|
|
||||||
return StatusCode(500, "An error occurred: " + ex.Message);
|
|
||||||
}
|
|
||||||
//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);
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
private string GetContentType(string fileName)
|
|
||||||
{
|
|
||||||
// You can add more content types based on the file extensions
|
|
||||||
switch (Path.GetExtension(fileName).ToLower())
|
|
||||||
{
|
|
||||||
//case ".txt":
|
|
||||||
// return "text/plain";
|
|
||||||
case ".jpg":
|
|
||||||
case ".jpeg":
|
|
||||||
return "image/jpeg";
|
|
||||||
case ".png":
|
|
||||||
return "image/png";
|
|
||||||
case ".gif":
|
|
||||||
return "image/gif";
|
|
||||||
case ".bmp":
|
|
||||||
return "image/bmp";
|
|
||||||
case ".webp":
|
|
||||||
return "image/webp";
|
|
||||||
case ".csv":
|
|
||||||
return "text/csv";
|
|
||||||
case ".pdf":
|
|
||||||
return "application/pdf";
|
|
||||||
case ".docx":
|
|
||||||
case ".doc":
|
|
||||||
return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
||||||
case ".xlsx":
|
|
||||||
case ".xls":
|
|
||||||
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
||||||
// Add more cases as needed
|
|
||||||
default:
|
|
||||||
return "application/octet-stream";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Get all Doculink.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
||||||
[Authorize(Roles = "admin")]
|
[Authorize(Roles = "admin")]
|
||||||
@ -265,7 +190,7 @@ namespace DamageAssesment.Api.DocuLinks.Controllers
|
|||||||
if (dbdoc.IsSuccess)
|
if (dbdoc.IsSuccess)
|
||||||
{
|
{
|
||||||
var documents = await this.documentsProvider.GetDocumentCounter();
|
var documents = await this.documentsProvider.GetDocumentCounter();
|
||||||
Models.Doculink DocuLink= uploadService.UpdateDocuments(documents.counter,dbdoc.Document, documentInfo);
|
Models.Doculink DocuLink= await azureBlobService.UpdateDocuments(documents.counter,dbdoc.Document, documentInfo);
|
||||||
var result = await this.documentsProvider.UpdateDocumentAsync(id, DocuLink);
|
var result = await this.documentsProvider.UpdateDocumentAsync(id, DocuLink);
|
||||||
if (result.IsSuccess)
|
if (result.IsSuccess)
|
||||||
{
|
{
|
||||||
@ -278,20 +203,6 @@ namespace DamageAssesment.Api.DocuLinks.Controllers
|
|||||||
return BadRequest(documentInfo);
|
return BadRequest(documentInfo);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// update existing doclink isactive field.
|
|
||||||
/// </summary>
|
|
||||||
[HttpPut]
|
|
||||||
[Route("doculinks/{id}/{isactive}")]
|
|
||||||
public async Task<IActionResult> UpdateIsActiveDocument(int id, bool isactive)
|
|
||||||
{
|
|
||||||
var result = await this.documentsProvider.UpdateDocumentAsync(id, isactive);
|
|
||||||
if (result.IsSuccess)
|
|
||||||
{
|
|
||||||
return Ok(result.Document);
|
|
||||||
}
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Create new doclink.
|
/// Create new doclink.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
// [Authorize(Roles = "admin")]
|
// [Authorize(Roles = "admin")]
|
||||||
@ -303,8 +214,8 @@ namespace DamageAssesment.Api.DocuLinks.Controllers
|
|||||||
{
|
{
|
||||||
if (documentInfo != null)
|
if (documentInfo != null)
|
||||||
{
|
{
|
||||||
var documents = await this.documentsProvider.GetDocumentCounter();
|
//var documents = await this.documentsProvider.GetDocumentCounter();
|
||||||
Models.Doculink DocuLink = uploadService.UploadDocument(documents.counter, documentInfo);
|
Models.Doculink DocuLink= await azureBlobService.UploadDocument(1, documentInfo);
|
||||||
var result = await this.documentsProvider.PostDocumentAsync(DocuLink);
|
var result = await this.documentsProvider.PostDocumentAsync(DocuLink);
|
||||||
if (result.IsSuccess)
|
if (result.IsSuccess)
|
||||||
{
|
{
|
||||||
@ -334,7 +245,7 @@ namespace DamageAssesment.Api.DocuLinks.Controllers
|
|||||||
// deleting file from folder
|
// deleting file from folder
|
||||||
foreach (var item in result.Document.doclinksAttachments)
|
foreach (var item in result.Document.doclinksAttachments)
|
||||||
{
|
{
|
||||||
uploadService.Movefile(item.Path);
|
azureBlobService.Movefile(item.Path);
|
||||||
}
|
}
|
||||||
return Ok(result.Document);
|
return Ok(result.Document);
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,7 @@ namespace DamageAssesment.Api.DocuLinks.Interfaces
|
|||||||
Task<(bool IsSuccess, IEnumerable<Models.ResDoculink> documents, string ErrorMessage)> GetdocumentsByLinkTypeIdAsync(int? linkTypeId, string? language, bool? isactive);
|
Task<(bool IsSuccess, IEnumerable<Models.ResDoculink> 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)> 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)> UpdateDocumentAsync(int id, bool isactive);
|
|
||||||
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();
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,8 +7,6 @@ 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);
|
|
||||||
Task<string> GetFile(string path);
|
|
||||||
void Movefile(string path);
|
void Movefile(string path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ namespace DamageAssesment.Api.DocuLinks.Models
|
|||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public int linkTypeId { get; set; }
|
public int linkTypeId { get; set; }
|
||||||
public List<DoculinkTranslation> documentsTranslations { get; set; }
|
public List<DoculinkTranslation> documentsTranslations { get; set; }
|
||||||
public bool IsActive { get; set; }
|
|
||||||
public int CustomOrder { get; set; }
|
public int CustomOrder { get; set; }
|
||||||
public List<FileModel>? Files { get; set; }
|
public List<FileModel>? Files { get; set; }
|
||||||
}
|
}
|
||||||
@ -18,7 +17,7 @@ namespace DamageAssesment.Api.DocuLinks.Models
|
|||||||
public string? FileExtension { get; set; }
|
public string? FileExtension { get; set; }
|
||||||
public int CustomOrder { get; set; }
|
public int CustomOrder { get; set; }
|
||||||
public string url { get;set; }
|
public string url { get;set; }
|
||||||
public bool IsAttachments { get; set; }
|
|
||||||
public string Language { get; set; }
|
public string Language { get; set; }
|
||||||
|
public bool IsAttachments { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,6 @@ 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>();
|
||||||
|
@ -55,7 +55,7 @@ namespace DamageAssesment.Api.DocuLinks.Providers
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
path = item.url;
|
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()
|
Documents = new Models.Doculink()
|
||||||
@ -104,7 +104,7 @@ namespace DamageAssesment.Api.DocuLinks.Providers
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
path = item.url;
|
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()
|
Models.Doculink Documents = new Models.Doculink()
|
||||||
{
|
{
|
||||||
|
@ -2,17 +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.Diagnostics.Eventing.Reader;
|
using System.Diagnostics.Eventing.Reader;
|
||||||
using System.Reflection.Metadata;
|
using System.Reflection.Metadata;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Xml;
|
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace DamageAssesment.Api.DocuLinks.Providers
|
namespace DamageAssesment.Api.DocuLinks.Providers
|
||||||
@ -26,18 +21,13 @@ 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, IHttpContextAccessor httpContextAccessor)
|
public DoculinkProvider(DoculinkDbContext DocumentDbContext, ILogger<DoculinkProvider> logger, IMapper mapper, IUploadService uploadservice, IAzureBlobService azureBlobService)
|
||||||
{
|
{
|
||||||
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();
|
||||||
}
|
}
|
||||||
@ -75,20 +65,13 @@ namespace DamageAssesment.Api.DocuLinks.Providers
|
|||||||
int counter = 0;
|
int counter = 0;
|
||||||
for (int i = 1; i <= 4; i++)
|
for (int i = 1; i <= 4; i++)
|
||||||
{
|
{
|
||||||
int linkTypeId = 2;
|
FileModel fileModel = new FileModel() { url = "www.google" + i + ".com", IsAttachments = false, CustomOrder = 1 };
|
||||||
FileModel fileModel = new FileModel();
|
|
||||||
if (i < 3)
|
|
||||||
{
|
|
||||||
linkTypeId = 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,Language="en" };
|
|
||||||
ReqDoculink documentInfo = new ReqDoculink() { linkTypeId = i, CustomOrder = i, Files = new List<FileModel>() { fileModel } };
|
ReqDoculink documentInfo = new ReqDoculink() { linkTypeId = i, CustomOrder = i, Files = new List<FileModel>() { fileModel } };
|
||||||
Models.Doculink document = uploadservice.UploadDocument(counter, documentInfo);
|
Db.DoculinkTranslation documents = new Db.DoculinkTranslation { DocumentId = i, title = "Test" + i, description = "ss" + i, Language = "en" };
|
||||||
|
Models.Doculink document = await azureBlobService.UploadDocument(counter, documentInfo);
|
||||||
DocumentDbContext.Documents.Add(mapper.Map<Models.Doculink, Db.Doculink>(document));
|
DocumentDbContext.Documents.Add(mapper.Map<Models.Doculink, Db.Doculink>(document));
|
||||||
DocumentDbContext.SaveChanges();
|
DocumentDbContext.SaveChanges();
|
||||||
|
DocumentDbContext.DocumentsTranslations.AddRange(documents);
|
||||||
var dbattachments = mapper.Map<List<Models.DoculinkAttachments>, List<Db.DoculinkAttachments>>(document.doclinksAttachments);
|
var dbattachments = mapper.Map<List<Models.DoculinkAttachments>, List<Db.DoculinkAttachments>>(document.doclinksAttachments);
|
||||||
dbattachments.ForEach(a => a.DocumentId = i);
|
dbattachments.ForEach(a => a.DocumentId = i);
|
||||||
DocumentDbContext.DoclinksAttachments.AddRange(dbattachments);
|
DocumentDbContext.DoclinksAttachments.AddRange(dbattachments);
|
||||||
@ -96,34 +79,6 @@ namespace DamageAssesment.Api.DocuLinks.Providers
|
|||||||
counter++;
|
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<Db.DoculinkTranslation> documents = new List<Db.DoculinkTranslation>();
|
|
||||||
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<Models.DoculinkTranslation> GetDocumentTranslations(int id, string? language)
|
public List<Models.DoculinkTranslation> GetDocumentTranslations(int id, string? language)
|
||||||
{
|
{
|
||||||
@ -182,38 +137,15 @@ 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))
|
||||||
{
|
{
|
||||||
doculinkAttachments = DocumentDbContext.DoclinksAttachments.AsNoTracking().Where(a => a.DocumentId == id).ToList();
|
return mapper.Map<List<Db.DoculinkAttachments>, List<Models.DoculinkAttachments>>(
|
||||||
|
DocumentDbContext.DoclinksAttachments.AsNoTracking().Where(a => a.DocumentId == id).ToList());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
doculinkAttachments = DocumentDbContext.DoclinksAttachments.AsNoTracking().Where(a => a.DocumentId == id && a.Language == language).ToList();
|
return mapper.Map<List<Db.DoculinkAttachments>, List<Models.DoculinkAttachments>>(
|
||||||
}
|
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)
|
||||||
@ -274,7 +206,6 @@ namespace DamageAssesment.Api.DocuLinks.Providers
|
|||||||
item.linktypes = CreateMultiLanguageLinkTypeObject(GetLinkTypeTranslations(item.linkTypeId, language));
|
item.linktypes = CreateMultiLanguageLinkTypeObject(GetLinkTypeTranslations(item.linkTypeId, language));
|
||||||
item.doclinksAttachments = GetDocumentAttachment(item.Id, language);
|
item.doclinksAttachments = GetDocumentAttachment(item.Id, language);
|
||||||
}
|
}
|
||||||
//List<ResDoculinks> doculinks = result.GroupBy(a => a.linkTypeId).Select(a => new ResDoculinks() { linkTypeId = a.Key, doculinks = a.ToList() }).ToList();
|
|
||||||
return (true, result, null);
|
return (true, result, null);
|
||||||
}
|
}
|
||||||
return (false, null, "Not found");
|
return (false, null, "Not found");
|
||||||
@ -390,7 +321,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 = GetDocumentAttachment(document.Id,"");
|
result.doclinksAttachments = Document.doclinksAttachments;
|
||||||
return (true, result, null);
|
return (true, result, null);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -432,7 +363,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 = GetDocumentAttachment(document.Id, "");
|
result.doclinksAttachments = Document.doclinksAttachments;
|
||||||
return (true, result, "Successful");
|
return (true, result, "Successful");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -455,35 +386,6 @@ namespace DamageAssesment.Api.DocuLinks.Providers
|
|||||||
return (false, null, ex.Message);
|
return (false, null, ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public async Task<(bool IsSuccess, Models.ResDoculink Document, string ErrorMessage)> UpdateDocumentAsync(int id,bool isactive)
|
|
||||||
{
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Db.Doculink Document = DocumentDbContext.Documents.AsNoTracking().Where(a => a.Id == id).FirstOrDefault();
|
|
||||||
if (Document == null)
|
|
||||||
{
|
|
||||||
return (false, null, "Not Found");
|
|
||||||
}
|
|
||||||
Document.IsActive = isactive;
|
|
||||||
DocumentDbContext.Documents.Update(Document);
|
|
||||||
DocumentDbContext.SaveChanges();
|
|
||||||
var result = mapper.Map<Db.Doculink, Models.ResDoculink>(Document);
|
|
||||||
var multilan = CreateMultiLanguageObject(GetDocumentTranslations(Document.Id, ""));
|
|
||||||
result.titles = multilan.titles;
|
|
||||||
result.description = multilan.description;
|
|
||||||
result.linktypes = CreateMultiLanguageLinkTypeObject(GetLinkTypeTranslations(result.linkTypeId, ""));
|
|
||||||
result.doclinksAttachments = mapper.Map<List<Db.DoculinkAttachments>, List<Models.DoculinkAttachments>>(
|
|
||||||
DocumentDbContext.DoclinksAttachments.AsNoTracking().Where(a => a.DocumentId == id).ToList());
|
|
||||||
return (true, result, $"DocumentId {id} deleted Successfuly");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
|
|
||||||
logger?.LogError(ex.ToString());
|
|
||||||
return (false, null, ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public async Task<(bool IsSuccess, Models.ResDoculink Document, string ErrorMessage)> DeleteDocumentAsync(int id)
|
public async Task<(bool IsSuccess, Models.ResDoculink Document, string ErrorMessage)> DeleteDocumentAsync(int id)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -499,8 +401,7 @@ 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 = mapper.Map<List<Db.DoculinkAttachments>, List<Models.DoculinkAttachments>>(
|
result.doclinksAttachments = GetDocumentAttachment(id, "");
|
||||||
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();
|
||||||
@ -518,7 +419,7 @@ namespace DamageAssesment.Api.DocuLinks.Providers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int AttachmentId = DocumentDbContext.DoclinksAttachments.Max(a => a.Id);
|
int AttachmentId = DocumentDbContext.Documents.Max(a => a.Id);
|
||||||
return (true, AttachmentId, "");
|
return (true, AttachmentId, "");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -25,41 +25,6 @@ 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<string> GetFile(string path)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (System.IO.File.Exists(path))
|
|
||||||
{
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null; // File not found
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
// Handle or log the exception as needed
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
@ -79,7 +44,7 @@ namespace DamageAssesment.Api.DocuLinks.Providers
|
|||||||
counter++;
|
counter++;
|
||||||
if (item.IsAttachments)
|
if (item.IsAttachments)
|
||||||
{
|
{
|
||||||
UserfileName = Path.GetFileName(item.FileName + item.FileExtension);
|
UserfileName = Path.GetFileName(item.FileName);
|
||||||
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));
|
||||||
@ -89,14 +54,20 @@ namespace DamageAssesment.Api.DocuLinks.Providers
|
|||||||
attachments.Add(new Models.DoculinkAttachments { docName = UserfileName, Path = path, IsAttachments = item.IsAttachments, CustomOrder = item.CustomOrder, Language = item.Language });
|
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,
|
Documents = new Models.Doculink()
|
||||||
documentsTranslations = documentInfo.documentsTranslations,doclinksAttachments=attachments,
|
{
|
||||||
IsDeleted=false,CustomOrder=documentInfo.CustomOrder, IsActive =documentInfo.IsActive
|
linkTypeId = documentInfo.linkTypeId,
|
||||||
|
documentsTranslations = documentInfo.documentsTranslations,
|
||||||
|
doclinksAttachments = attachments,
|
||||||
|
IsDeleted = false,
|
||||||
|
CustomOrder = documentInfo.CustomOrder,
|
||||||
|
IsActive = true
|
||||||
};
|
};
|
||||||
|
|
||||||
return Documents;
|
return Documents;
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex)
|
||||||
|
{
|
||||||
return new Models.Doculink();
|
return new Models.Doculink();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +92,7 @@ namespace DamageAssesment.Api.DocuLinks.Providers
|
|||||||
{
|
{
|
||||||
if (item.IsAttachments)
|
if (item.IsAttachments)
|
||||||
{
|
{
|
||||||
UserfileName = Path.GetFileName(item.FileName+item.FileExtension);
|
UserfileName = Path.GetFileName(item.FileName);
|
||||||
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));
|
||||||
@ -136,7 +107,7 @@ namespace DamageAssesment.Api.DocuLinks.Providers
|
|||||||
Id = documentInfo.Id,
|
Id = documentInfo.Id,
|
||||||
linkTypeId = documentInfo.linkTypeId,
|
linkTypeId = documentInfo.linkTypeId,
|
||||||
documentsTranslations = documentInfo.documentsTranslations,
|
documentsTranslations = documentInfo.documentsTranslations,
|
||||||
IsActive = documentInfo.IsActive,
|
IsActive = true,
|
||||||
IsDeleted = false,
|
IsDeleted = false,
|
||||||
CustomOrder = documentInfo.CustomOrder,
|
CustomOrder = documentInfo.CustomOrder,
|
||||||
doclinksAttachments = attachments
|
doclinksAttachments = attachments
|
||||||
@ -145,7 +116,8 @@ namespace DamageAssesment.Api.DocuLinks.Providers
|
|||||||
return Documents;
|
return Documents;
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (Exception ex) {
|
catch (Exception ex)
|
||||||
|
{
|
||||||
return new Models.Doculink();
|
return new Models.Doculink();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
//"DoculinkConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
//"DoculinkConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
||||||
"DoculinkConnection": "Server=207.180.248.35;Database=da_survey_dev;User Id=sa;Password=YourStrongPassw0rd;TrustServerCertificate=True;"
|
"DoculinkConnection": "Server=tcp:da-dev.database.windows.net,1433;Initial Catalog=da-dev-db;Encrypt=True;User ID=admin-dev;Password=b3tgRABw8LGE75k;TrustServerCertificate=False;Connection Timeout=30;"
|
||||||
|
|
||||||
},
|
},
|
||||||
"Fileupload": {
|
"Fileupload": {
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
//"EmployeeConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
//"EmployeeConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
||||||
"EmployeeConnection": "Server=207.180.248.35;Database=da_survey_dev;User Id=sa;Password=YourStrongPassw0rd;TrustServerCertificate=True;"
|
"EmployeeConnection": "Server=tcp:da-dev.database.windows.net,1433;Initial Catalog=da-dev-db;Encrypt=True;User ID=admin-dev;Password=b3tgRABw8LGE75k;TrustServerCertificate=False;Connection Timeout=30;"
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
|
//"ConnectionStrings": {
|
||||||
|
// "LocationConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
||||||
|
//},
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
//"LocationConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
//"LocationConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
||||||
"LocationConnection": "Server=207.180.248.35;Database=da_survey_dev;User Id=sa;Password=YourStrongPassw0rd;TrustServerCertificate=True;"
|
"LocationConnection": "Server=tcp:da-dev.database.windows.net,1433;Initial Catalog=da-dev-db;Encrypt=True;User ID=admin-dev;Password=b3tgRABw8LGE75k;TrustServerCertificate=False;Connection Timeout=30;"
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using DamageAssesment.Api.Questions.Interfaces;
|
using DamageAssesment.Api.Questions.Interfaces;
|
||||||
using DamageAssesment.Api.Questions.Models;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
@ -112,26 +111,6 @@ namespace DamageAssesment.Api.Questions.Controllers
|
|||||||
return CreatedAtRoute("DefaultApi", questions);
|
return CreatedAtRoute("DefaultApi", questions);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// PUT request for update a multiple question (multilingual) for survey.
|
|
||||||
/// </summary>
|
|
||||||
[HttpPut("questions/multiple/{surveyid}")]
|
|
||||||
public async Task<IActionResult> CreateQuestions(int surveyid, List<Models.Question> questions)
|
|
||||||
{
|
|
||||||
if (questions != null)
|
|
||||||
{
|
|
||||||
var result = await this.questionsProvider.PutQuestionsAsync(surveyid,questions);
|
|
||||||
if (result.IsSuccess)
|
|
||||||
{
|
|
||||||
return Ok(result.Question);
|
|
||||||
}
|
|
||||||
if (result.ErrorMessage == "Not Found")
|
|
||||||
return NotFound(result.ErrorMessage);
|
|
||||||
|
|
||||||
return BadRequest(result.ErrorMessage);
|
|
||||||
}
|
|
||||||
return CreatedAtRoute("DefaultApi", questions);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// POST request for creating a new question (multilingual).
|
/// POST request for creating a new question (multilingual).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ namespace DamageAssesment.Api.Questions.Interfaces
|
|||||||
Task<(bool IsSuccess, List<SurveyQuestions> SurveyQuestions, string ErrorMessage)> GetSurveyQuestionAsync(int surveyId,string language);
|
Task<(bool IsSuccess, List<SurveyQuestions> SurveyQuestions, string ErrorMessage)> GetSurveyQuestionAsync(int surveyId,string language);
|
||||||
Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> PostQuestionAsync(Models.Question Question);
|
Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> PostQuestionAsync(Models.Question Question);
|
||||||
Task<(bool IsSuccess, IEnumerable<Models.MultiLanguage> Question, string ErrorMessage)> PostQuestionsAsync(List<Models.Question> Questions);
|
Task<(bool IsSuccess, IEnumerable<Models.MultiLanguage> Question, string ErrorMessage)> PostQuestionsAsync(List<Models.Question> Questions);
|
||||||
Task<(bool IsSuccess, IEnumerable<Models.MultiLanguage> Question, string ErrorMessage)> PutQuestionsAsync(int surveyId,List<Models.Question> Questions);
|
|
||||||
Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> UpdateQuestionAsync(Models.Question Question);
|
Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> UpdateQuestionAsync(Models.Question Question);
|
||||||
Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> DeleteQuestionAsync(int id);
|
Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> DeleteQuestionAsync(int id);
|
||||||
|
|
||||||
|
@ -376,36 +376,6 @@ namespace DamageAssesment.Api.Questions.Providers
|
|||||||
return (false, null, ex.Message);
|
return (false, null, ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<(bool IsSuccess, IEnumerable<Models.MultiLanguage> Question, string ErrorMessage)> PutQuestionsAsync(int surveyId, List<Models.Question> Questions)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var questions=await questionDbContext.Questions.AsNoTracking().Where(a=>a.SurveyId == surveyId).ToListAsync();
|
|
||||||
if (questions != null)
|
|
||||||
{
|
|
||||||
List<int> questionids=questions.Select(a=>a.Id).ToList();
|
|
||||||
var questiontrans = await questionDbContext.QuestionsTranslations.AsNoTracking().Where(x => questionids.Contains(x.QuestionId)).ToListAsync();
|
|
||||||
if (questiontrans != null)
|
|
||||||
questionDbContext.QuestionsTranslations.RemoveRange(questiontrans);
|
|
||||||
questionDbContext.Questions.RemoveRange(questions);
|
|
||||||
questionDbContext.SaveChanges();
|
|
||||||
}
|
|
||||||
List<Models.MultiLanguage> results = new List<MultiLanguage>();
|
|
||||||
logger?.LogInformation("Query Question");
|
|
||||||
foreach (Models.Question Question in Questions)
|
|
||||||
{
|
|
||||||
Question.SurveyId = surveyId;
|
|
||||||
results.Add(InsertQuestion(Question));
|
|
||||||
}
|
|
||||||
return (true, results, null);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger?.LogError(ex.ToString());
|
|
||||||
return (false, null, ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public async Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> UpdateQuestionAsync(Models.Question Question)
|
public async Task<(bool IsSuccess, Models.MultiLanguage Question, string ErrorMessage)> UpdateQuestionAsync(Models.Question Question)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -439,11 +409,8 @@ namespace DamageAssesment.Api.Questions.Providers
|
|||||||
|
|
||||||
if (question != null)
|
if (question != null)
|
||||||
{
|
{
|
||||||
var questiontrans=await questionDbContext.QuestionsTranslations.AsNoTracking().Where(x=>x.QuestionId== id).ToListAsync();
|
|
||||||
var result = mapper.Map<Db.Question, Models.MultiLanguage>(question);
|
var result = mapper.Map<Db.Question, Models.MultiLanguage>(question);
|
||||||
result.Text = CreateMultiLanguageObject(GetQuestionsTranslations(result.Id, ""));
|
result.Text = CreateMultiLanguageObject(GetQuestionsTranslations(result.Id, ""));
|
||||||
if(questiontrans!=null)
|
|
||||||
questionDbContext.QuestionsTranslations.RemoveRange(questiontrans);
|
|
||||||
questionDbContext.Questions.Remove(question);
|
questionDbContext.Questions.Remove(question);
|
||||||
questionDbContext.SaveChanges();
|
questionDbContext.SaveChanges();
|
||||||
return (true, result, $"QuestionID {id} deleted Successfuly");
|
return (true, result, $"QuestionID {id} deleted Successfuly");
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
//"QuestionConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
//"QuestionConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
||||||
"QuestionConnection": "Server=207.180.248.35;Database=da_survey_dev;User Id=sa;Password=YourStrongPassw0rd;TrustServerCertificate=True;"
|
"QuestionConnection": "Server=tcp:da-dev.database.windows.net,1433;Initial Catalog=da-dev-db;Encrypt=True;User ID=admin-dev;Password=b3tgRABw8LGE75k;TrustServerCertificate=False;Connection Timeout=30;"
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,20 +71,16 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
logger?.LogInformation("Querying to get SurveyResponse object from DB");
|
logger?.LogInformation("Querying to get SurveyResponse object from DB");
|
||||||
List<Db.SurveyResponse> listSurveyResponse = null;
|
IQueryable<Db.SurveyResponse> listSurveyResponse = null;
|
||||||
if (employeeid == 0)
|
if (employeeid == 0)
|
||||||
{
|
{
|
||||||
listSurveyResponse = surveyResponseDbContext.SurveyResponses.Where(s => s.SurveyId == surveyId).ToList();
|
listSurveyResponse = surveyResponseDbContext.SurveyResponses.Where(s => s.SurveyId == surveyId);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
listSurveyResponse = surveyResponseDbContext.SurveyResponses.Where(s => s.SurveyId == surveyId && s.EmployeeId == employeeid).ToList();
|
listSurveyResponse = surveyResponseDbContext.SurveyResponses.Where(s => s.SurveyId == surveyId && s.EmployeeId == employeeid);
|
||||||
}
|
}
|
||||||
listSurveyResponse = listSurveyResponse
|
|
||||||
.OrderByDescending(obj => obj.Id)
|
|
||||||
.GroupBy(obj => new { obj.SurveyId, obj.LocationId })//obj.EmployeeId,
|
|
||||||
.Select(group => group.FirstOrDefault()) // or .FirstOrDefault() if you want to handle empty groups
|
|
||||||
.ToList();
|
|
||||||
if (listSurveyResponse.Any())
|
if (listSurveyResponse.Any())
|
||||||
{
|
{
|
||||||
var answers = await getAnswersByRegionAndSurveyIdAsync(listSurveyResponse);
|
var answers = await getAnswersByRegionAndSurveyIdAsync(listSurveyResponse);
|
||||||
@ -436,7 +432,7 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Method to get Answers by region with surveyId as input parameter
|
//Method to get Answers by region with surveyId as input parameter
|
||||||
private async Task<dynamic> getAnswersByRegionAndSurveyIdAsync(List<Db.SurveyResponse> surveyResponses)
|
private async Task<dynamic> getAnswersByRegionAndSurveyIdAsync(IQueryable<Db.SurveyResponse> surveyResponses)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -582,11 +578,6 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
surveyResonses = await surveyResponseDbContext.SurveyResponses.Where(x => x.SurveyId == surveyId && x.EmployeeId == employeeid).ToListAsync();
|
surveyResonses = await surveyResponseDbContext.SurveyResponses.Where(x => x.SurveyId == surveyId && x.EmployeeId == employeeid).ToListAsync();
|
||||||
employee = await employeeServiceProvider.getEmployeeAsync(employeeid, token);
|
employee = await employeeServiceProvider.getEmployeeAsync(employeeid, token);
|
||||||
}
|
}
|
||||||
surveyResonses = surveyResonses
|
|
||||||
.OrderByDescending(obj => obj.Id)
|
|
||||||
.GroupBy(obj => new { obj.SurveyId, obj.LocationId })//obj.EmployeeId,
|
|
||||||
.Select(group => group.FirstOrDefault()) // or .FirstOrDefault() if you want to handle empty groups
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
var answers = await answerServiceProvider.getAnswersAsync(token);
|
var answers = await answerServiceProvider.getAnswersAsync(token);
|
||||||
var questions = await questionServiceProvider.getQuestionsAsync(null, token);
|
var questions = await questionServiceProvider.getQuestionsAsync(null, token);
|
||||||
@ -916,11 +907,7 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
_employee = new { employee.Id, employee.Name, employee.BirthDate, employee.Email, employee.OfficePhoneNumber };
|
_employee = new { employee.Id, employee.Name, employee.BirthDate, employee.Email, employee.OfficePhoneNumber };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
surveyResonses = surveyResonses
|
|
||||||
.OrderByDescending(obj => obj.Id)
|
|
||||||
.GroupBy(obj => new { obj.SurveyId, obj.LocationId }) //obj.EmployeeId,
|
|
||||||
.Select(group => group.FirstOrDefault()) // or .FirstOrDefault() if you want to handle empty groups
|
|
||||||
.ToList();
|
|
||||||
var answers = await answerServiceProvider.getAnswersAsync(token);
|
var answers = await answerServiceProvider.getAnswersAsync(token);
|
||||||
var questions = await questionServiceProvider.getQuestionsAsync(null, token);
|
var questions = await questionServiceProvider.getQuestionsAsync(null, token);
|
||||||
var surveyQuestions = from q in questions where q.SurveyId == surveyId select q;
|
var surveyQuestions = from q in questions where q.SurveyId == surveyId select q;
|
||||||
@ -986,11 +973,7 @@ namespace DamageAssesment.Api.Responses.Providers
|
|||||||
_employee = new { employee.Id, employee.Name, employee.BirthDate, employee.Email, employee.OfficePhoneNumber };
|
_employee = new { employee.Id, employee.Name, employee.BirthDate, employee.Email, employee.OfficePhoneNumber };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
surveyResponses = surveyResponses
|
|
||||||
.OrderByDescending(obj => obj.Id)
|
|
||||||
.GroupBy(obj => new { obj.SurveyId, obj.LocationId })//, obj.EmployeeId
|
|
||||||
.Select(group => group.FirstOrDefault()) // or .FirstOrDefault() if you want to handle empty groups
|
|
||||||
.ToList();
|
|
||||||
//var surveyResponses = await surveyResponseDbContext.Responses.Where(x => x.SurveyId == survey.Id).ToListAsync();
|
//var surveyResponses = await surveyResponseDbContext.Responses.Where(x => x.SurveyId == survey.Id).ToListAsync();
|
||||||
// var employees = await employeeServiceProvider.getEmployeesAsync();
|
// var employees = await employeeServiceProvider.getEmployeesAsync();
|
||||||
var answers = await answerServiceProvider.getAnswersAsync(token);
|
var answers = await answerServiceProvider.getAnswersAsync(token);
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
},
|
},
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
//"ResponsesConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
//"ResponsesConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
||||||
"ResponsesConnection": "Server=207.180.248.35;Database=da_survey_dev;User Id=sa;Password=YourStrongPassw0rd;TrustServerCertificate=True;"
|
"ResponsesConnection": "Server=tcp:da-dev.database.windows.net,1433;Initial Catalog=da-dev-db;Encrypt=True;User ID=admin-dev;Password=b3tgRABw8LGE75k;TrustServerCertificate=False;Connection Timeout=30;"
|
||||||
|
|
||||||
},
|
},
|
||||||
//"EndPointSettings": {
|
//"EndPointSettings": {
|
||||||
// "AnswerUrlBase": "http://localhost:5200",
|
// "AnswerUrlBase": "http://localhost:5200",
|
||||||
|
@ -178,11 +178,6 @@ namespace DamageAssesment.Api.Surveys.Providers
|
|||||||
{
|
{
|
||||||
if (survey != null)
|
if (survey != null)
|
||||||
{
|
{
|
||||||
if (survey.StartDate != null && survey.EndDate != null)
|
|
||||||
{
|
|
||||||
if(survey.StartDate.Value>survey.EndDate.Value)
|
|
||||||
return (false, null, $"Survey start date should be less than enddate");
|
|
||||||
}
|
|
||||||
survey.CreatedDate = DateTime.Now;
|
survey.CreatedDate = DateTime.Now;
|
||||||
Db.Survey _survey = mapper.Map<Models.Survey, Db.Survey>(survey);
|
Db.Survey _survey = mapper.Map<Models.Survey, Db.Survey>(survey);
|
||||||
|
|
||||||
@ -219,11 +214,6 @@ namespace DamageAssesment.Api.Surveys.Providers
|
|||||||
{
|
{
|
||||||
if (survey != null)
|
if (survey != null)
|
||||||
{
|
{
|
||||||
if (survey.StartDate != null && survey.EndDate != null)
|
|
||||||
{
|
|
||||||
if (survey.StartDate.Value > survey.EndDate.Value)
|
|
||||||
return (false, null, $"Survey start date should be less than enddate");
|
|
||||||
}
|
|
||||||
var _survey = await surveyDbContext.Surveys.AsNoTracking().Where(s => s.Id == Id).SingleOrDefaultAsync();
|
var _survey = await surveyDbContext.Surveys.AsNoTracking().Where(s => s.Id == Id).SingleOrDefaultAsync();
|
||||||
|
|
||||||
if (_survey != null)
|
if (_survey != null)
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
//"SurveyConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
//"SurveyConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
||||||
"SurveyConnection": "Server=207.180.248.35;Database=da_survey_dev;User Id=sa;Password=YourStrongPassw0rd;TrustServerCertificate=True;"
|
"SurveyConnection": "Server=tcp:da-dev.database.windows.net,1433;Initial Catalog=da-dev-db;Encrypt=True;User ID=admin-dev;Password=b3tgRABw8LGE75k;TrustServerCertificate=False;Connection Timeout=30;"
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,20 @@
|
|||||||
{
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||||
|
"iisSettings": {
|
||||||
|
"windowsAuthentication": false,
|
||||||
|
"anonymousAuthentication": true,
|
||||||
|
"iisExpress": {
|
||||||
|
"applicationUrl": "http://localhost:28382",
|
||||||
|
"sslPort": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
"profiles": {
|
"profiles": {
|
||||||
"DamageAssesment.Api.Users": {
|
"DamageAssesment.Api.Users": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"launchUrl": "swagger",
|
"launchUrl": "swagger",
|
||||||
|
"applicationUrl": "http://localhost:5027",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
},
|
},
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
],
|
],
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
//"UsersAccessConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
//"UsersAccessConnection": "Server=DESKTOP-OF5DPLQ\\SQLEXPRESS;Database=da_survey_dev;Trusted_Connection=True;TrustServerCertificate=True;"
|
||||||
"UsersAccessConnection": "Server=207.180.248.35;Database=da_survey_dev;User Id=sa;Password=YourStrongPassw0rd;TrustServerCertificate=True;"
|
"UsersAccessConnection": "Server=tcp:da-dev.database.windows.net,1433;Initial Catalog=da-dev-db;Encrypt=True;User ID=admin-dev;Password=b3tgRABw8LGE75k;TrustServerCertificate=False;Connection Timeout=30;"
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DamageAssesment.Api.Attachm
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4CB40DC2-D9D2-4384-A7A6-9968F5C777A2}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4CB40DC2-D9D2-4384-A7A6-9968F5C777A2}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
..\..\..\..\Sample\Migrations.ps1 = ..\..\..\..\Sample\Migrations.ps1
|
..\db\migrate-sqldb_v1.ps1 = ..\db\migrate-sqldb_v1.ps1
|
||||||
|
..\..\Sample\Migrations.ps1 = ..\..\Sample\Migrations.ps1
|
||||||
ReadMe.txt = ReadMe.txt
|
ReadMe.txt = ReadMe.txt
|
||||||
ReadMe4Dev.txt = ReadMe4Dev.txt
|
ReadMe4Dev.txt = ReadMe4Dev.txt
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
|
@ -10,7 +10,8 @@ $microservices = @(
|
|||||||
"DamageAssesment.Api.Locations",
|
"DamageAssesment.Api.Locations",
|
||||||
"DamageAssesment.Api.Questions",
|
"DamageAssesment.Api.Questions",
|
||||||
"DamageAssesment.Api.Responses",
|
"DamageAssesment.Api.Responses",
|
||||||
"DamageAssesment.Api.Surveys"
|
"DamageAssesment.Api.Surveys",
|
||||||
|
"DamageAssesment.Api.UsersAccess"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user