using LiangLiSystem.Services.Helpers; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Traffic.Data.ViewModels; using Traffic.Service.Interfaces; namespace Traffic.Api.Controllers { /// /// 不開單原因設定 /// [Route("api/notPunish")] [Authorize] [ApiController] public class NotPunishController : ControllerBase { private readonly INotPunishService _service; public NotPunishController(INotPunishService service) { _service = service; } /// /// 取得所有不開單原因 /// /// [HttpGet("all")] public IActionResult GetNotPunishs() { try { var result = new Response(); result.Result = _service.GetNotPunishs(); return Ok(result); } catch (Exception) { return BadRequest(); } } /// /// 取得不開單原因列表by條件 /// /// /// [HttpGet("")] public IActionResult GetNotPunishs([FromQuery] SearchModelViewModel searchModel) { try { var result = new Response(); var model = Util.GetSearchModel(searchModel); result.Result = _service.GetNotPunishs(model); return Ok(result); } catch (Exception) { return BadRequest(); } } /// /// 取得不開單原因 by id /// /// /// [HttpGet("{id}")] public IActionResult GetNotPunish(int id) { try { var result = new Response(); result.Result = _service.GetNotPunishById(id); return Ok(result); } catch (Exception) { return BadRequest(); } } /// /// 新增不開單原因 /// /// /// [HttpPost("")] public IActionResult InsertNotPunish(NotPunishViewModel vm) { try { var result = _service.InsertNotPunish(vm); return result.Success ? Ok(result) : BadRequest(result); } catch (Exception) { return BadRequest(); } } /// /// 修改不開單原因 /// /// 不開單原因的流水號 /// /// [HttpPut("{id}")] public IActionResult UpdateNotPunish(int id, NotPunishViewModel vm) { try { var result = _service.UpdatNotPunish(id, vm); return result.Success ? Ok(result) : BadRequest(result); } catch (Exception) { return BadRequest(); } } /// /// 刪除不開單原因 /// /// 不開單原因的流水號 /// [HttpDelete("{id}")] public IActionResult DeleteNotPunish(int id) { try { var result = _service.DeleteNotPunish(id); return result.Success ? Ok(result) : BadRequest(result); } catch (Exception) { return BadRequest(); } } } }