diff --git a/Yavsc/ApiControllers/PdfEstimateController.cs b/Yavsc/ApiControllers/PdfEstimateController.cs index e871ba68..d16fc18e 100644 --- a/Yavsc/ApiControllers/PdfEstimateController.cs +++ b/Yavsc/ApiControllers/PdfEstimateController.cs @@ -84,6 +84,7 @@ namespace Yavsc.ApiControllers return ViewComponent("Estimate",new object[] { id, "Pdf" } ); } + [HttpPost("prosign/{id}")] public async Task ProSign(long id) { @@ -97,7 +98,7 @@ namespace Yavsc.ApiControllers } if (Request.Form.Files.Count!=1) return new BadRequestResult(); - User.ReceiveSignature(id,Request.Form.Files[0],"pro"); + User.ReceiveProSignature(id,Request.Form.Files[0],"pro"); estimate.ProviderValidationDate = DateTime.Now; dbContext.SaveChanges(); // Notify the client @@ -107,6 +108,22 @@ namespace Yavsc.ApiControllers return Ok (new { ProviderValidationDate = estimate.ProviderValidationDate, GCMSent = grep.success }); } + [HttpGet("prosign/{id}")] + public async Task GetProSign(long id) + { + // For authorization purpose + var estimate = dbContext.Estimates.FirstOrDefault(e=>e.Id == id); + if (!await authorizationService.AuthorizeAsync(User, estimate, new ViewRequirement())) + { + return new ChallengeResult(); + } + + var filename = FileSystemHelpers.SignFileNameFormat("pro",id); + FileInfo fi = new FileInfo(Path.Combine(Startup.UserBillsDirName, filename)); + if (!fi.Exists) return HttpNotFound(new { Error = "Professional signature not found" }); + return File(fi.OpenRead(), "application/x-pdf", filename); ; + } + [HttpPost("clisign/{id}")] public async Task CliSign(long id) { @@ -119,11 +136,26 @@ namespace Yavsc.ApiControllers } if (Request.Form.Files.Count!=1) return new BadRequestResult(); - User.ReceiveSignature(id,Request.Form.Files[0],"cli"); + User.ReceiveProSignature(id,Request.Form.Files[0],"cli"); estimate.ClientValidationDate = DateTime.Now; dbContext.SaveChanges(); return Ok (new { ClientValidationDate = estimate.ClientValidationDate }); } + [HttpGet("clisign/{id}")] + public async Task GetCliSign(long id) + { + // For authorization purpose + var estimate = dbContext.Estimates.FirstOrDefault(e=>e.Id == id); + if (!await authorizationService.AuthorizeAsync(User, estimate, new ViewRequirement())) + { + return new ChallengeResult(); + } + + var filename = FileSystemHelpers.SignFileNameFormat("pro",id); + FileInfo fi = new FileInfo(Path.Combine(Startup.UserBillsDirName, filename)); + if (!fi.Exists) return HttpNotFound(new { Error = "Professional signature not found" }); + return File(fi.OpenRead(), "application/x-pdf", filename); ; + } } } \ No newline at end of file diff --git a/Yavsc/Helpers/FileSystemHelpers.cs b/Yavsc/Helpers/FileSystemHelpers.cs index f4ec2aa2..0c42fcad 100644 --- a/Yavsc/Helpers/FileSystemHelpers.cs +++ b/Yavsc/Helpers/FileSystemHelpers.cs @@ -1,5 +1,6 @@ +using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; @@ -169,10 +170,13 @@ namespace Yavsc.Helpers dir, xsmallname), ImageFormat.Png); } } - public static FileRecievedInfo ReceiveSignature(this ClaimsPrincipal user, long estimateId, IFormFile formFile, string signtype) + public static Func + SignFileNameFormat = new Func ((signType,estimateId) => $"estimate-{signType}sign-{estimateId}.png"); + + public static FileRecievedInfo ReceiveProSignature(this ClaimsPrincipal user, long estimateId, IFormFile formFile, string signtype) { var item = new FileRecievedInfo(); - item.FileName = $"estimate-{signtype}sign-{estimateId}.png"; + item.FileName = SignFileNameFormat("pro",estimateId); var destFileName = Path.Combine(Startup.SiteSetup.UserFiles.Bills, item.FileName); var fi = new FileInfo(destFileName); diff --git a/Yavsc/Models/Workflow/Process/Action.cs b/Yavsc/Models/Workflow/Process/Action.cs index e12babba..66e64704 100644 --- a/Yavsc/Models/Workflow/Process/Action.cs +++ b/Yavsc/Models/Workflow/Process/Action.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; -namespace Yavsc.Models +namespace Yavsc.Models.Process { public abstract class Action { diff --git a/Yavsc/Models/Workflow/Process/Conjonction.cs b/Yavsc/Models/Workflow/Process/Conjonction.cs index aef10887..bd2125db 100644 --- a/Yavsc/Models/Workflow/Process/Conjonction.cs +++ b/Yavsc/Models/Workflow/Process/Conjonction.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Yavsc.Models +namespace Yavsc.Models.Process { public class Conjonction : List, IRequisition { diff --git a/Yavsc/Models/Workflow/Process/Disjonction.cs b/Yavsc/Models/Workflow/Process/Disjonction.cs index 268cce11..416257b7 100644 --- a/Yavsc/Models/Workflow/Process/Disjonction.cs +++ b/Yavsc/Models/Workflow/Process/Disjonction.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Yavsc.Models +namespace Yavsc.Models.Process { public class Disjonction : List, IRequisition { diff --git a/Yavsc/Models/Workflow/Process/InputValue.cs b/Yavsc/Models/Workflow/Process/InputValue.cs index 813b4b48..cb6290e0 100644 --- a/Yavsc/Models/Workflow/Process/InputValue.cs +++ b/Yavsc/Models/Workflow/Process/InputValue.cs @@ -1,5 +1,5 @@ -namespace Yavsc.Models +namespace Yavsc.Models.Process { public class ConstInputValue : NamedRequisition { diff --git a/Yavsc/Models/Workflow/Process/NamedRequisition.cs b/Yavsc/Models/Workflow/Process/NamedRequisition.cs index 92955407..570dbf33 100644 --- a/Yavsc/Models/Workflow/Process/NamedRequisition.cs +++ b/Yavsc/Models/Workflow/Process/NamedRequisition.cs @@ -1,5 +1,5 @@ -namespace Yavsc.Models +namespace Yavsc.Models.Process { public abstract class NamedRequisition : IRequisition { diff --git a/Yavsc/Models/Workflow/Process/Negation.cs b/Yavsc/Models/Workflow/Process/Negation.cs index 3bf19766..343b9940 100644 --- a/Yavsc/Models/Workflow/Process/Negation.cs +++ b/Yavsc/Models/Workflow/Process/Negation.cs @@ -1,5 +1,5 @@ -namespace Yavsc.Models +namespace Yavsc.Models.Process { public class Negation : IRequisition where Exp : IRequisition { diff --git a/Yavsc/Models/Workflow/Process/Rule.cs b/Yavsc/Models/Workflow/Process/Rule.cs index 1d04967f..f367344e 100644 --- a/Yavsc/Models/Workflow/Process/Rule.cs +++ b/Yavsc/Models/Workflow/Process/Rule.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace Yavsc.Models +namespace Yavsc.Models.Process { /// /// An abstract, identified rule