using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Ropin.Inspection.Api.Common; using Ropin.Inspection.Model.ViewModel; using Ropin.Inspection.Service.Interface; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Ropin.Inspection.Api.Controllers { /// /// 岗位 /// public class TsysPostController : BaseController { public ILogger _logger { get; } private readonly ITsysPostService _tsysPostService; /// /// 构造函数 /// /// /// public TsysPostController(ITsysPostService tsysPostService, ILogger logger) { _tsysPostService = tsysPostService; _logger = logger; } /// /// 通过岗位ID获取岗位信息 /// /// /// [HttpGet("GetPostAsync/{PostId}")] public async Task GetPostAsync(Guid PostId) { if (Guid.Empty == PostId) { return new ApiResult(ReturnCode.GeneralError); } try { var Post = await _tsysPostService.GetByIdAsync(PostId); return new ApiResult(Post); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 获取所有岗位 /// /// [HttpGet("GetPostsAsync")] public async Task GetPostsAsync() { try { var PostList = await _tsysPostService.GetAllAsync(); return new ApiResult>(PostList?.ToList()); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 创建岗位 /// /// /// [Route("CreatePostAsync")] [HttpPost] public async Task CreatePostAsync(TsysPostViewModel Post) { if (Post == null) { return new ApiResult(ReturnCode.ArgsError); } try { await _tsysPostService.CreateOneAsync(Post); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 删除岗位 /// /// /// [HttpDelete("DeletePostAsync/{PostId}")] public async Task DeletePostAsync(Guid PostId) { if (Guid.Empty == PostId) { return new ApiResult(ReturnCode.GeneralError); } try { await _tsysPostService.DeleteAsync(PostId); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 更新岗位 /// /// /// /// [HttpPut("UpdatePostAsync/{PostId}")] public async Task UpdatePostAsync(Guid PostId, TsysPostUpdateViewModel updatePost) { if (Guid.Empty == PostId) { return new ApiResult(ReturnCode.GeneralError); } try { await _tsysPostService.UpdateAsync(PostId, updatePost); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } } }