Exemple #1
0
        public static IActionResult CreateResult <T>(
            this Controller @this,
            Result <T> result,
            ActionResultOptions <T> options)
        {
            object value;

            if (!result.HasError)
            {
                value = result.Content;
            }
            else
            {
                value = result.ErrorMessage;
            }

            if (result.Status == Status.Ok)
            {
                return(@this.Ok(value));
            }
            if (result.Status == Status.NotFound)
            {
                return(@this.NotFound(value));
            }
            if (result.Status == Status.BadRequest)
            {
                return(@this.BadRequest(value));
            }
            if (result.Status == Status.Created)
            {
                return(@this.CreatedAtRoute(options.RouteName, options.RouteValues(result.Content), value));
            }

            throw new ArgumentException("Unknown status.", nameof(result));
        }
Exemple #2
0
        public static IActionResult CreateResult <T>(
            this Controller @this,
            Result <T> result,
            Action <ActionResultOptions <T> > options)
        {
            ActionResultOptions <T> o = new ActionResultOptions <T>(@this);

            options(o);
            return(@this.CreateResult(result, o));
        }