This commit is contained in:
2022-03-10 23:32:33 +00:00
parent 3591907b41
commit 0784313e6d
5 changed files with 62 additions and 17 deletions

View File

@@ -242,6 +242,7 @@ namespace AyaNova.Api.Controllers
string AttachToObjectId = string.Empty;
string errorMessage = string.Empty;
string Notes = string.Empty;
long? OverrideUserId = null;
List<UploadFileData> FileData = new List<UploadFileData>();
var uploadFormData = await ApiUploadProcessor.ProcessUploadAsync(HttpContext);
@@ -262,6 +263,10 @@ namespace AyaNova.Api.Controllers
if (!badRequest)
{
AttachToAType = uploadFormData.FormFieldData["AttachToAType"].ToString();
//for v8 migrate purposes
if (uploadFormData.FormFieldData.ContainsKey("OverrideUserId"))
OverrideUserId = long.Parse(uploadFormData.FormFieldData["AttachToAType"].ToString());
AttachToObjectId = uploadFormData.FormFieldData["AttachToObjectId"].ToString();
if (uploadFormData.FormFieldData.ContainsKey("Notes"))
Notes = uploadFormData.FormFieldData["Notes"].ToString();
@@ -365,7 +370,7 @@ namespace AyaNova.Api.Controllers
if (theDate == DateTime.MinValue)
theDate = DateTime.UtcNow;
var v = await FileUtil.StoreFileAttachmentAsync(a.InitialUploadedPathName, a.MimeType, a.OriginalFileName, theDate, attachToObject, Notes, ct);
var v = await FileUtil.StoreFileAttachmentAsync(a.InitialUploadedPathName, a.MimeType, a.OriginalFileName, theDate, attachToObject, Notes, OverrideUserId ?? UserId, ct);
//EVENT LOG
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, attachToObject.ObjectId, attachToObject.AType, AyaEvent.AttachmentCreate, v.DisplayFileName), ct);
@@ -561,7 +566,7 @@ namespace AyaNova.Api.Controllers
//is this allowed?
//Is this a customer user attempting to view a wo attachments??
if (dbObject.AttachToAType == AyaType.WorkOrder && (DownloadUser.UserType == UserType.Customer || DownloadUser.UserType == UserType.HeadOffice))
{
//check if allowed
@@ -606,14 +611,46 @@ namespace AyaNova.Api.Controllers
async private Task<object> GetFileListForObjectAsync(AyaType ayaType, long ayaId)
{
return await ct.FileAttachment.AsNoTracking().Where(z => z.AttachToObjectId == ayaId && z.AttachToAType == ayaType).OrderBy(z => z.DisplayFileName)
.Select(z => new { z.Id, z.Concurrency, z.ContentType, z.DisplayFileName, z.LastModified, z.Notes })
.ToArrayAsync();
// var v = l.OrderBy(z => z.DisplayFileName);
// return v;
var retList = new List<FileAttachmentListItem>();
using (var cmd = ct.Database.GetDbConnection().CreateCommand())
{
await ct.Database.OpenConnectionAsync();
cmd.CommandText = $@"select afileattachment.id, displayfilename,contenttype,lastmodified, afileattachment.notes, size, auser.name as attachedbyuser from afileattachment
left join auser on (afileattachment.attachtoobjectid=auser.id)
where attachtoatype={ayaType} and attachtoobjectid={ayaId}
order by displayfilename";
using (var dr = await cmd.ExecuteReaderAsync())
{
while (dr.Read())
{
retList.Add(new FileAttachmentListItem() {
Id = dr.GetInt64(0),
DisplayFileName = dr.GetString(1),
ContentType = dr.GetString(2),
LastModified = dr.GetDateTime(3),
Notes = dr.GetString(4),
AttachedByUser = dr.GetString(5),
Size = dr.GetInt64(6)
});
}
}
}
return retList;
}
private class FileAttachmentListItem
{
public long Id { get; set; }
// public uint Concurrency { get; set; }
public string DisplayFileName { get; set; }
public string ContentType { get; set; }//mime type
public DateTime LastModified { get; set; }
public string Notes { get; set; }
public string AttachedByUser { get; set; }
public long Size { get; set; }
}
/// <summary>
/// Trigger immediate AttachmentMaintenanceJob