117 lines
3.5 KiB
C#
117 lines
3.5 KiB
C#
namespace LaaProductionWeb.Controllers
|
|
{
|
|
using LaaProductionWeb.Services.Interfaces;
|
|
using LaaProductionWeb.Services.Models;
|
|
|
|
using System.Web.Mvc;
|
|
|
|
[Authorize]
|
|
// [AllowedRoles("Protocol")]
|
|
public class ProtocolController : Controller
|
|
{
|
|
public const string FilePDF = nameof(FilePDF);
|
|
|
|
private readonly IProtocolService protocolService;
|
|
|
|
public ProtocolController(IProtocolService protocolService)
|
|
=> this.protocolService = protocolService;
|
|
|
|
[HttpGet]
|
|
public ActionResult Index(int orderId = 0)
|
|
{
|
|
var orderClientModel = this.protocolService.FindOrder(orderId);
|
|
|
|
if (orderClientModel.FileId > 0)
|
|
{
|
|
return this.RedirectToAction(nameof(Document), orderClientModel);
|
|
}
|
|
|
|
return this.View(orderClientModel);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult Index(OrderClientModel model)
|
|
{
|
|
var files = this.Request.Files;
|
|
|
|
if (model.OrderId is null || model.OrderId <= 0)
|
|
{
|
|
this.TempData[FilePDF] = $"Bitte Auftrag auswählen.";
|
|
}
|
|
else if (files.Count > 0)
|
|
{
|
|
var file = this.Request.Files.Get(0);
|
|
|
|
if (file.ContentType == "application/pdf" && model.ClientId > 0 && model.OrderId > 0)
|
|
{
|
|
model.FileId = this.protocolService.SaveFile(file.InputStream, model.ClientId.Value, model.OrderId.Value);
|
|
|
|
if (model.FileId > 0)
|
|
{
|
|
return this.RedirectToAction(nameof(this.Document), model);
|
|
}
|
|
else
|
|
{
|
|
this.TempData[FilePDF] = $"Der PDF Datei wurde nicht hochgeladen.";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.TempData[FilePDF] = $"Bitte, PDF Datei hochladen.";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.TempData[FilePDF] = "Kein PDF Datei wurde ausgewählt.";
|
|
}
|
|
|
|
return this.View(model);
|
|
}
|
|
|
|
[HttpGet]
|
|
public ActionResult Document(OrderClientModel model)
|
|
{
|
|
model.FileContent = this.protocolService.FileContent(model.FileId);
|
|
|
|
return this.View(model);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult DeleteFile(int fileId, int orderId)
|
|
{
|
|
this.protocolService.DeleteFile(fileId);
|
|
|
|
return this.RedirectToAction(nameof(this.Index), new { orderId });
|
|
}
|
|
|
|
public ActionResult Clients(string search = null)
|
|
{
|
|
var clientsOrders = this.protocolService.FindOrdersByClient(search);
|
|
|
|
return this.PartialView(clientsOrders);
|
|
}
|
|
|
|
public ActionResult Orders(int search = 0)
|
|
{
|
|
var clientsOrders = this.protocolService.FindOrdersById(search);
|
|
|
|
return this.PartialView(clientsOrders);
|
|
}
|
|
|
|
public ActionResult Body(int orderId = 0)
|
|
{
|
|
var testStatus = this.protocolService.LoadTestStatus(orderId);
|
|
|
|
return this.PartialView(testStatus);
|
|
}
|
|
|
|
[HttpGet]
|
|
public ActionResult Print(int orderId = 0)
|
|
{
|
|
var orderClientModel = this.protocolService.FindOrder(orderId);
|
|
|
|
return this.View(orderClientModel);
|
|
}
|
|
}
|
|
} |