diff --git a/Yavsc/ApiControllers/EstimateApiController.cs b/Yavsc/ApiControllers/EstimateApiController.cs index 3b35502d..400a2633 100644 --- a/Yavsc/ApiControllers/EstimateApiController.cs +++ b/Yavsc/ApiControllers/EstimateApiController.cs @@ -1,4 +1,3 @@ -using System; using System.Linq; using System.Security.Claims; using Microsoft.AspNet.Authorization; @@ -68,7 +67,6 @@ namespace Yavsc.Controllers [HttpPut("{id}")] public IActionResult PutEstimate(long id, [FromBody] Estimate estimate) { - var valdate = DateTime.Now; if (!ModelState.IsValid) { @@ -90,7 +88,6 @@ namespace Yavsc.Controllers } var entry = _context.Attach(estimate); - estimate.ProviderValidationDate = valdate; try { _context.SaveChanges(); @@ -107,7 +104,7 @@ namespace Yavsc.Controllers } } - return Ok( new { Id = estimate.Id, LatestValidationDate = valdate }); + return Ok( new { Id = estimate.Id }); } // POST: api/Estimate @@ -127,8 +124,6 @@ namespace Yavsc.Controllers return HttpBadRequest(ModelState); } } - var valdate = DateTime.Now; - estimate.ProviderValidationDate = valdate; _context.Estimates.Add(estimate); /* _context.AttachRange(estimate.Bill); @@ -153,7 +148,7 @@ namespace Yavsc.Controllers throw; } } - return Ok( new { Id = estimate.Id, Bill = estimate.Bill , LatestValidationDate = valdate }); + return Ok( new { Id = estimate.Id, Bill = estimate.Bill }); } // DELETE: api/Estimate/5 diff --git a/Yavsc/ApiControllers/PdfEstimateController.cs b/Yavsc/ApiControllers/PdfEstimateController.cs index 7c940bbc..d819d88a 100644 --- a/Yavsc/ApiControllers/PdfEstimateController.cs +++ b/Yavsc/ApiControllers/PdfEstimateController.cs @@ -11,6 +11,7 @@ namespace Yavsc.ApiControllers using Microsoft.Data.Entity; using System.Threading.Tasks; using Microsoft.Extensions.Logging; + using System; [Route("api/pdfestimate"), Authorize] public class PdfEstimateController : Controller @@ -37,48 +38,62 @@ namespace Yavsc.ApiControllers var estimate = dbContext.Estimates.Include( e=>e.Query ).FirstOrDefault(e=>e.Id == id); - logger.LogWarning($"#######ESTIMATE OWNER ID {estimate.OwnerId} ########"); if (!await authorizationService.AuthorizeAsync(User, estimate, new ViewRequirement())) { return new ChallengeResult(); } - + var filename = $"estimate-{id}.pdf"; - var cd = new System.Net.Mime.ContentDisposition - { - // for example foo.bak - FileName = filename, - - // always prompt the user for downloading, set to true if you want - // the browser to try to show the file inline - Inline = false, - }; - FileInfo fi = new FileInfo(Path.Combine(Startup.UserBillsDirName, filename)); if (!fi.Exists) return Ok(new { Error = "Not generated" }); return File(fi.OpenRead(), "application/x-pdf", filename); ; } [HttpGet("estimate-{id}.tex", Name = "GetTex"), Authorize] - public IActionResult GetTex(long id) + public async Task GetTex(long id) { + var estimate = dbContext.Estimates.Include( + e=>e.Query + ).FirstOrDefault(e=>e.Id == id); + if (!await authorizationService.AuthorizeAsync(User, estimate, new ViewRequirement())) + { + return new ChallengeResult(); + } Response.ContentType = "text/x-tex"; return ViewComponent("Estimate",new object[] { id, "LaTeX" }); } [HttpPost("gen/{id}")] - public IActionResult GeneratePdf(long id) + public async Task GeneratePdf(long id) { + var estimate = dbContext.Estimates.Include( + e=>e.Query + ).FirstOrDefault(e=>e.Id == id); + if (!await authorizationService.AuthorizeAsync(User, estimate, new ViewRequirement())) + { + return new ChallengeResult(); + } return ViewComponent("Estimate",new object[] { id, "Pdf" } ); } [HttpPost("prosign/{id}")] - public IActionResult ProSign(long id) + public async Task ProSign(long id) { + var estimate = dbContext.Estimates.Include( + e=>e.Query + ).FirstOrDefault(e=>e.Id == id); + logger.LogWarning("I Was here"); + if (!await authorizationService.AuthorizeAsync(User, estimate, new ViewRequirement())) + { + return new ChallengeResult(); + } if (Request.Form.Files.Count!=1) return new BadRequestResult(); - return Ok (User.ReceiveProSignature(id,Request.Form.Files[0])); + User.ReceiveProSignature(id,Request.Form.Files[0]); + estimate.ProviderValidationDate = DateTime.Now; + dbContext.SaveChanges(); + return Ok (new { ProviderValidationDate = estimate.ProviderValidationDate }); } } } \ No newline at end of file