tycg_carviolation_BE/Traffic.Api/Controllers/RoleController.cs

124 lines
3.6 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.Models;
using Traffic.Data.ViewModels;
using Traffic.Service.Interfaces;
namespace Traffic.Api.Controllers
{
[Route("api/role")]
[Authorize]
[ApiController]
public class RoleController : ControllerBase
{
private readonly IRoleService _service;
public RoleController(IRoleService service)
{
this._service = service;
}
[HttpPost("PostRoleDataList")]
public IActionResult PostRoleDataList(RoleData roleData)
{
try
{
var userIdentity = (ClaimsIdentity)User.Identity;
var mID = new ParserForUserFromClaim(userIdentity).GetUserId();
return Ok(_service.PostRoleDataList(mID, roleData));
}
catch (Exception)
{
return BadRequest();
}
}
[HttpGet("GetRoleDataList")]
public IActionResult GetRoleDataList([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.GetRoleDataList(model);
return Ok(result);
}
catch (Exception)
{
return BadRequest();
}
}
[HttpGet("GetRoleInfoList")]
public IActionResult GetRoleInfoList()
{
try
{
var result = new Response();
result.Result = _service.GetRoleInfoList();
return Ok(result);
}
catch (Exception)
{
return BadRequest();
}
}
[HttpGet("GetRolePermissionInfo/{id}")]
public IActionResult GetRolePermissionInfo(int? Id)
{
try
{
return Ok(new { Result = _service.GetRolePermissionInfo(Id) });
}
catch (Exception)
{
return BadRequest();
}
}
[HttpGet("GetAllPagePermission/{id}")]
public IActionResult GetAllPagePermission(int id)
{
try
{
var re = new Response();
re.Result = _service.GetAllPagePermission(id);
return Ok(re);
}
catch (Exception)
{
return BadRequest();
}
}
[HttpPut("PutPageRoleStatus")]
public IActionResult PutPageRoleStatus(PagePermissionData pagePermission)
{
try
{
return Ok(new { Result = _service.PutPageRoleStatus(pagePermission) });
}
catch (Exception)
{
return BadRequest();
}
}
}
}