143 lines
3.8 KiB
C#
143 lines
3.8 KiB
C#
using LiangLiSystem.Services.Helpers;
|
|
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/[controller]")]
|
|
[ApiController]
|
|
public class RepairController : ControllerBase
|
|
{
|
|
private readonly IRepairService _service;
|
|
|
|
public RepairController(IRepairService service)
|
|
{
|
|
_service = service;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取得所有線上報修
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("all")]
|
|
public IActionResult GetRepairs()
|
|
{
|
|
try
|
|
{
|
|
var result = new Response();
|
|
result.Result = _service.GetRepairs();
|
|
return Ok(result);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取得線上報修列表by條件
|
|
/// </summary>
|
|
/// <param name="searchModel"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("")]
|
|
public IActionResult GetRepairs([FromQuery] SearchModelViewModel searchModel)
|
|
{
|
|
try
|
|
{
|
|
var result = new Response();
|
|
var model = Util.GetSearchModel(searchModel);
|
|
result.Result = _service.GetRepairs(model);
|
|
return Ok(result);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取得線上報修by id
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("{id}")]
|
|
public IActionResult GetRepair(int id)
|
|
{
|
|
try
|
|
{
|
|
var result = new Response();
|
|
result.Result = _service.GetRepairById(id);
|
|
return Ok(result);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增線上報修
|
|
/// </summary>
|
|
/// <param name="vm"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("")]
|
|
public IActionResult InsertRepair(RepairViewModel vm)
|
|
{
|
|
try
|
|
{
|
|
var result = _service.InsertRepair(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 UpdateRepair(int id, RepairViewModel vm)
|
|
{
|
|
try
|
|
{
|
|
var result = _service.UpdatRepair(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 DeleteRepair(int id)
|
|
{
|
|
try
|
|
{
|
|
var result = _service.DeleteRepair(id);
|
|
return result.Success ? Ok(result) : BadRequest(result);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
}
|
|
}
|
|
}
|