Exemplo n.º 1
0
        public static void SetError <TModel>(this IListViewModelResponse <TModel> response, ILogger logger, Exception ex)
        {
            response.DidError     = true;
            response.ErrorMessage = ex.Message;

            logger?.LogError(ex.Message);
        }
        public static IActionResult ToHttpResponse <TModel>(this IListViewModelResponse <TModel> response)
        {
            var status = HttpStatusCode.OK;

            if (response.DidError)
            {
                status = HttpStatusCode.InternalServerError;
            }
            else if (response.Model == null)
            {
                status = HttpStatusCode.NoContent;
            }

            return(new ObjectResult(response)
            {
                StatusCode = (Int32)status
            });
        }