Files
hrm_eva/ApiControllers/eva_create_evaluation_detail_processControllers.cs

201 lines
7.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Logging;
using TTSW.Controllers;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
using TodoAPI2.Models;
using System.Data;
using Microsoft.Extensions.Configuration;
using System.IO;
namespace TodoAPI2.Controllers
{
//[Authorize]
[Produces("application/json")]
[Route("api/eva_create_evaluation_detail_process")]
public class eva_create_evaluation_detail_processController : BaseController
{
#region Private Variables
private ILogger<eva_create_evaluation_detail_processController> _logger;
private Ieva_create_evaluation_detail_processService _repository;
private IConfiguration Configuration { get; set; }
private Iexternal_employeeService emp;
#endregion
#region Properties
#endregion
/// <summary>
/// Default constructure for dependency injection
/// </summary>
/// <param name="repository"></param>
/// <param name="configuration"></param>
/// <param name="logger"></param>
/// <param name="inemp"></param>
public eva_create_evaluation_detail_processController(ILogger<eva_create_evaluation_detail_processController> logger,
Iexternal_employeeService inemp,
Ieva_create_evaluation_detail_processService repository, IConfiguration configuration)
{
_logger = logger;
_repository = repository;
Configuration = configuration;
emp = inemp;
}
/// <summary>
/// Get specific item by id
/// </summary>
/// <remarks>
/// </remarks>
/// <returns>Return Get specific item by id</returns>
/// <response code="200">Returns the item</response>
/// <response code="500">Error Occurred</response>
[HttpGet("{id}/{path}")]
[ProducesResponseType(typeof(eva_create_evaluation_detail_processWithSelectionViewModel), 200)]
[ProducesResponseType(400)]
[ProducesResponseType(500)]
//[ValidateAntiForgeryToken]
public IActionResult Get(int id, string path)
{
try
{
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
if (!string.IsNullOrEmpty(HttpContext.Request.Cookies["user_id"]))
{
var loginid = Convert.ToInt32(HttpContext.Request.Cookies["user_id"]);
var e = emp.GetEmployeeForLogin(Convert.ToInt32(loginid));
var result = _repository.GetWithSelection(id, e.id, path);
return Ok(result);
}
else
{
return Unauthorized();
}
}
catch (Exception ex)
{
_logger.LogCritical($"Exception in IActionResult Get.", ex);
return StatusCode(500, $"Exception in IActionResult Get. {ex.Message}");
}
}
/// <summary>
/// Get Blank Item
/// </summary>
/// <remarks>
/// </remarks>
/// <returns>Return a blank item</returns>
/// <response code="200">Returns the item</response>
/// <response code="500">Error Occurred</response>
[HttpGet("GetBlankItem")]
[ProducesResponseType(typeof(eva_create_evaluation_detail_processWithSelectionViewModel), 200)]
[ProducesResponseType(400)]
[ProducesResponseType(500)]
//[ValidateAntiForgeryToken]
public IActionResult GetBlankItem()
{
try
{
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
var loginid = Convert.ToInt32(HttpContext.Request.Cookies["user_id"]);
var e = emp.GetEmployeeForLogin(Convert.ToInt32(loginid));
var result = _repository.GetBlankItemWithEmp(e.id);
return Ok(result);
}
catch (Exception ex)
{
_logger.LogCritical($"Exception in IActionResult GetBlankItem.", ex);
return StatusCode(500, $"Exception in IActionResult GetBlankItem. {ex.Message}");
}
}
/// <summary>
/// Get list items by create_evaluation_id
/// </summary>
/// <remarks>
/// </remarks>
/// <returns>Return list of items by specifced keyword</returns>
/// <response code="200">Returns the item</response>
/// <response code="500">Error Occurred</response>
[HttpGet("")]
[ProducesResponseType(typeof(List<eva_create_evaluation_detail_processViewModel>), 200)]
[ProducesResponseType(400)]
[ProducesResponseType(500)]
//[ValidateAntiForgeryToken]
public IActionResult GetList(int? create_evaluation_id)
{
try
{
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
if (!string.IsNullOrEmpty(HttpContext.Request.Cookies["user_id"]))
{
var loginid = Convert.ToInt32(HttpContext.Request.Cookies["user_id"]);
var e = emp.GetEmployeeForLogin(Convert.ToInt32(loginid));
return Ok(_repository.GetListBycreate_evaluation_id(create_evaluation_id, e.id, HttpContext.Request.Path));
}
else
{
return Unauthorized();
}
}
catch (Exception ex)
{
_logger.LogCritical($"Exception in IActionResult GetList.", ex);
return StatusCode(500, $"Exception in IActionResult GetList. {ex.Message}");
}
}
/// <summary>
/// Get list items by search
/// </summary>
/// <remarks>
/// </remarks>
/// <returns>Return list of items by specifced keyword</returns>
/// <response code="200">Returns the item</response>
/// <response code="500">Error Occurred</response>
[HttpGet("GetListBySearch")]
[ProducesResponseType(typeof(List<eva_create_evaluation_detail_processViewModel>), 200)]
[ProducesResponseType(400)]
[ProducesResponseType(500)]
//[ValidateAntiForgeryToken]
public IActionResult GetListBySearch(eva_create_evaluation_detail_processSearchModel model)
{
try
{
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
if (!string.IsNullOrEmpty(HttpContext.Request.Cookies["user_id"]))
{
var loginid = Convert.ToInt32(HttpContext.Request.Cookies["user_id"]);
var e = emp.GetEmployeeForLogin(Convert.ToInt32(loginid));
return Ok(_repository.GetListBySearch(model, e.id, model.path));
}
else
{
return Unauthorized();
}
}
catch (Exception ex)
{
_logger.LogCritical($"Exception in IActionResult GetListBySearch.", ex);
return StatusCode(500, $"Exception in IActionResult GetListBySearch. {ex.Message}");
}
}
}
}