321 lines
12 KiB
C#
321 lines
12 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_summary2")]
|
|
public class eva_create_evaluation_detail_summary2Controller : BaseController
|
|
{
|
|
#region Private Variables
|
|
private ILogger<eva_create_evaluation_detail_summary2Controller> _logger;
|
|
private Ieva_create_evaluation_detail_summary2Service _repository;
|
|
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="logger"></param>
|
|
public eva_create_evaluation_detail_summary2Controller(ILogger<eva_create_evaluation_detail_summary2Controller> logger, Ieva_create_evaluation_detail_summary2Service repository, IConfiguration configuration)
|
|
{
|
|
_logger = logger;
|
|
_repository = repository;
|
|
Configuration = configuration;
|
|
}
|
|
|
|
/// <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_summary2WithSelectionViewModel), 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_summary2WithSelectionViewModel), 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_summary2ViewModel>), 200)]
|
|
[ProducesResponseType(400)]
|
|
[ProducesResponseType(500)]
|
|
//[ValidateAntiForgeryToken]
|
|
public IActionResult GetList(int? create_evaluation_id)
|
|
{
|
|
try
|
|
{
|
|
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
|
|
return Ok(_repository.GetListBycreate_evaluation_id(create_evaluation_id));
|
|
}
|
|
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_summary2ViewModel>), 200)]
|
|
[ProducesResponseType(400)]
|
|
[ProducesResponseType(500)]
|
|
//[ValidateAntiForgeryToken]
|
|
public IActionResult GetListBySearch(eva_create_evaluation_detail_summary2SearchModel model)
|
|
{
|
|
try
|
|
{
|
|
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
|
|
return Ok(_repository.GetListBySearch(model));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogCritical($"Exception in IActionResult GetListBySearch.", ex);
|
|
return StatusCode(500, $"Exception in IActionResult GetListBySearch. {ex.Message}");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Create new item
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// </remarks>
|
|
/// <param name="model"></param>
|
|
/// <returns>Response Result Message</returns>
|
|
/// <response code="200">Response Result Message</response>
|
|
/// <response code="400">If the model is invalid</response>
|
|
/// <response code="500">Error Occurred</response>
|
|
[HttpPost("")]
|
|
[ProducesResponseType(typeof(CommonResponseMessage), 200)]
|
|
[ProducesResponseType(400)]
|
|
[ProducesResponseType(500)]
|
|
//[ValidateAntiForgeryToken]
|
|
public IActionResult Insert([FromBody] eva_create_evaluation_detail_summary2InputModel model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
try
|
|
{
|
|
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
|
|
var result = _repository.Insert(model);
|
|
var message = new CommonResponseMessage();
|
|
message.code = "200";
|
|
message.message = $"เพิ่มข้อมูล เรียบร้อย";
|
|
message.data = result;
|
|
return Ok(message);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogCritical($"Exception while insert.", ex);
|
|
return StatusCode(500, $"Exception while insert. {ex.Message}");
|
|
}
|
|
}
|
|
|
|
return BadRequest(ModelState);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update item
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// </remarks>
|
|
/// <param name="id"></param>
|
|
/// <param name="model"></param>
|
|
/// <returns>Response Result Message</returns>
|
|
/// <response code="200">Response Result Message</response>
|
|
/// <response code="400">If the model is invalid</response>
|
|
/// <response code="500">Error Occurred</response>
|
|
[HttpPut("{id}")]
|
|
[ProducesResponseType(typeof(CommonResponseMessage), 200)]
|
|
[ProducesResponseType(400)]
|
|
[ProducesResponseType(500)]
|
|
//[ValidateAntiForgeryToken]
|
|
public IActionResult Update(int id, [FromBody] eva_create_evaluation_detail_summary2InputModel model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
try
|
|
{
|
|
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
|
|
var result = _repository.Update(id, model);
|
|
var message = new CommonResponseMessage();
|
|
message.code = "200";
|
|
message.message = $"แก้ไขข้อมูล เรียบร้อย";
|
|
message.data = result;
|
|
return Ok(message);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogCritical($"Exception while update {id.ToString()}.", ex);
|
|
return StatusCode(500, $"Exception while update {id.ToString()}. {ex.Message}");
|
|
}
|
|
}
|
|
|
|
return BadRequest(ModelState);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Delete item
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// </remarks>
|
|
/// <param name="id"></param>
|
|
/// <returns>Response Result Message</returns>
|
|
/// <response code="200">Response Result Message</response>
|
|
/// <response code="400">If the model is invalid</response>
|
|
/// <response code="500">Error Occurred</response>
|
|
[HttpDelete("{id}")]
|
|
[ProducesResponseType(typeof(CommonResponseMessage), 200)]
|
|
[ProducesResponseType(400)]
|
|
[ProducesResponseType(500)]
|
|
//[ValidateAntiForgeryToken]
|
|
public IActionResult Delete(int id)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
try
|
|
{
|
|
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
|
|
_repository.Delete(id);
|
|
var message = new CommonResponseMessage();
|
|
message.code = "200";
|
|
message.message = $"ลบข้อมูล เรียบร้อย";
|
|
message.data = null;
|
|
return Ok(message);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogCritical($"Exception while delete {id.ToString()}.", ex);
|
|
return StatusCode(500, $"ไม่สามารถลบข้อมูลได้ เพราะข้อมูลถูกใช้ในส่วนงานอื่น");
|
|
}
|
|
}
|
|
|
|
return BadRequest(ModelState);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update multiple item
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// </remarks>
|
|
/// <param name="model"></param>
|
|
/// <returns>Response Result Message</returns>
|
|
/// <response code="200">Response Result Message</response>
|
|
/// <response code="400">If the model is invalid</response>
|
|
/// <response code="500">Error Occurred</response>
|
|
[HttpPut("UpdateMultiple")]
|
|
[ProducesResponseType(typeof(CommonResponseMessage), 200)]
|
|
[ProducesResponseType(400)]
|
|
[ProducesResponseType(500)]
|
|
//[ValidateAntiForgeryToken]
|
|
public IActionResult UpdateMultiple([FromBody] List<eva_create_evaluation_detail_summary2InputModel> model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
try
|
|
{
|
|
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
|
|
string rowCount = _repository.UpdateMultiple(model);
|
|
var message = new CommonResponseMessage();
|
|
message.code = "200";
|
|
message.message = "ปรับปรุงข้อมูลเรียบร้อย จำนวน "+rowCount+" รายการ";
|
|
message.data = null;
|
|
return Ok(message);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogCritical($"Exception while UpdateMultiple.", ex);
|
|
return StatusCode(500, $"Exception while UpdateMultiple. {ex.Message}");
|
|
}
|
|
}
|
|
|
|
return BadRequest(ModelState);
|
|
}
|
|
|
|
|
|
}
|
|
}
|