This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using AyaNova.Models;
|
||||
using AyaNova.Biz;
|
||||
@@ -192,10 +193,10 @@ namespace AyaNova.Util
|
||||
//stream entry into a new jobject and add it to the list
|
||||
StreamReader reader = new StreamReader(entry.Open());
|
||||
string text = reader.ReadToEnd();
|
||||
var j = JObject.Parse(text);
|
||||
|
||||
var j = JObject.Parse(text);
|
||||
|
||||
//Here add v7 import file name as sometimes it's needed later (locales)
|
||||
j.Add("V7_SOURCE_FILE_NAME", JToken.FromObject(importFileName));
|
||||
j.Add("V7_SOURCE_FILE_NAME", JToken.FromObject(importFileName));
|
||||
jList.Add(j);
|
||||
}
|
||||
}
|
||||
@@ -259,7 +260,7 @@ namespace AyaNova.Util
|
||||
/// <param name="attachToObject"></param>
|
||||
/// <param name="ct"></param>
|
||||
/// <returns></returns>
|
||||
internal static FileAttachment storeFileAttachment(string tempFilePath, string contentType, string fileName, AyaTypeId attachToObject, AyContext ct)
|
||||
internal static async Task<FileAttachment> StoreFileAttachmentAsync(string tempFilePath, string contentType, string fileName, AyaTypeId attachToObject, AyContext ct)
|
||||
{
|
||||
//calculate hash
|
||||
var hash = FileHash.GetChecksum(tempFilePath);
|
||||
@@ -287,15 +288,15 @@ namespace AyaNova.Util
|
||||
{
|
||||
StoredFileName = hash,
|
||||
DisplayFileName = fileName,
|
||||
Notes = string.Empty,
|
||||
Notes = string.Empty,
|
||||
ContentType = contentType,
|
||||
AttachToObjectId = attachToObject.ObjectId,
|
||||
AttachToObjectType = attachToObject.ObjectType
|
||||
};
|
||||
|
||||
//Store in DB
|
||||
ct.FileAttachment.Add(fi);
|
||||
ct.SaveChanges();
|
||||
await ct.FileAttachment.AddAsync(fi);
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//Return AyFileInfo object
|
||||
return fi;
|
||||
@@ -333,15 +334,15 @@ namespace AyaNova.Util
|
||||
/// <param name="fileAttachmentToBeDeleted"></param>
|
||||
/// <param name="ct"></param>
|
||||
/// <returns></returns>
|
||||
internal static FileAttachment deleteFileAttachment(FileAttachment fileAttachmentToBeDeleted, AyContext ct)
|
||||
internal static async Task<FileAttachment> DeleteFileAttachmentAsync(FileAttachment fileAttachmentToBeDeleted, AyContext ct)
|
||||
{
|
||||
|
||||
//check ref count of file
|
||||
var count = ct.FileAttachment.Count(w => w.StoredFileName == fileAttachmentToBeDeleted.StoredFileName);
|
||||
var count = await ct.FileAttachment.LongCountAsync(w => w.StoredFileName == fileAttachmentToBeDeleted.StoredFileName);
|
||||
|
||||
//Store in DB
|
||||
ct.FileAttachment.Remove(fileAttachmentToBeDeleted);
|
||||
ct.SaveChanges();
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
if (count < 2)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user