tycg_carviolation_BE/Traffic.Api/Controllers/SystemController.cs

88 lines
2.5 KiB
C#
Raw Normal View History

using Microsoft.AspNetCore.Authorization;
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/system")]
[Authorize]
[ApiController]
public class SystemController : ControllerBase
{
private readonly IPageListService _service;
public SystemController(IPageListService service)
{
this._service = service;
}
[HttpGet("GetPageDataList")]
public IActionResult GetPageDataList([FromQuery] SearchModelViewModel searchModel)
{
try
{
var result = new Response();
var model = new SearchModel
{
Term = searchModel.Term,
Page = Convert.ToInt32(string.IsNullOrWhiteSpace(searchModel.Page) ? "1" : searchModel.Page),
PageSize = Convert.ToInt32(string.IsNullOrWhiteSpace(searchModel.PageSize) ? "1" : searchModel.PageSize),
IsAsc = searchModel.IsAsc == "true" ? true : false,
Order = string.IsNullOrWhiteSpace(searchModel.Order) ? "id" : searchModel.Order
};
result.Result = _service.GetPageDataList(model);
return Ok(result);
}
catch (Exception)
{
return BadRequest();
}
}
[HttpPost("PostPageListData")]
public IActionResult PostPageListData(PageData pageData)
{
try
{
return Ok(_service.PostPageDataList(pageData));
}
catch (Exception)
{
return BadRequest();
}
}
[HttpPut("PutPageData")]
public IActionResult PutPageData(PageData pageData)
{
try
{
return Ok(_service.PutPageData(pageData));
}
catch (Exception)
{
return BadRequest();
}
}
[HttpDelete("DeletePageData")]
public IActionResult DeletePageData(int id)
{
try
{
return Ok(_service.DeletePageData(id));
}
catch (Exception)
{
return BadRequest();
}
}
}
}