laatzen/LaaProductionWeb/LaaProductionWeb/Controllers/ApprovalsController.cs
2023-05-17 14:57:05 +02:00

49 lines
1.4 KiB
C#

namespace LaaProductionWeb.Controllers
{
using LaaProductionWeb.App_Infrastructure;
using LaaProductionWeb.Services.Interfaces;
using LaaProductionWeb.Services.Models;
using System;
using System.Web.Mvc;
[AllowedRoles(UserRoles.WEB_ProdApproval)]
public class ApprovalsController : Controller
{
private readonly IApprovalsService approvals;
public ApprovalsController()
=> this.approvals = ServiceProvider.Current.GetService<IApprovalsService>();
[HttpGet]
public ActionResult Add()
=> this.View(new ProductionApproval
{
ApproverName = this.User.ClaimName(),
ApprovalDate = DateTime.Now
});
[HttpPost]
public ActionResult Add(ProductionApproval approval)
{
if (this.ModelState.IsValid)
{
approval.ApprovalDate = DateTime.Now;
approval.ApproverName = this.User.ClaimName();
var addResult = this.approvals.Add(approval);
if (addResult)
{
this.TempData["Success"] = (string)addResult;
return this.RedirectToAction(nameof(this.Add));
}
this.TempData["Error"] = (string)addResult;
}
return this.View(approval);
}
}
}