using System; using System.Threading.Tasks; using Infrastructure; using Microsoft.AspNetCore.Mvc; using OpenAuth.App; using OpenAuth.App.Request; using OpenAuth.App.Response; using OpenAuth.Repository.Domain; namespace OpenAuth.WebApi.Controllers { ///
/// {ModuleName}接口 ///
[Route("api/[controller]/[action]")] [ApiController] public class {ClassName}sController : ControllerBase { private readonly {ModuleCode} _app; //获取详情 [HttpGet] public Response<{ClassName}> Get(string id) { var result = new Response<{ClassName}>(); try { result.Result = _app.Get(id); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } //添加 [HttpPost] public Response Add(AddOrUpdate{ClassName}Req obj) { var result = new Response(); try { _app.Add(obj); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } //修改 [HttpPost] public Response Update(AddOrUpdate{ClassName}Req obj) { var result = new Response(); try { _app.Update(obj); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } ///
/// 加载列表 ///
[HttpGet] public async Task Load([FromQuery]Query{ClassName}ListReq request) { return await _app.Load(request); } ///
/// 批量删除 ///
[HttpPost] public Response Delete([FromBody]string[] ids) { var result = new Response(); try { _app.Delete(ids); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } public {ClassName}sController({ModuleCode} app) { _app = app; } } }