Exemplo n.º 1
0
        /// <summary>
        /// 指定方法返回Json结果
        /// </summary>
        /// <typeparam name="T">传入参数类型</typeparam>
        /// <param name="func">操作方法</param>
        /// <param name="func2">操作方法2</param>
        /// <param name="arg">传入参数</param>
        /// <returns>操作后的结果</returns>
        protected ActionResult ResultToJson <T>(Func <T, IMethodResult> func, Func <T, IMethodResult> func2, T arg)
        {
            return(ResultToJson(() =>
            {
                IMethodResult ret1 = func(arg);

                if (!ret1.IsSuccess)
                {
                    return ret1;
                }

                IMethodResult ret2 = func2(arg);

                if (!ret2.IsSuccess)
                {
                    return ret2;
                }

                if (!ret1.IsWriteLog && !ret2.IsWriteLog)
                {
                    return MethodResult.Success();
                }
                else if (ret1.IsWriteLog && !ret2.IsWriteLog)
                {
                    return ret1;
                }
                else if (!ret1.IsWriteLog && ret2.IsWriteLog)
                {
                    return ret2;
                }
                else
                {
                    return MethodResult.SuccessAndLog("{0}; {1}", ret1.Description, ret2.Description);
                }
            }));
        }