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 _logger; private Ieva_create_evaluation_detail_agreementService _repository; private Iexternal_employeeService emp; private IConfiguration Configuration { get; set; } #endregion #region Properties #endregion /// /// Default constructure for dependency injection /// /// /// /// /// public eva_create_evaluation_detail_agreementController(ILogger logger, Ieva_create_evaluation_detail_agreementService repository, IConfiguration configuration, Iexternal_employeeService inemp) { _logger = logger; _repository = repository; Configuration = configuration; emp = inemp; } /// /// Get specific item by id /// /// /// /// Return Get specific item by id /// Returns the item /// Error Occurred [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}"); } } /// /// Get Blank Item /// /// /// /// Return a blank item /// Returns the item /// Error Occurred [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}"); } } /// /// Get list items by create_evaluation_id /// /// /// /// Return list of items by specifced keyword /// Returns the item /// Error Occurred [HttpGet("")] [ProducesResponseType(typeof(List), 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}"); } } /// /// Get list items by search /// /// /// /// Return list of items by specifced keyword /// Returns the item /// Error Occurred [HttpGet("GetListBySearch")] [ProducesResponseType(typeof(List), 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}"); } } } }