예제 #1
0
        /// <summary>
        /// 返回数据结果。
        /// </summary>
        /// <param name="data">数据列表。</param>
        /// <param name="message">消息。</param>
        /// <returns>返回包含数据的结果。</returns>
        protected virtual IActionResult Success(object data, string message = null)
        {
            var instance = new ApiDataResult(data);

            instance.Message = message;
            return(Success(instance));
        }
예제 #2
0
        /// <summary>
        /// 返回验证失败结果。
        /// </summary>
        /// <returns>验证失败结果。</returns>
        protected virtual IActionResult BadResult()
        {
            var dic    = new Dictionary <string, string>();
            var result = new ApiDataResult <Dictionary <string, string> >(dic)
            {
                Code = (int)ErrorCode.ValidError
            };

            foreach (var key in ModelState.Keys)
            {
                var error = ModelState[key].Errors.FirstOrDefault()?.ErrorMessage;
                if (string.IsNullOrEmpty(key))
                {
                    result.Message = error;
                }
                else
                {
                    dic[key] = error;
                }
            }
            return(OkResult(result));
        }