This commit is contained in:
@@ -13,6 +13,7 @@ using AyaNova.Api.ControllerHelpers;
|
|||||||
using AyaNova.Util;
|
using AyaNova.Util;
|
||||||
using AyaNova.Biz;
|
using AyaNova.Biz;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace AyaNova.Api.Controllers
|
namespace AyaNova.Api.Controllers
|
||||||
{
|
{
|
||||||
@@ -133,7 +134,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Normallyh wouldn't return a whole list but in this case the UI demands it because of reactivity issues
|
//Normallyh wouldn't return a whole list but in this case the UI demands it because of reactivity issues
|
||||||
var ret = await GetFileListForObjectAsync(dbObj.AttachToObjectType, dbObj.AttachToObjectId);
|
var ret = await GetFileListForObjectAsync(dbObj.AttachToObjectType, dbObj.AttachToObjectId);
|
||||||
return Ok(ApiOkResponse.Response(ret, true));
|
return Ok(ApiOkResponse.Response(ret, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,6 +164,13 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//used to hold extra file data sent by client
|
||||||
|
public class fileData
|
||||||
|
{
|
||||||
|
public string name { get; set; }
|
||||||
|
public long lastModified { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Upload attachment file
|
/// Upload attachment file
|
||||||
///
|
///
|
||||||
@@ -196,6 +204,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
string AttachToObjectId = string.Empty;
|
string AttachToObjectId = string.Empty;
|
||||||
string errorMessage = string.Empty;
|
string errorMessage = string.Empty;
|
||||||
string Notes = string.Empty;
|
string Notes = string.Empty;
|
||||||
|
List<fileData> FileData = new List<fileData>();
|
||||||
|
|
||||||
if (!uploadFormData.FormFieldData.ContainsKey("AttachToObjectType") || !uploadFormData.FormFieldData.ContainsKey("AttachToObjectId"))
|
if (!uploadFormData.FormFieldData.ContainsKey("AttachToObjectType") || !uploadFormData.FormFieldData.ContainsKey("AttachToObjectId"))
|
||||||
{
|
{
|
||||||
@@ -207,6 +216,10 @@ namespace AyaNova.Api.Controllers
|
|||||||
AttachToObjectType = uploadFormData.FormFieldData["AttachToObjectType"].ToString();
|
AttachToObjectType = uploadFormData.FormFieldData["AttachToObjectType"].ToString();
|
||||||
AttachToObjectId = uploadFormData.FormFieldData["AttachToObjectId"].ToString();
|
AttachToObjectId = uploadFormData.FormFieldData["AttachToObjectId"].ToString();
|
||||||
Notes = uploadFormData.FormFieldData["Notes"].ToString();
|
Notes = uploadFormData.FormFieldData["Notes"].ToString();
|
||||||
|
//fileData in JSON stringify format which contains the actual last modified dates etc
|
||||||
|
//"[{\"name\":\"Client.csv\",\"lastModified\":1582822079618},{\"name\":\"wmi4fu06nrs41.jpg\",\"lastModified\":1586900220990}]"
|
||||||
|
FileData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<fileData>>(uploadFormData.FormFieldData["FileData"].ToString());
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(AttachToObjectType) || string.IsNullOrWhiteSpace(AttachToObjectId))
|
if (string.IsNullOrWhiteSpace(AttachToObjectType) || string.IsNullOrWhiteSpace(AttachToObjectId))
|
||||||
{
|
{
|
||||||
badRequest = true;
|
badRequest = true;
|
||||||
@@ -275,14 +288,26 @@ namespace AyaNova.Api.Controllers
|
|||||||
//We have our files and a confirmed AyObject, ready to attach and save permanently
|
//We have our files and a confirmed AyObject, ready to attach and save permanently
|
||||||
if (uploadFormData.UploadedFiles.Count > 0)
|
if (uploadFormData.UploadedFiles.Count > 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
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);
|
//Get the actual date from the separate filedata
|
||||||
// returnList.Add(new NameIdItem()
|
//this is because the lastModified date is always empty in the form data files
|
||||||
// {
|
DateTime theDate = DateTime.MinValue;
|
||||||
// Name = v.DisplayFileName,
|
foreach (fileData f in FileData)
|
||||||
// Id = v.Id
|
{
|
||||||
// });
|
if (f.name == a.OriginalFileName)
|
||||||
|
{
|
||||||
|
if (f.lastModified > 0)
|
||||||
|
{
|
||||||
|
theDate = DateTimeOffset.FromUnixTimeMilliseconds(f.lastModified).DateTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (theDate == DateTime.MinValue)
|
||||||
|
theDate = DateTime.UtcNow;
|
||||||
|
|
||||||
|
var v = await FileUtil.StoreFileAttachmentAsync(a.InitialUploadedPathName, a.MimeType, a.OriginalFileName, theDate, attachToObject, Notes, ct);
|
||||||
|
|
||||||
//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);
|
||||||
|
|||||||
Reference in New Issue
Block a user