ASP.NET / ASP.NET Helpdesk System Using jQuery and Bootstrap / CasestudyWebsite / Controllers / DepartmentController.cs
DepartmentController.cs
Raw
/*
 * Description: The DepartmentController class is a controller for handling requests
 *              related to departments. It provides a method for retrieving all departments.
 *              The controller uses the DepartmentViewModel class to manage the data for the departments,
 *              and it returns the list of departments in the response to the request.
 */
using HelpdeskViewModels;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using System.Reflection;
namespace CasestudyWebsite.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class DepartmentController : ControllerBase
    {
        [HttpGet]
        public async Task<IActionResult> GetAll()
        {
            try
            {
                DepartmentViewModel viewmodel = new();
                List<DepartmentViewModel> allDepartments = await viewmodel.GetAll();
                return Ok(allDepartments);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Problem in " + GetType().Name + " " +
                MethodBase.GetCurrentMethod()!.Name + " " + ex.Message);
                return StatusCode(StatusCodes.Status500InternalServerError); // something went wrong
            }
        }
    }
}