ActionResponse:
namespace Siia.Model.Infrastructure { public class ActionResponse { private static readonly ActionResponse _success = new ActionResponse { IsSuccess = true }; public bool IsSuccess { get; set; } = true; public int Code { get; set; } public string Message { get; set; } public object Result { get; set; } public static ActionResponse Success => _success; public static ActionResponse Succeed(object result = null) { return new ActionResponse { IsSuccess = true, Result = result }; } public static ActionResponse Fail(int code, string message) { return new ActionResponse { IsSuccess = false, Code = code, Message = message }; } public ActionResponse<T> To<T>() { return new ActionResponse<T> { IsSuccess = this.IsSuccess, Code = this.Code, Result = (T)this.Result }; } } public class ActionResponse<T> : ActionResponse { public new T Result { get; set; } } }
调用:
/// <summary> /// 获取账号信息 /// </summary> /// <returns></returns> [HttpGet("[action]")] public async Task<IActionResult> GetAccountInfo() { var result = await _accountsService.GetAccountInfo(_passport.UserId); return Ok(ActionResponse.Succeed(result)); }