estimation signature
This commit is contained in:
parent
959ce72d79
commit
077e1051ff
2 changed files with 33 additions and 23 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
using System;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using Microsoft.AspNet.Authorization;
|
using Microsoft.AspNet.Authorization;
|
||||||
|
|
@ -68,7 +67,6 @@ namespace Yavsc.Controllers
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
public IActionResult PutEstimate(long id, [FromBody] Estimate estimate)
|
public IActionResult PutEstimate(long id, [FromBody] Estimate estimate)
|
||||||
{
|
{
|
||||||
var valdate = DateTime.Now;
|
|
||||||
|
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
{
|
{
|
||||||
|
|
@ -90,7 +88,6 @@ namespace Yavsc.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
var entry = _context.Attach(estimate);
|
var entry = _context.Attach(estimate);
|
||||||
estimate.ProviderValidationDate = valdate;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_context.SaveChanges();
|
_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
|
// POST: api/Estimate
|
||||||
|
|
@ -127,8 +124,6 @@ namespace Yavsc.Controllers
|
||||||
return HttpBadRequest(ModelState);
|
return HttpBadRequest(ModelState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var valdate = DateTime.Now;
|
|
||||||
estimate.ProviderValidationDate = valdate;
|
|
||||||
|
|
||||||
_context.Estimates.Add(estimate);
|
_context.Estimates.Add(estimate);
|
||||||
/* _context.AttachRange(estimate.Bill);
|
/* _context.AttachRange(estimate.Bill);
|
||||||
|
|
@ -153,7 +148,7 @@ namespace Yavsc.Controllers
|
||||||
throw;
|
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
|
// DELETE: api/Estimate/5
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ namespace Yavsc.ApiControllers
|
||||||
using Microsoft.Data.Entity;
|
using Microsoft.Data.Entity;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
|
||||||
[Route("api/pdfestimate"), Authorize]
|
[Route("api/pdfestimate"), Authorize]
|
||||||
public class PdfEstimateController : Controller
|
public class PdfEstimateController : Controller
|
||||||
|
|
@ -37,48 +38,62 @@ namespace Yavsc.ApiControllers
|
||||||
var estimate = dbContext.Estimates.Include(
|
var estimate = dbContext.Estimates.Include(
|
||||||
e=>e.Query
|
e=>e.Query
|
||||||
).FirstOrDefault(e=>e.Id == id);
|
).FirstOrDefault(e=>e.Id == id);
|
||||||
logger.LogWarning($"#######ESTIMATE OWNER ID {estimate.OwnerId} ########");
|
|
||||||
if (!await authorizationService.AuthorizeAsync(User, estimate, new ViewRequirement()))
|
if (!await authorizationService.AuthorizeAsync(User, estimate, new ViewRequirement()))
|
||||||
{
|
{
|
||||||
return new ChallengeResult();
|
return new ChallengeResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
var filename = $"estimate-{id}.pdf";
|
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));
|
FileInfo fi = new FileInfo(Path.Combine(Startup.UserBillsDirName, filename));
|
||||||
if (!fi.Exists) return Ok(new { Error = "Not generated" });
|
if (!fi.Exists) return Ok(new { Error = "Not generated" });
|
||||||
return File(fi.OpenRead(), "application/x-pdf", filename); ;
|
return File(fi.OpenRead(), "application/x-pdf", filename); ;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("estimate-{id}.tex", Name = "GetTex"), Authorize]
|
[HttpGet("estimate-{id}.tex", Name = "GetTex"), Authorize]
|
||||||
public IActionResult GetTex(long id)
|
public async Task<IActionResult> 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";
|
Response.ContentType = "text/x-tex";
|
||||||
return ViewComponent("Estimate",new object[] { id, "LaTeX" });
|
return ViewComponent("Estimate",new object[] { id, "LaTeX" });
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("gen/{id}")]
|
[HttpPost("gen/{id}")]
|
||||||
public IActionResult GeneratePdf(long id)
|
public async Task<IActionResult> 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" } );
|
return ViewComponent("Estimate",new object[] { id, "Pdf" } );
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("prosign/{id}")]
|
[HttpPost("prosign/{id}")]
|
||||||
public IActionResult ProSign(long id)
|
public async Task<IActionResult> 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)
|
if (Request.Form.Files.Count!=1)
|
||||||
return new BadRequestResult();
|
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 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue