Esempio n. 1
0
        public IActionResult ToResponse()
        {
            var  model    = new ResponseJsonModel();
            bool hasError = _checkHasError(model);

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

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

            return(Json(model, _jsonSerializerSettings));
        }
Esempio n. 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));
        }
Esempio n. 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);
        }