Esempio n. 1
0
        public override void OnException(ExceptionContext filterContext)
        {
            Exception ex = filterContext.Exception;

            //zapis samego wyjątku do logu - np. z wykorzystaniem nloga

            filterContext.ExceptionHandled = true;

            var result = new ViewModels.ApiResult()
            {
                Success = false,
                Errors  = new List <ViewModels.ApiResultErrorMessage>()
                {
                    new ViewModels.ApiResultErrorMessage()
                    {
                        PropertyName = string.Empty,
                        Error        = ex.Message
                    }
                }
            };

            filterContext.Result = new JsonResult()
            {
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                Data = result
            };
        }
Esempio n. 2
0
        protected ActionResult SuccessResult(object value = null)
        {
            var result = new ViewModels.ApiResult()
            {
                Success = true,
                Value   = value
            };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 3
0
        public ActionResult ErrorResult(IEnumerable <ValidationFailure> errors)
        {
            var result = new ViewModels.ApiResult()
            {
                Success = false,
                Errors  = errors.Select(e => new ViewModels.ApiResultErrorMessage()
                {
                    PropertyName = e.PropertyName,
                    Error        = e.ErrorMessage
                })
            };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 4
0
        protected ActionResult ErrorResult(string message)
        {
            var result = new ViewModels.ApiResult()
            {
                Success = false,
                Errors  = new List <ViewModels.ApiResultErrorMessage>()
                {
                    new ViewModels.ApiResultErrorMessage()
                    {
                        PropertyName = string.Empty,
                        Error        = message
                    }
                }
            };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }