123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Logging;
- using Ropin.Inspection.Api.Common;
- using Ropin.Inspection.Model;
- using Ropin.Inspection.Model.ViewModel;
- using Ropin.Inspection.Service.SYS.Interface;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- namespace Ropin.Inspection.Api.Controllers
- {
- [AllowAnonymous]
-
-
-
- public class TsysRoleController : BaseController
- {
- private readonly ILogger<TsysRoleController> _logger;
- private readonly ITsysRoleService _tsysRoleService;
-
-
-
-
-
- public TsysRoleController(ITsysRoleService tsysRoleService, ILogger<TsysRoleController> logger)
- {
- _tsysRoleService = tsysRoleService;
- _logger = logger;
- }
-
-
-
-
-
- [HttpGet("GetRoleAsync/{RoleId}")]
- public async Task<ApiResult> GetRoleAsync(Guid RoleId)
- {
- if (Guid.Empty == RoleId)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- var Role = await _tsysRoleService.GetByIdAsync(RoleId);
- return new ApiResult<TsysRoleViewModel>(Role);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
-
-
-
-
- [HttpGet("GetRolesAsync")]
- public async Task<ApiResult> GetRolesAsync()
- {
- try
- {
- var RoleList = await _tsysRoleService.GetAllAsync();
- return new ApiResult<IEnumerable<TsysRoleViewModel>>(RoleList.OrderBy(i=>i.C_LicenseCode));
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
-
-
-
-
-
- [HttpGet("GetBylicenseCodeAsync/{LicenseCode}/{status=1}")]
- public async Task<ApiResult> GetBylicenseCodeAsync(string LicenseCode, string status)
- {
- if (string.IsNullOrEmpty(LicenseCode))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- var RoleList = await _tsysRoleService.GetBylicenseCodeAsync(LicenseCode, status);
- return new ApiResult<IEnumerable<TsysRoleOrgLicenseViewModel>>(RoleList);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
-
-
-
-
-
-
-
- [HttpGet("GetBylicenseCodeByNameAsync/{LicenseCode}/{Name}/{status=1}")]
- public async Task<ApiResult> GetBylicenseCodeByNameAsync(string LicenseCode, string Name, string status)
- {
- if (string.IsNullOrEmpty(LicenseCode))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- var RoleList = await _tsysRoleService.GetBylicenseCodeAsync(LicenseCode, status);
- if(string.IsNullOrWhiteSpace(Name))
- return new ApiResult<IEnumerable<TsysRoleOrgLicenseViewModel>>(RoleList);
- else
- return new ApiResult<IEnumerable<TsysRoleOrgLicenseViewModel>>(RoleList.Where(x=>x.C_Name.Contains(Name)));
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
-
-
-
-
-
- [Route("CreateRoleAsync")]
- [HttpPost]
- public async Task<ApiResult> CreateRoleAsync([FromBody] TsysRoleCreateViewModel Role)
- {
- if (Role == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- await _tsysRoleService.CreateAsync(Role);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
-
-
-
-
-
- [HttpDelete("DeleteRoleAsync/{RoleId}")]
- public async Task<ApiResult> DeleteRoleAsync(Guid RoleId)
- {
- if (Guid.Empty == RoleId)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _tsysRoleService.DeleteAsync(RoleId);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
-
-
-
-
-
-
- [HttpPut("UpdateRoleAsync/{RoleId}")]
- public async Task<ApiResult> UpdateRoleAsync(Guid RoleId, TsysRoleUpdateViewModel updateRole)
- {
- if (Guid.Empty == RoleId)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _tsysRoleService.UpdateAsync(RoleId, updateRole);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- }
|