using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using ODCWeb.DataAccess.Repository.IRepository; using ODCWeb.Models; namespace ODCWeb.Areas.Staff.Controllers {/////////////////////////////////////// DISCONTINUED [Area("Staff")] [Authorize(Roles = "Admin")] public class BQSectionController : Controller { private readonly IUnitOfWork _unitOfWork; public BQSectionController(IUnitOfWork unitOfWork) { _unitOfWork = unitOfWork; } [HttpPost] [ValidateAntiForgeryToken] public IActionResult AddSection(int templateId, string sectionName) { if (string.IsNullOrEmpty(sectionName)) { TempData["error"] = "Section name is required"; return RedirectToAction("View", "BQTemplate", new { id = templateId }); } var section = new BQSection { BQTemplateId = templateId, Name = sectionName, OrderIndex = _unitOfWork.BQSection.GetAll() .Where(s => s.BQTemplateId == templateId) .Count() + 1 }; _unitOfWork.BQSection.Add(section); _unitOfWork.save(); TempData["success"] = "Section added successfully"; return RedirectToAction("View", "BQTemplate", new { id = templateId }); } [HttpPost] [ValidateAntiForgeryToken] public IActionResult Delete(int id) { var section = _unitOfWork.BQSection.Get(s => s.BQSectionId == id); if (section == null) return NotFound(); var templateId = section.BQTemplateId; _unitOfWork.BQSection.Remove(section); _unitOfWork.save(); var remainingSections = _unitOfWork.BQSection.GetAll() .Where(s => s.BQTemplateId == templateId) .OrderBy(s => s.OrderIndex) .ToList(); for (int i = 0; i < remainingSections.Count; i++) { remainingSections[i].OrderIndex = i + 1; _unitOfWork.BQSection.update(remainingSections[i]); } _unitOfWork.save(); TempData["success"] = "Section deleted successfully"; return RedirectToAction("View", "BQTemplate", new { id = templateId }); } } }