Update to Async Attachement, Answer and Update Multiple Answers submission - backlog #288

This commit is contained in:
Reginald Cherenfant Jasmin
2023-08-27 11:55:58 -04:00
parent 5a641ff3aa
commit 96ccb96bf1
50 changed files with 166 additions and 1087 deletions

View File

@ -83,15 +83,15 @@ namespace DamageAssesment.Api.Attachments.Controllers
/// </summary>
[HttpPost("Attachments"), DisableRequestSizeLimit]
public IActionResult UploadAttachmentAsync(AttachmentInfo attachmentInfo)
public async Task<IActionResult> UploadAttachmentAsync(AttachmentInfo attachmentInfo)
{
try
{
if (attachmentInfo.Answers.Count > 0)
{
var Attachments = this.AttachmentProvider.GetAttachmentCounter();
var Attachments = await this.AttachmentProvider.GetAttachmentCounter();
List<Models.Attachment> attachments = UploadService.UploadAttachment(attachmentInfo.ResponseId, Attachments.counter, attachmentInfo.Answers);
var result = this.AttachmentProvider.PostAttachmentAsync(attachments);
var result = await this.AttachmentProvider.PostAttachmentAsync(attachments);
if (result.IsSuccess)
{
return Ok(result.Attachments);
@ -110,17 +110,17 @@ namespace DamageAssesment.Api.Attachments.Controllers
/// </summary>
[HttpPut("Attachments"), DisableRequestSizeLimit]
public IActionResult UpdateAttachmentAsync(AttachmentInfo attachmentInfo)
public async Task<IActionResult> UpdateAttachmentAsync(AttachmentInfo attachmentInfo)
{
try
{
if (attachmentInfo.Answers.Count > 0)
{
var res = this.AttachmentProvider.GetAttachmentInfo(attachmentInfo.Answers);
var res = await this.AttachmentProvider.GetAttachmentInfo(attachmentInfo.Answers);
if (res.IsSuccess)
{
List<Models.Attachment> attachments = UploadService.UpdateAttachments(attachmentInfo.ResponseId, attachmentInfo.Answers, res.Attachments);
var result = this.AttachmentProvider.PutAttachmentAsync(attachments);
var result = await this.AttachmentProvider.PutAttachmentAsync(attachments);
if (result.IsSuccess)
{
return Ok(result.Attachments);

View File

@ -6,12 +6,12 @@ namespace DamageAssesment.Api.Attachments.Interfaces
{
Task<(bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage)> GetAttachmentsAsync();
Task<(bool IsSuccess, Models.Attachment Attachment, string ErrorMessage)> GetAttachmentByIdAsync(int Id);
(bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage) PostAttachmentAsync(List<Models.Attachment> Attachments);
(bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage) PutAttachmentAsync(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, Models.Attachment Attachment, string Path)> DeleteAttachmentAsync(int Id);
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);
(bool IsSuccess, int counter, string message) GetAttachmentCounter();
(bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage) GetAttachmentInfo(List<AnswerInfo> answers);
Task<(bool IsSuccess, int counter, string message)> GetAttachmentCounter();
Task<(bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage)> GetAttachmentInfo(List<AnswerInfo> answers);
}
}

View File

@ -65,14 +65,14 @@ namespace DamageAssesment.Api.Attachments.Providers
return (false, null, ex.Message);
}
}
public (bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage) PostAttachmentAsync(List<Models.Attachment> Attachments)
public async Task<(bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage)> PostAttachmentAsync(List<Models.Attachment> Attachments)
{
try
{
logger?.LogInformation("Query Attachment");
List<Db.Attachment> attachments = mapper.Map<List<Models.Attachment>, List<Db.Attachment>>(Attachments);
AttachmentDbContext.Attachments.AddRange(attachments);
AttachmentDbContext.SaveChanges();
await AttachmentDbContext.SaveChangesAsync();
var result = mapper.Map<IEnumerable<Db.Attachment>, IEnumerable<Models.Attachment>>(attachments);
return (true, result, null);
}
@ -83,14 +83,14 @@ namespace DamageAssesment.Api.Attachments.Providers
}
}
public (bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage) PutAttachmentAsync(List<Models.Attachment> Attachments)
public async Task<(bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage)> PutAttachmentAsync(List<Models.Attachment> Attachments)
{
try
{
logger?.LogInformation("Query Attachment");
List<Db.Attachment> attachments = mapper.Map<List<Models.Attachment>, List<Db.Attachment>>(Attachments);
AttachmentDbContext.Attachments.UpdateRange(attachments);
AttachmentDbContext.SaveChanges();
await AttachmentDbContext.SaveChangesAsync();
var result = mapper.Map<IEnumerable<Db.Attachment>, IEnumerable<Models.Attachment>>(attachments);
return (true, result, null);
}
@ -110,7 +110,7 @@ namespace DamageAssesment.Api.Attachments.Providers
if (Attachments.Count > 0)
{
AttachmentDbContext.Attachments.RemoveRange(Attachments);
AttachmentDbContext.SaveChanges();
await AttachmentDbContext.SaveChangesAsync();
}
return (true, AttachmentId, "");
}
@ -121,7 +121,7 @@ namespace DamageAssesment.Api.Attachments.Providers
return (false, AttachmentId, "");
}
}
public (bool IsSuccess,int counter,string message) GetAttachmentCounter()
public async Task<(bool IsSuccess,int counter,string message)> GetAttachmentCounter()
{
try
{
@ -143,7 +143,7 @@ namespace DamageAssesment.Api.Attachments.Providers
if (Attachments.Count > 0)
{
AttachmentDbContext.Attachments.RemoveRange(Attachments);
AttachmentDbContext.SaveChanges();
await AttachmentDbContext.SaveChangesAsync();
}
return (true, AttachmentId, "");
}
@ -154,7 +154,7 @@ namespace DamageAssesment.Api.Attachments.Providers
return (false, AttachmentId, "");
}
}
public (bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage) GetAttachmentInfo(List<AnswerInfo> answers)
public async Task<(bool IsSuccess, IEnumerable<Models.Attachment> Attachments, string ErrorMessage)> GetAttachmentInfo(List<AnswerInfo> answers)
{
try
{
@ -183,7 +183,7 @@ namespace DamageAssesment.Api.Attachments.Providers
}
Attachment.IsDeleted = true;
AttachmentDbContext.Attachments.Update(Attachment);
AttachmentDbContext.SaveChanges();
await AttachmentDbContext.SaveChangesAsync();
return (true, mapper.Map<Db.Attachment, Models.Attachment>(Attachment), $"Attachment {Id} is deleted");
}
catch (Exception ex)