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 { /// /// 廠商資料設定 /// [Route("api/companyInformation")] [Authorize] [ApiController] public class CompanyInformationController : ControllerBase { private readonly ICompanyInformationService _service; public CompanyInformationController(ICompanyInformationService service) { _service = service; } /// /// 取得廠商資料設定列表 /// [AllowAnonymous] [HttpGet("all")] public IActionResult GetCompanyInformations() { try { var result = new Response(); result.Result = _service.GetCompanyInformations(); return Ok(result); } catch (Exception) { return BadRequest(); } } /// /// 取得廠商資料設定列表 (Email 空白的不顯示) /// [AllowAnonymous] [HttpGet("all/emailNotNull")] public IActionResult GetCompanyInformationsEmailNotNull() { try { var result = new Response(); result.Result = _service.GetCompanyInformationsEmailNotNull(); return Ok(result); } catch (Exception) { return BadRequest(); } } /// /// 取得廠商資料設定列表 /// /// /// [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(); } } /// /// 取得廠商資料 by id /// /// /// [HttpGet("{id}")] public IActionResult GetCompanyInformation(int id) { try { var result = new Response(); result.Result = _service.GetCompanyInformationById(id); return Ok(result); } catch (Exception) { return BadRequest(); } } /// /// 新增廠商資料設定 /// /// /// [HttpPost("")] public IActionResult InsertCompanyInformation(CompanyInformationViewModel vm) { try { var result = _service.InsertCompanyInformation(vm); return result.Success ? Ok(result) : BadRequest(result); } catch (Exception) { return BadRequest(); } } /// /// 修改廠商資料設定 /// /// 廠商資料的流水號 /// /// [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(); } } /// /// 刪除廠商資料 /// /// 廠商資料的流水號 /// [HttpDelete("{id}")] public IActionResult DeleteCompanyInformation(int id) { try { var result = _service.DeleteCompanyInformation(id); return result.Success ? Ok(result) : BadRequest(result); } catch (Exception) { return BadRequest(); } } } }