211 lines
5.9 KiB
C#
211 lines
5.9 KiB
C#
using LiangLiSystem.Services.Helpers;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Security.Claims;
|
|
using System.Threading.Tasks;
|
|
using Traffic.Data.ViewModels;
|
|
using Traffic.Service.Interfaces;
|
|
|
|
namespace Traffic.Api.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 行政區管理
|
|
/// </summary>
|
|
[Route("api/siteInformation")]
|
|
[Authorize]
|
|
[ApiController]
|
|
public class SiteInformationController : ControllerBase
|
|
{
|
|
private readonly ISiteInformationService _service;
|
|
|
|
public SiteInformationController(ISiteInformationService service)
|
|
{
|
|
_service = service;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取得所有行政區列表 by 員警
|
|
/// </summary>
|
|
[HttpGet("user")]
|
|
public IActionResult GetSiteInformationsByUser()
|
|
{
|
|
try
|
|
{
|
|
var userIdentity = (ClaimsIdentity)User.Identity;
|
|
var userId = new ParserForUserFromClaim(userIdentity).GetUserId();
|
|
|
|
var result = new Response();
|
|
result.Result = _service.GetSiteInformationsByUser(userId);
|
|
return Ok(result);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取得所有行政區列表
|
|
/// </summary>
|
|
[AllowAnonymous]
|
|
[HttpGet("emailNoNull")]
|
|
public IActionResult GetSiteInformationsEmailNoNull()
|
|
{
|
|
try
|
|
{
|
|
var result = new Response();
|
|
result.Result = _service.GetSiteInformations().Where(i => !string.IsNullOrWhiteSpace(i.CompanyEmail));
|
|
return Ok(result);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取得所有行政區列表
|
|
/// </summary>
|
|
[AllowAnonymous]
|
|
[HttpGet("all")]
|
|
public IActionResult GetSiteInformations()
|
|
{
|
|
try
|
|
{
|
|
var result = new Response();
|
|
result.Result = _service.GetSiteInformations();
|
|
return Ok(result);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取得行政區列表 by EventType
|
|
/// </summary>
|
|
/// <param name="eventTypes"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("eventType")]
|
|
public IActionResult GetSiteInformationsByEventTypes(List<string> eventTypes)
|
|
{
|
|
try
|
|
{
|
|
var result = new Response
|
|
{
|
|
Result = _service.GetSiteInformationsByEventTypes(eventTypes)
|
|
};
|
|
return Ok(result);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取得行政區列表 by 條件
|
|
/// </summary>
|
|
/// <param name="searchModel"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("")]
|
|
public IActionResult GetSiteInformations([FromQuery] SearchModelViewModel searchModel)
|
|
{
|
|
try
|
|
{
|
|
var result = new Response();
|
|
var model = Util.GetSearchModel(searchModel);
|
|
result.Result = _service.GetSiteInformations(model);
|
|
return Ok(result);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取得行政區 by id
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("{id}")]
|
|
public IActionResult GetSiteInformation(int id)
|
|
{
|
|
try
|
|
{
|
|
var result = new Response();
|
|
result.Result = _service.GetSiteInformationById(id);
|
|
return Ok(result);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增行政區
|
|
/// </summary>
|
|
/// <param name="vm"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("")]
|
|
public IActionResult InsertSiteInformation(SiteInformationViewModel vm)
|
|
{
|
|
try
|
|
{
|
|
var result = _service.InsertSiteInformation(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 UpdateSiteInformation(int id, SiteInformationViewModel vm)
|
|
{
|
|
try
|
|
{
|
|
var result = _service.UpdatSiteInformation(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 DeleteSiteInformation(int id)
|
|
{
|
|
try
|
|
{
|
|
var result = _service.DeleteSiteInformation(id);
|
|
return result.Success ? Ok(result) : BadRequest(result);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
}
|
|
}
|
|
}
|