Files
hrm_eva/ApiControllers/eva_create_evaluation_detail_agreementControllers.cs

189 lines
6.8 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_agreement")]
public class eva_create_evaluation_detail_agreementController : BaseController
{
#region Private Variables
private ILogger<eva_create_evaluation_detail_agreementController> _logger;
private Ieva_create_evaluation_detail_agreementService _repository;
private Iexternal_employeeService emp;
private IConfiguration Configuration { get; set; }
#endregion
#region Properties
#endregion
/// <summary>
/// Default constructure for dependency injection
/// </summary>
/// <param name="repository"></param>
/// <param name="configuration"></param>
/// <param name="inemp"></param>
/// <param name="logger"></param>
public eva_create_evaluation_detail_agreementController(ILogger<eva_create_evaluation_detail_agreementController> logger,
Ieva_create_evaluation_detail_agreementService repository, IConfiguration configuration,
Iexternal_employeeService inemp)
{
_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}")]
[ProducesResponseType(typeof(eva_create_evaluation_detail_agreementWithSelectionViewModel), 200)]
[ProducesResponseType(400)]
[ProducesResponseType(500)]
//[ValidateAntiForgeryToken]
public IActionResult Get(int id)
{
try
{
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
var result = _repository.GetWithSelection(id);
return Ok(result);
}
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_agreementWithSelectionViewModel), 200)]
[ProducesResponseType(400)]
[ProducesResponseType(500)]
//[ValidateAntiForgeryToken]
public IActionResult GetBlankItem()
{
try
{
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
var result = _repository.GetBlankItem();
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_agreementViewModel>), 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));
}
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_agreementViewModel>), 200)]
[ProducesResponseType(400)]
[ProducesResponseType(500)]
//[ValidateAntiForgeryToken]
public IActionResult GetListBySearch(eva_create_evaluation_detail_agreementSearchModel 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));
}
else
{
return Unauthorized();
}
}
catch (Exception ex)
{
_logger.LogCritical($"Exception in IActionResult GetListBySearch.", ex);
return StatusCode(500, $"Exception in IActionResult GetListBySearch. {ex.Message}");
}
}
}
}