using Autofac.Core; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Ropin.Inspection.Api.Common; using Ropin.Inspection.Model.ViewModel; using Ropin.Inspection.Service; 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 { [AllowAnonymous] public class TsysPrivController : BaseController { public ILogger _logger { get; } private readonly ITsysPrivService _service; /// /// 构造函数 /// /// /// public TsysPrivController(ITsysPrivService service, ILogger logger) { _service = service; _logger = logger; } /// /// 获取树型列表 /// /// [HttpPost("GetPrivTree")] public async Task GetListTreeAsync(TsysPrivSearch model) { try { if (model==null) { model = new TsysPrivSearch(); } var list = await _service.GetPrivTree(model); return new ApiResult>(list); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 创建 /// /// /// [Route("CreatePrivAsync")] [HttpPost] public async Task CreatePrivAsync(TsysPrivViewModel entity) { if (entity == null) { return new ApiResult(ReturnCode.ArgsError); } try { await _service.CreateOneAsync(entity); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 更新 /// /// /// /// [HttpPut("UpdatePriv/{id}")] public async Task UpdatePrivAsync(string id, TsysPrivViewModel updateModel) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _service.UpdateOneAsync(id, updateModel); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 删除 /// /// /// [HttpDelete("DeletePriv/{id}")] public async Task DeletePriv(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _service.DeleteAsync(id); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } } }