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;
}
///
/// 取得所有線上報修
///
///
[HttpGet("all")]
public IActionResult GetRepairs()
{
try
{
var result = new Response();
result.Result = _service.GetRepairs();
return Ok(result);
}
catch (Exception)
{
return BadRequest();
}
}
///
/// 取得線上報修列表by條件
///
///
///
[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();
}
}
///
/// 取得線上報修by id
///
///
///
[HttpGet("{id}")]
public IActionResult GetRepair(int id)
{
try
{
var result = new Response();
result.Result = _service.GetRepairById(id);
return Ok(result);
}
catch (Exception)
{
return BadRequest();
}
}
///
/// 新增線上報修
///
///
///
[HttpPost("")]
public IActionResult InsertRepair(RepairViewModel vm)
{
try
{
var result = _service.InsertRepair(vm);
return result.Success ? Ok(result) : BadRequest(result);
}
catch (Exception)
{
return BadRequest();
}
}
///
/// 修改線上報修
///
/// 線上報修的流水號
///
///
[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();
}
}
///
/// 刪除線上報修
///
/// 線上報修的流水號
///
[HttpDelete("{id}")]
public IActionResult DeleteRepair(int id)
{
try
{
var result = _service.DeleteRepair(id);
return result.Success ? Ok(result) : BadRequest(result);
}
catch (Exception)
{
return BadRequest();
}
}
}
}