Example #1
0
        public IActionResult ToResponse()
        {
            var  model    = new ResponseJsonModel();
            bool hasError = _checkHasError(model);

            return(Json(model, _jsonSerializerSettings));
        }
Example #2
0
        public IActionResult ToResponse(bool isSuccess)
        {
            var model = new ResponseJsonModel();

            if (!_checkHasError(model))
            {
                model.success = isSuccess;
            }

            return(Json(model, _jsonSerializerSettings));
        }
Example #3
0
        public IActionResult ToResponse <T>(T data) where T : class
        {
            var model = new ResponseJsonModel <T>();

            if (!_checkHasError(model))
            {
                model.data = data;
            }

            return(Json(model, _jsonSerializerSettings));
        }
Example #4
0
        private bool _checkHasError(ResponseJsonModel model)
        {
            var hasError = _process.HasError;

            if (hasError)
            {
                var errorMessage = _process.ToError();

                model.error = new ErrorJsonModel()
                {
                    Result       = false,
                    code         = errorMessage.Message,
                    ErrorMessage = errorMessage.Message,
                    trace_keys   = errorMessage.TraceKeys
                };
            }
            model.success = !hasError;
            return(hasError);
        }