using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using ODCWeb.DataAccess.Repository.IRepository; using ODCWeb.Models; using ODCWeb.Models.ViewModels; namespace ODCWeb.Areas.Staff.Controllers {/////////////////////////////////////// DISCONTINUED [Area("Staff")] [Authorize(Roles = "Admin")] public class BQTemplateController : Controller { private readonly IUnitOfWork _unitOfWork; public BQTemplateController(IUnitOfWork unitOfWork) { _unitOfWork = unitOfWork; } public IActionResult Index() { var templates = _unitOfWork.BQTemplate.GetAll() .OrderByDescending(t => t.CreatedDate) .ToList(); return View(templates); } [HttpGet] public IActionResult Create() { return View(new BQTemplate()); } [HttpPost] [ValidateAntiForgeryToken] public IActionResult Create(BQTemplate template) { if (ModelState.IsValid) { template.CreatedDate = DateTime.Now; template.CreatedBy = User.Identity.Name; template.IsActive = true; _unitOfWork.BQTemplate.Add(template); _unitOfWork.save(); TempData["success"] = "BQ Template created successfully"; return RedirectToAction(nameof(Index)); } return View(template); } public IActionResult View(int? id) { if (id == null || id == 0) return NotFound(); var template = _unitOfWork.BQTemplate.Get(t => t.BQTemplateId == id); if (template == null) return NotFound(); var sections = _unitOfWork.BQSection.GetAll(includeProperties: "Items") .Where(s => s.BQTemplateId == id) .OrderBy(s => s.OrderIndex) .ToList(); var viewModel = new BQTemplateViewModel { Template = template, Sections = sections, TotalItems = sections.Sum(s => s.Items?.Count ?? 0) }; return View(viewModel); } [HttpPost] [ValidateAntiForgeryToken] public IActionResult ToggleStatus(int id) { var template = _unitOfWork.BQTemplate.Get(t => t.BQTemplateId == id); if (template == null) return NotFound(); template.IsActive = !template.IsActive; _unitOfWork.BQTemplate.update(template); _unitOfWork.save(); TempData["success"] = $"Template status updated to {(template.IsActive ? "active" : "inactive")}"; return RedirectToAction(nameof(Index)); } } }