tycg_carviolation_BE/Traffic.Api/Controllers/CompanyInformationController.cs

163 lines
4.6 KiB
C#

using LiangLiSystem.Services.Helpers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using Traffic.Data.ViewModels;
using Traffic.Service.Interfaces;
namespace Traffic.Api.Controllers
{
/// <summary>
/// 廠商資料設定
/// </summary>
[Route("api/companyInformation")]
[Authorize]
[ApiController]
public class CompanyInformationController : ControllerBase
{
private readonly ICompanyInformationService _service;
public CompanyInformationController(ICompanyInformationService service)
{
_service = service;
}
/// <summary>
/// 取得廠商資料設定列表
/// </summary>
[AllowAnonymous]
[HttpGet("all")]
public IActionResult GetCompanyInformations()
{
try
{
var result = new Response();
result.Result = _service.GetCompanyInformations();
return Ok(result);
}
catch (Exception)
{
return BadRequest();
}
}
/// <summary>
/// 取得廠商資料設定列表 (Email 空白的不顯示)
/// </summary>
[AllowAnonymous]
[HttpGet("all/emailNotNull")]
public IActionResult GetCompanyInformationsEmailNotNull()
{
try
{
var result = new Response();
result.Result = _service.GetCompanyInformationsEmailNotNull();
return Ok(result);
}
catch (Exception)
{
return BadRequest();
}
}
/// <summary>
/// 取得廠商資料設定列表
/// </summary>
/// <param name="searchModel"></param>
/// <returns></returns>
[HttpGet("")]
public IActionResult GetCompanyInformations([FromQuery] SearchModelViewModel searchModel)
{
try
{
var result = new Response();
var model = Util.GetSearchModel(searchModel);
result.Result = _service.GetCompanyInformations(model);
return Ok(result);
}
catch (Exception)
{
return BadRequest();
}
}
/// <summary>
/// 取得廠商資料 by id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}")]
public IActionResult GetCompanyInformation(int id)
{
try
{
var result = new Response();
result.Result = _service.GetCompanyInformationById(id);
return Ok(result);
}
catch (Exception)
{
return BadRequest();
}
}
/// <summary>
/// 新增廠商資料設定
/// </summary>
/// <param name="vm"></param>
/// <returns></returns>
[HttpPost("")]
public IActionResult InsertCompanyInformation(CompanyInformationViewModel vm)
{
try
{
var result = _service.InsertCompanyInformation(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 UpdateCompanyInformation(int id, CompanyInformationViewModel vm)
{
try
{
var result = _service.UpdatCompanyInformation(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 DeleteCompanyInformation(int id)
{
try
{
var result = _service.DeleteCompanyInformation(id);
return result.Success ? Ok(result) : BadRequest(result);
}
catch (Exception)
{
return BadRequest();
}
}
}
}