tycg_carviolation_BE/Traffic.Api/Controllers/PoliceStationController.cs

146 lines
4.3 KiB
C#

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/group")]
[Authorize]
[ApiController]
public class PoliceStationController : ControllerBase
{
private readonly IPoliceStationService _service;
public PoliceStationController(IPoliceStationService service)
{
_service = service;
}
/// <summary>
/// 取得 PoliceStation 列表
/// </summary>
/// <param name="searchModel"></param>
/// <returns></returns>
[HttpGet("GetGroupDataList")]
public IActionResult GetPoliceStations([FromQuery] SearchModelViewModel searchModel)
{
try
{
var result = new Response();
var model = new SearchModel
{
Term = searchModel.Term,
Page = Convert.ToInt32(string.IsNullOrWhiteSpace(searchModel.Page) ? "1" : searchModel.Page),
PageSize = Convert.ToInt32(string.IsNullOrWhiteSpace(searchModel.PageSize) ? "1" : searchModel.PageSize),
IsAsc = searchModel.IsAsc == "true" ? true : false,
Order = string.IsNullOrWhiteSpace(searchModel.Order) ? "id" : searchModel.Order,
};
result.Result = _service.GetPoliceStations(model);
return Ok(result);
}
catch (Exception)
{
return BadRequest();
}
}
/// <summary>
/// 取得 PoliceStation by id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("GetGroupData/{id}")]
public IActionResult GetPoliceStation(int id)
{
try
{
var result = new Response();
result.Result = _service.GetPoliceStationById(id);
return Ok(result);
}
catch (Exception)
{
return BadRequest();
}
}
[HttpGet("GetGroupNameList")]
public IActionResult GetGroupNameList()
{
try
{
var result = new Response();
result.Result = _service.GetGroupNameList();
return Ok(result);
}
catch (Exception)
{
return BadRequest();
}
}
/// <summary>
/// 新增 PoliceStation
/// </summary>
/// <param name="vm"></param>
/// <returns></returns>
[HttpPost("PostGroupData")]
public IActionResult InsertPoliceStation(PoliceStationViewModel vm)
{
try
{
var result = _service.InsertPoliceStation(vm);
return result.Success ? Ok(result) : BadRequest(result);
}
catch (Exception)
{
return BadRequest();
}
}
/// <summary>
/// 修改 PoliceStation
/// </summary>
/// <param name="vm"></param>
/// <returns></returns>
[HttpPut("PutGroupData")]
public IActionResult UpdatePoliceStation(PoliceStationViewModel vm)
{
try
{
var result = _service.UpdatPoliceStation(vm);
return result.Success ? Ok(result) : BadRequest(result);
}
catch (Exception)
{
return BadRequest();
}
}
/// <summary>
/// 刪除 PoliceStation
/// </summary>
/// <param name="id">PoliceStation 的流水號</param>
/// <returns></returns>
[HttpDelete("DeleteGroupData/{id}")]
public IActionResult DeletePoliceStation(int id)
{
try
{
var result = _service.DeletePoliceStation(id);
return result.Success ? Ok(result) : BadRequest(result);
}
catch (Exception)
{
return BadRequest();
}
}
}
}