コード例 #1
0
        public JsonCommonResult(CommonActionResult commonActionResult)
            : base(commonActionResult)
        {
            this.Data = commonActionResult.ViewModels;

            if (this.Data != null)
            {
                this.Count = commonActionResult.ViewModels.Count;
            }

            this.ServerVerison = commonActionResult.ServerVerison;
            this.Ratio         = commonActionResult.Ratio;
            this.Total         = commonActionResult.Total;

            if (this.ServerVerison.HasValue)
            {
                this.CustomResultHeaders.Add(new CustomHeaderItem {
                    Key = "sver", Value = this.ServerVerison.ToString(), IsValueType = true
                });
            }

            if (this.Ratio.HasValue)
            {
                this.CustomResultHeaders.Add(new CustomHeaderItem {
                    Key = "ratio", Value = this.Ratio.ToString(), IsValueType = true
                });
            }

            if (this.Total.HasValue)
            {
                this.CustomResultHeaders.Add(new CustomHeaderItem {
                    Key = "total", Value = this.Total.ToString(), IsValueType = true
                });
            }
        }
コード例 #2
0
 public JsonSingleDataResult(CommonActionResult commonActionResult)
     : base(commonActionResult)
 {
     if (commonActionResult.ViewModels != null && commonActionResult.ViewModels.Count > 0)
     {
         this.Data = commonActionResult.ViewModels[0];
     }
 }
コード例 #3
0
ファイル: JsonResultBase.cs プロジェクト: itabas016/ebandbox
        public JsonResultBase(CommonActionResult commonActionResult)
        {
            if (commonActionResult.CommonResult != null)
            {
                this.ResultCode = commonActionResult.CommonResult.result;

                this.Description = commonActionResult.CommonResult.desc;

                this.CustomResultHeaders = commonActionResult.CustomResultHeaders;
            }

            this.Host = commonActionResult.Host;
        }
コード例 #4
0
        public virtual CommonActionResult BuildResult <T>(Func <bool> checkParameterAction, Func <IList <T> > getViewModelsActions, bool?checkSignature = null)
            where T : IViewModel
        {
            var defaultViewModels = new List <IViewModel>();
            var actionResult      = new CommonActionResult(this.RequestRepository, defaultViewModels);

            actionResult.CommonResult = new CommonResult();

            try
            {
                CheckParamAndGetResult <T>(checkParameterAction, getViewModelsActions, actionResult);
            }
            catch (Exception ex)
            {
                actionResult.CommonResult.result = ResultCode.System_Error;
                LogHelper.Error(string.Format("BuildResult Error:{1}{0}URL:{2}{0}Stacktrace{3}", Environment.NewLine, ex.Message, this.RequestRepository.RawUrl, ex.StackTrace));
            }

            return(actionResult);
        }
コード例 #5
0
        private static void CheckParamAndGetResult <T>(Func <bool> checkParameterAction, Func <IList <T> > getViewModelsActions, CommonActionResult actionResult) where T : IViewModel
        {
            if (checkParameterAction())
            {
                var viewModels = getViewModelsActions();
                if (viewModels.Any())
                {
                    actionResult.CommonResult.result = ResultCode.Successful;
                }
                else
                {
                    actionResult.CommonResult.result = ResultCode.No_Record_Found;
                }

                if (viewModels != null && viewModels.Any())
                {
                    viewModels.ToList().ForEach(s => actionResult.ViewModels.Add(s));
                }
            }
            else
            {
                actionResult.CommonResult.result = ResultCode.Invalid_Parameter;
            }
        }