|
@@ -1,29 +1,36 @@
|
|
|
using System;
|
|
|
+using System.Linq;
|
|
|
using InABox.Clients;
|
|
|
using InABox.Core;
|
|
|
+using JetBrains.Annotations;
|
|
|
|
|
|
namespace InABox.Mobile
|
|
|
{
|
|
|
public static class EntityDocumentUtils
|
|
|
{
|
|
|
+ [CanBeNull]
|
|
|
public static T SaveDocument<T>(MobileDocument image, Func<T> shell, string auditmessage) where T : IEntityDocumentShell
|
|
|
{
|
|
|
- T result = default(T);
|
|
|
- Document doc = new Document()
|
|
|
+ T result = shell();
|
|
|
+ if (result != null)
|
|
|
{
|
|
|
- FileName = image.FileName,
|
|
|
- Data = image.Data,
|
|
|
- CRC = CoreUtils.CalculateCRC(image.Data),
|
|
|
- TimeStamp = DateTime.Now
|
|
|
- };
|
|
|
- new Client<Document>().Save(doc, auditmessage);
|
|
|
-
|
|
|
- result = shell();
|
|
|
- result.DocumentID = doc.ID;
|
|
|
- result.FileName = doc.FileName;
|
|
|
- result.Thumbnail = MobileUtils.ImageTools.CreateThumbnail(doc.Data, 128, 128);
|
|
|
- result.Save(auditmessage);
|
|
|
-
|
|
|
+ Document doc = new Document()
|
|
|
+ {
|
|
|
+ FileName = image.FileName,
|
|
|
+ Data = image.Data,
|
|
|
+ CRC = CoreUtils.CalculateCRC(image.Data),
|
|
|
+ TimeStamp = DateTime.Now
|
|
|
+ };
|
|
|
+ new Client<Document>().Save(doc, auditmessage);
|
|
|
+
|
|
|
+
|
|
|
+ result.DocumentID = doc.ID;
|
|
|
+ result.FileName = doc.FileName;
|
|
|
+ if ((!image.IsPDF()) && result.Thumbnail?.Any() != true)
|
|
|
+ result.Thumbnail = MobileUtils.ImageTools.CreateThumbnail(doc.Data, 256, 256);
|
|
|
+ result.Save(auditmessage);
|
|
|
+ }
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
}
|