This commit is contained in:
2020-04-22 18:57:24 +00:00
parent bb2d6fe357
commit b7e770d5dc

View File

@@ -76,7 +76,7 @@ namespace AyaNova.Api.Controllers
if (!ModelState.IsValid) if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState)); return BadRequest(new ApiErrorResponse(ModelState));
var ret = await ct.FileAttachment.AsNoTracking().Where(m => m.AttachToObjectId == ayaId && m.AttachToObjectType == ayaType).OrderBy(m => m.DisplayFileName).Select(m => new { m.Id, m.ConcurrencyToken, m.ContentType, m.DisplayFileName, m.LastModified, m.Notes }).ToArrayAsync(); var ret = await GetFileListForObjectAsync(ayaType, ayaId);
return Ok(ApiOkResponse.Response(ret, true)); return Ok(ApiOkResponse.Response(ret, true));
} }
@@ -99,8 +99,9 @@ namespace AyaNova.Api.Controllers
if (!serverState.IsOpen) if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason)); return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
var returnList = new List<NameIdItem>(); // var returnList = new List<NameIdItem>();
object ret = null;
AyaTypeId attachToObject = null;
try try
{ {
if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType)) if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
@@ -133,7 +134,7 @@ namespace AyaNova.Api.Controllers
//Get type and id object from post paramters //Get type and id object from post paramters
AyaTypeId attachToObject = null;
if (!badRequest) if (!badRequest)
{ {
attachToObject = new AyaTypeId(AttachToObjectType, AttachToObjectId); attachToObject = new AyaTypeId(AttachToObjectType, AttachToObjectId);
@@ -195,11 +196,11 @@ namespace AyaNova.Api.Controllers
foreach (UploadedFileInfo a in uploadFormData.UploadedFiles) foreach (UploadedFileInfo a in uploadFormData.UploadedFiles)
{ {
var v = await FileUtil.StoreFileAttachmentAsync(a.InitialUploadedPathName, a.MimeType, a.OriginalFileName, a.LastModified, attachToObject, Notes, ct); var v = await FileUtil.StoreFileAttachmentAsync(a.InitialUploadedPathName, a.MimeType, a.OriginalFileName, a.LastModified, attachToObject, Notes, ct);
returnList.Add(new NameIdItem() // returnList.Add(new NameIdItem()
{ // {
Name = v.DisplayFileName, // Name = v.DisplayFileName,
Id = v.Id // Id = v.Id
}); // });
//EVENT LOG //EVENT LOG
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, attachToObject.ObjectId, attachToObject.ObjectType, AyaEvent.AttachmentCreate, v.DisplayFileName), ct); await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, attachToObject.ObjectId, attachToObject.ObjectType, AyaEvent.AttachmentCreate, v.DisplayFileName), ct);
@@ -211,6 +212,7 @@ namespace AyaNova.Api.Controllers
} }
} }
ret = await GetFileListForObjectAsync(attachToObject.ObjectType, attachToObject.ObjectId);
} }
catch (InvalidDataException ex) catch (InvalidDataException ex)
{ {
@@ -218,7 +220,7 @@ namespace AyaNova.Api.Controllers
} }
//Return the list of attachment ids and filenames //Return the list of attachment ids and filenames
return Ok(ApiOkResponse.Response(returnList, false)); return Ok(ApiOkResponse.Response(ret, false));
} }
/// <summary> /// <summary>
@@ -380,6 +382,10 @@ namespace AyaNova.Api.Controllers
//////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////
async private Task<object> GetFileListForObjectAsync(AyaType ayaType, long ayaId)
{
return await ct.FileAttachment.AsNoTracking().Where(m => m.AttachToObjectId == ayaId && m.AttachToObjectType == ayaType).OrderBy(m => m.DisplayFileName).Select(m => new { m.Id, m.ConcurrencyToken, m.ContentType, m.DisplayFileName, m.LastModified, m.Notes }).ToArrayAsync();
}
}//eoc }//eoc
}//eons }//eons