2016-11-07 19:34:56 +01:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using Microsoft.AspNet.Authorization;
|
|
|
|
|
|
using Microsoft.AspNet.Mvc;
|
2016-11-09 14:03:57 +01:00
|
|
|
|
using System.Web.Routing;
|
|
|
|
|
|
using Microsoft.AspNet.Mvc.ViewComponents;
|
2016-11-07 19:34:56 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Yavsc.ApiControllers
|
|
|
|
|
|
{
|
2016-11-09 14:03:57 +01:00
|
|
|
|
using Models;
|
2016-12-01 17:42:34 +01:00
|
|
|
|
using Helpers;
|
2016-11-09 14:03:57 +01:00
|
|
|
|
|
2016-11-07 19:34:56 +01:00
|
|
|
|
[Route("api/pdfestimate"), Authorize]
|
|
|
|
|
|
public class PdfEstimateController : Controller
|
|
|
|
|
|
{
|
2016-11-09 14:03:57 +01:00
|
|
|
|
ApplicationDbContext dbContext;
|
|
|
|
|
|
|
|
|
|
|
|
public PdfEstimateController(
|
|
|
|
|
|
IViewComponentDescriptorCollectionProvider provider,
|
|
|
|
|
|
IViewComponentSelector selector,
|
|
|
|
|
|
IViewComponentInvokerFactory factory,
|
|
|
|
|
|
ApplicationDbContext context)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
dbContext = context;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("get/{id}", Name = "Get"), Authorize]
|
2016-11-07 19:34:56 +01:00
|
|
|
|
public IActionResult Get(long id)
|
|
|
|
|
|
{
|
|
|
|
|
|
var filename = $"estimate-{id}.pdf";
|
2016-11-09 14:03:57 +01:00
|
|
|
|
|
2016-11-07 19:34:56 +01:00
|
|
|
|
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,
|
|
|
|
|
|
};
|
2016-11-09 14:03:57 +01:00
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
|
|
|
|
|
Response.ContentType = "text/x-tex";
|
2016-11-30 11:01:22 +01:00
|
|
|
|
return ViewComponent("Estimate",new object[] { id, "LaTeX" });
|
2016-11-09 14:03:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-11-10 01:02:57 +01:00
|
|
|
|
[HttpPost("gen/{id}")]
|
2016-11-24 01:01:41 +01:00
|
|
|
|
public IActionResult GeneratePdf(long id)
|
2016-11-09 14:03:57 +01:00
|
|
|
|
{
|
2016-11-30 11:01:22 +01:00
|
|
|
|
return ViewComponent("Estimate",new object[] { id, "Pdf" } );
|
2016-11-07 19:34:56 +01:00
|
|
|
|
}
|
2016-12-01 17:42:34 +01:00
|
|
|
|
|
|
|
|
|
|
[HttpPost("prosign/{id}")]
|
|
|
|
|
|
public IActionResult ProSign(long id)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Request.Form.Files.Count!=1)
|
|
|
|
|
|
return new BadRequestResult();
|
|
|
|
|
|
return Ok (User.ReceiveProSignature(id,Request.Form.Files[0]));
|
|
|
|
|
|
}
|
2016-11-07 19:34:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|