This commit is contained in:
2018-10-04 20:56:40 +00:00
parent 179cc0a522
commit 7ea5c911aa
6 changed files with 24 additions and 18 deletions

View File

@@ -73,9 +73,7 @@ namespace AyaNova.Api.Controllers
public async Task<IActionResult> GetDownloadToken()
{
if (!serverState.IsOpen)
{
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
}
long lUserId = UserIdFromContext.Id(HttpContext.Items);
var u = await ct.User.FirstOrDefaultAsync(a => a.Id == lUserId);
@@ -127,22 +125,15 @@ namespace AyaNova.Api.Controllers
{
//Adapted from the example found here: https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads#uploading-large-files-with-streaming
if (!serverState.IsOpen)
{
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
}
var returnList = new List<NameIdItem>();
try
{
if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
{
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, "FileUploadAttempt", $"Expected a multipart request, but got {Request.ContentType}"));
}
var uploadFormData = await ApiUploadProcessor.ProcessAttachmentUpload(HttpContext);
@@ -238,9 +229,13 @@ namespace AyaNova.Api.Controllers
Id = v.Id
});
//Log
//EVENT LOG
EventLogProcessor.AddEntryToContextNoSave(new Event(UserId, attachToObject.ObjectId, attachToObject.ObjectType, AyaEvent.AttachmentCreate, v.DisplayFileName), ct);
ct.SaveChanges();
//SEARCH INDEXING
Search.ProcessNewObjectKeywords(ct, UserLocaleIdFromContext.Id(HttpContext.Items), v.Id, AyaType.FileAttachment, v.DisplayFileName, v.DisplayFileName, v.Notes, v.StoredFileName);
}
}
}
@@ -305,9 +300,13 @@ namespace AyaNova.Api.Controllers
//this handles removing the file if there are no refs left and also the db record for the attachment
FileUtil.deleteFileAttachment(dbObj, ct);
//Log
//Event log process delete
EventLogProcessor.AddEntryToContextNoSave(new Event(UserId, dbObj.AttachToObjectId, dbObj.AttachToObjectType, AyaEvent.AttachmentDelete, dbObj.DisplayFileName), ct);
ct.SaveChanges();
//Delete search index
Search.ProcessDeletedObjectKeywords(ct, dbObj.Id, AyaType.FileAttachment);
return NoContent();
}