Feature: Document Template Packages

Document Templates can be grouped into a package and generated on-demand
in the same was as individual document templates. Packages can be
generated in bulk.
This commit is contained in:
Gary Sharp
2016-11-14 01:21:23 +11:00
parent ef8df08e29
commit aca037ecf8
75 changed files with 8008 additions and 2078 deletions
@@ -6,6 +6,7 @@ using Disco.Services;
using Disco.Services.Authorization;
using Disco.Services.Devices.Exporting;
using Disco.Services.Devices.Importing;
using Disco.Services.Documents;
using Disco.Services.Interop;
using Disco.Services.Interop.ActiveDirectory;
using Disco.Services.Users;
@@ -380,9 +381,10 @@ namespace Disco.Web.Areas.API.Controllers
public virtual ActionResult GeneratePdf(string id, string DocumentTemplateId)
{
if (string.IsNullOrEmpty(id))
throw new ArgumentNullException("id");
throw new ArgumentNullException(nameof(id));
if (string.IsNullOrEmpty(DocumentTemplateId))
throw new ArgumentNullException("AttachmentTypeId");
throw new ArgumentNullException(nameof(DocumentTemplateId));
var device = Database.Devices.Find(id);
if (device != null)
{
@@ -400,12 +402,49 @@ namespace Disco.Web.Areas.API.Controllers
}
else
{
throw new ArgumentException("Invalid Document Template Id", "id");
throw new ArgumentException("Invalid Document Template Id", nameof(DocumentTemplateId));
}
}
else
{
throw new ArgumentException("Invalid Serial Number", "id");
throw new ArgumentException("Invalid Serial Number", nameof(id));
}
}
[DiscoAuthorize(Claims.Device.Actions.GenerateDocuments)]
public virtual ActionResult GeneratePdfPackage(string id, string DocumentTemplatePackageId)
{
if (string.IsNullOrEmpty(id))
throw new ArgumentNullException(nameof(id));
if (string.IsNullOrEmpty(DocumentTemplatePackageId))
throw new ArgumentNullException(nameof(DocumentTemplatePackageId));
var device = Database.Devices.Find(id);
if (device != null)
{
var package = DocumentTemplatePackages.GetPackage(DocumentTemplatePackageId);
if (package != null)
{
if (package.Scope != AttachmentTypes.Device)
throw new ArgumentException("This package cannot be generated from the Device Scope", nameof(DocumentTemplatePackageId));
var timeStamp = DateTime.Now;
Stream pdf;
using (var generationState = DocumentState.DefaultState())
{
pdf = package.GeneratePdfPackage(Database, device, UserService.CurrentUser, timeStamp, generationState);
}
Database.SaveChanges();
return File(pdf, "application/pdf", string.Format("{0}_{1}_{2:yyyyMMdd-HHmmss}.pdf", package.Id, device.SerialNumber, timeStamp));
}
else
{
throw new ArgumentException("Invalid Document Template Package Id", nameof(DocumentTemplatePackageId));
}
}
else
{
throw new ArgumentException("Invalid Serial Number", nameof(id));
}
}