ASP.NET / ASP.NET Helpdesk System Using jQuery and Bootstrap / CasestudyWebsite / Controllers / ProblemController.cs
ProblemController.cs
Raw
/*
 * Description: The ProblemController class is a controller for handling requests related to problems.
 *              It provides methods for performing operations on problem data, such as retrieving 
 *              a problem by description and getting all problems. The controller uses the
 *              ProblemViewModel class to retrieve the data for problems.
 */
using HelpdeskViewModels;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using System.Reflection;
namespace CasestudyWebsite.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ProblemController : ControllerBase
    {
        [HttpGet("{description}")]
        public async Task<IActionResult> GetByDescription(String description)
        {
            try
            {
                ProblemViewModel viewmodel = new() { Description = description };
                await viewmodel.GetByDescription();
                return Ok(viewmodel);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Problem in " + GetType().Name + " " +
                MethodBase.GetCurrentMethod()!.Name + " " + ex.Message);
                return StatusCode(StatusCodes.Status500InternalServerError); // something went wrong
            }
        }
        [HttpGet]
        public async Task<IActionResult> GetAll()
        {
            try
            {
                ProblemViewModel viewmodel = new();
                List<ProblemViewModel> allProblems = await viewmodel.GetAll();
                return Ok(allProblems);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Problem in " + GetType().Name + " " +
                MethodBase.GetCurrentMethod()!.Name + " " + ex.Message);
                return StatusCode(StatusCodes.Status500InternalServerError); // something went wrong
            }
        }
    }
}