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; using System.Net; namespace TodoAPI2.Controllers { //[Authorize] [Produces("application/json")] [Route("api/eva_create_evaluation_detail_firstdoc")] public class eva_create_evaluation_detail_firstdocController : BaseController { #region Private Variables private ILogger _logger; private Ieva_create_evaluation_detail_firstdocService _repository; private Iexternal_employeeService emp; private IConfiguration Configuration { get; set; } #endregion #region Properties #endregion /// /// Default constructure for dependency injection /// /// /// /// /// public eva_create_evaluation_detail_firstdocController(ILogger logger, Ieva_create_evaluation_detail_firstdocService 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_firstdocWithSelectionViewModel), 200)] [ProducesResponseType(400)] [ProducesResponseType(500)] //[ValidateAntiForgeryToken] public IActionResult Get(int 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)); var result = _repository.GetWithSelection(id, e.id); return Ok(result); } else { return Unauthorized(); } } catch (Exception ex) { _logger.LogCritical($"Exception in IActionResult Get.", ex); return StatusCode(500, $"{ex.Message}"); } } /// /// Get Blank Item /// /// /// /// Return a blank item /// Returns the item /// Error Occurred [HttpGet("GetBlankItem")] [ProducesResponseType(typeof(eva_create_evaluation_detail_firstdocWithSelectionViewModel), 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, $"{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, $"{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_firstdocSearchModel 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, $"{ex.Message}"); } } } }