namespace LaaProduction.Web.Controllers { using LaaProduction.Personalization; using LaaProduction.Web.App_Infrastructure; using LaaProduction.Services.Interfaces; using LaaProduction.Services.Models; using LaaProductionDI; using System.Web.Mvc; [AllowedRoles(EmployeesRoles.WEB_PuneProtokoll)] public class ProtocolController : Controller { public const string FilePDF = nameof(FilePDF); private readonly IProtocolService protocolService; public ProtocolController() => this.protocolService = LaaServiceProvider.GetService(); [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) { if (model.OrderId > 0 && model.ClientId > 0) { var files = this.Request.Files; if (files.Count > 0) { var file = files.Get(0); if (file.ContentType == "application/pdf") { var completed = this.protocolService.OrderCompleted(model.OrderId.Value); if (completed) { 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 könte nicht hochgeladen werden."; } } else { this.TempData[FilePDF] = $"Auftrag enthält nicht bestandene Prüfungen."; } } else { this.TempData[FilePDF] = $"Bitte, PDF Datei hochladen."; } } else { this.TempData[FilePDF] = "Kein PDF Datei wurde ausgewählt."; } } else { this.TempData[FilePDF] = $"Bitte Auftrag auswählen."; } return this.View(model); } [HttpGet] public ActionResult Document(OrderClientModel model) { model.FileContent = this.protocolService.FileContent(model.FileId); return this.View(model); } [HttpPost] 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); } } }