123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- using Autofac.Core;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Logging;
- using Ropin.Inspection.Api.Common;
- using Ropin.Inspection.Model;
- using Ropin.Inspection.Service.SYS.Interface;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using System;
- using Ropin.Inspection.Model.ViewModel.SYS;
- namespace Ropin.Inspection.Api.Controllers.SYS
- {
- public class TsysRoleHandController : BaseController
- {
- private readonly ILogger<TsysRoleController> _logger;
- private readonly ITsysRoleHandServices _service;
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="service"></param>
- /// <param name="logger"></param>
- public TsysRoleHandController(ITsysRoleHandServices service, ILogger<TsysRoleController> logger)
- {
- _service = service;
- _logger = logger;
- }
- /// <summary>
- /// 创建角色手持设备关联
- /// </summary>
- /// <returns></returns>
- [HttpPost("CreateAsync")]
- public async Task<ApiResult> CreateAsync(AddRoleHandModel viewModel)
- {
- if (viewModel == null || Guid.Empty == viewModel.C_RoleCode || null == viewModel.HandList||viewModel.HandList.Count==0)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _service.CreateAsync(viewModel);
- return new ApiResult(ReturnCode.Success, "添加成功!");
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 创建角色手持设备关联
- /// </summary>
- /// <returns></returns>
- [HttpPost("CreateOneAsync")]
- public async Task<ApiResult> CreateOneAsync(TSYSRoleHandViewModel viewModel)
- {
- if (viewModel == null || Guid.Empty == viewModel.C_RoleCode || Guid.Empty == viewModel.C_HandCode)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _service.CreateOneAsync(viewModel);
- return new ApiResult(ReturnCode.Success, "添加成功!");
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 删除角色手持设备关联,根据角色ID和手持设备ID
- /// </summary>
- /// <returns></returns>
- [HttpPost("DeleteRoleHandAsync")]
- public async Task<ApiResult> DeleteRoleHandAsync(TSYSRoleHandViewModel viewModel)
- {
- if (viewModel == null || Guid.Empty == viewModel.C_RoleCode || Guid.Empty == viewModel.C_HandCode)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _service.DeleteRoleHandAsync(viewModel.C_HandCode,viewModel.C_RoleCode);
- return new ApiResult(ReturnCode.Success, "删除成功!");
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 通过角色ID获取角色手持设备关联
- /// </summary>
- /// <param name="roleId"></param>
- /// <returns></returns>
- [HttpGet("GetRoleHandListByRoleIdAsync/{roleId}")]
- public async Task<ApiResult> GetRoleHandListByRoleIdAsync(Guid roleId)
- {
- if (roleId==Guid.Empty)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- var rolePrivs = await _service.GetRoleHandListAsync(roleId);
- return new ApiResult<IEnumerable<TSYSRoleHandModel>>(rolePrivs);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- }
- }
|