0
I’m having a hard time doing an operation. I have a console application that opens a PDF. This console takes the name of Servico.exe, although it has the service name, it is an exe and not a service. Opening the PDF is ok. I created a MVC5 project. I used the ADO .Net Entity Framework
which led Morrison to say that this was a bad approach, but since it is only a POC I went ahead and then I see another approach. My difficulty is opening the program that calls the report from within the controller or view. Below is the controller that should do this. This controller was generated by the VS2013 Wizard. I cannot mount an action or method that does this.
public class AppealReportController : Controller
{
private ReportDBContext db = new ReportDBContext();
// GET: AppealReport
public async Task<ActionResult> Index()
{
var pOC_SOLIC_RELATORIO = db.POC_SOLIC_RELATORIO.Include(p => p.POC_RELATORIO);
return View(await pOC_SOLIC_RELATORIO.ToListAsync());
}
// GET: AppealReport/Details/5
public async Task<ActionResult> Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
POC_SOLIC_RELATORIO pOC_SOLIC_RELATORIO = await db.POC_SOLIC_RELATORIO.FindAsync(id);
if (pOC_SOLIC_RELATORIO == null)
{
return HttpNotFound();
}
return View(pOC_SOLIC_RELATORIO);
}
// GET: AppealReport/Create
public ActionResult Create()
{
ViewBag.ID_RELATORIO = new SelectList(db.POC_RELATORIO, "ID_RELATORIO", "NM_RELATORIO");
return View();
}
// POST: AppealReport/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create([Bind(Include = "ID_SOLIC_RELATORIO,ID_RELATORIO,ID_USUARIO,DT_SOLICITACAO,DT_AGENDAMENTO,DT_GERACAO,BL_RELATORIO")] POC_SOLIC_RELATORIO pOC_SOLIC_RELATORIO)
{
if (ModelState.IsValid)
{
db.POC_SOLIC_RELATORIO.Add(pOC_SOLIC_RELATORIO);
await db.SaveChangesAsync();
return RedirectToAction("Index");
}
ViewBag.ID_RELATORIO = new SelectList(db.POC_RELATORIO, "ID_RELATORIO", "NM_RELATORIO", pOC_SOLIC_RELATORIO.ID_RELATORIO);
return View(pOC_SOLIC_RELATORIO);
}
// GET: AppealReport/Edit/5
public async Task<ActionResult> Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
POC_SOLIC_RELATORIO pOC_SOLIC_RELATORIO = await db.POC_SOLIC_RELATORIO.FindAsync(id);
if (pOC_SOLIC_RELATORIO == null)
{
return HttpNotFound();
}
ViewBag.ID_RELATORIO = new SelectList(db.POC_RELATORIO, "ID_RELATORIO", "NM_RELATORIO", pOC_SOLIC_RELATORIO.ID_RELATORIO);
return View(pOC_SOLIC_RELATORIO);
}
// POST: AppealReport/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Edit([Bind(Include = "ID_SOLIC_RELATORIO,ID_RELATORIO,ID_USUARIO,DT_SOLICITACAO,DT_AGENDAMENTO,DT_GERACAO,BL_RELATORIO")] POC_SOLIC_RELATORIO pOC_SOLIC_RELATORIO)
{
if (ModelState.IsValid)
{
db.Entry(pOC_SOLIC_RELATORIO).State = EntityState.Modified;
await db.SaveChangesAsync();
return RedirectToAction("Index");
}
ViewBag.ID_RELATORIO = new SelectList(db.POC_RELATORIO, "ID_RELATORIO", "NM_RELATORIO", pOC_SOLIC_RELATORIO.ID_RELATORIO);
return View(pOC_SOLIC_RELATORIO);
}
// GET: AppealReport/Delete/5
public async Task<ActionResult> Delete(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
POC_SOLIC_RELATORIO pOC_SOLIC_RELATORIO = await db.POC_SOLIC_RELATORIO.FindAsync(id);
if (pOC_SOLIC_RELATORIO == null)
{
return HttpNotFound();
}
return View(pOC_SOLIC_RELATORIO);
}
// POST: AppealReport/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<ActionResult> DeleteConfirmed(int id)
{
POC_SOLIC_RELATORIO pOC_SOLIC_RELATORIO = await db.POC_SOLIC_RELATORIO.FindAsync(id);
db.POC_SOLIC_RELATORIO.Remove(pOC_SOLIC_RELATORIO);
await db.SaveChangesAsync();
return RedirectToAction("Index");
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
I tried that and it didn’t work:
public void openApplication()
{
System.Diagnostics.Process.Start("C:\\Projetos\\Servicos\\bin\\Servicos.exe");
}
And I made that call:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create([Bind(Include = "ID_SOLIC_RELATORIO,ID_RELATORIO,ID_USUARIO,DT_SOLICITACAO,DT_AGENDAMENTO,DT_GERACAO,BL_RELATORIO")] POC_SOLIC_RELATORIO pOC_SOLIC_RELATORIO)
{
if (ModelState.IsValid)
{
db.POC_SOLIC_RELATORIO.Add(pOC_SOLIC_RELATORIO);
openApplication();//Aqui não funfa
await db.SaveChangesAsync();
return RedirectToAction("Index");
}
ViewBag.ID_RELATORIO = new SelectList(db.POC_RELATORIO, "ID_RELATORIO", "NM_RELATORIO", pOC_SOLIC_RELATORIO.ID_RELATORIO);
return View(pOC_SOLIC_RELATORIO);
}
As the question became broad, I made an edit and changed the title and content only for the opening of an external executable program on mvc.
– pnet
There is a big problem of approach there. An ASP.NET MVC application is a web application, so it is not made to open executables, even if they are local. A classic of this is the package Rotating, which generates a PDF by calling an executable and does not work in Windows Azure web instances, for example. Anyway, I’ll answer your question.
– Leonel Sanches da Silva