tycg_carviolation_BE/Traffic.Api/Controllers/NotPunishController.cs

148 lines
4.0 KiB
C#

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
{
/// <summary>
/// 不開單原因設定
/// </summary>
[Route("api/notPunish")]
[Authorize]
[ApiController]
public class NotPunishController : ControllerBase
{
private readonly INotPunishService _service;
public NotPunishController(INotPunishService service)
{
_service = service;
}
/// <summary>
/// 取得所有不開單原因
/// </summary>
/// <returns></returns>
[HttpGet("all")]
public IActionResult GetNotPunishs()
{
try
{
var result = new Response();
result.Result = _service.GetNotPunishs();
return Ok(result);
}
catch (Exception)
{
return BadRequest();
}
}
/// <summary>
/// 取得不開單原因列表by條件
/// </summary>
/// <param name="searchModel"></param>
/// <returns></returns>
[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();
}
}
/// <summary>
/// 取得不開單原因 by id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}")]
public IActionResult GetNotPunish(int id)
{
try
{
var result = new Response();
result.Result = _service.GetNotPunishById(id);
return Ok(result);
}
catch (Exception)
{
return BadRequest();
}
}
/// <summary>
/// 新增不開單原因
/// </summary>
/// <param name="vm"></param>
/// <returns></returns>
[HttpPost("")]
public IActionResult InsertNotPunish(NotPunishViewModel vm)
{
try
{
var result = _service.InsertNotPunish(vm);
return result.Success ? Ok(result) : BadRequest(result);
}
catch (Exception)
{
return BadRequest();
}
}
/// <summary>
/// 修改不開單原因
/// </summary>
/// <param name="id">不開單原因的流水號</param>
/// <param name="vm"></param>
/// <returns></returns>
[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();
}
}
/// <summary>
/// 刪除不開單原因
/// </summary>
/// <param name="id">不開單原因的流水號</param>
/// <returns></returns>
[HttpDelete("{id}")]
public IActionResult DeleteNotPunish(int id)
{
try
{
var result = _service.DeleteNotPunish(id);
return result.Success ? Ok(result) : BadRequest(result);
}
catch (Exception)
{
return BadRequest();
}
}
}
}