Antaris.AspNetCore.Mvc.Widgets.Internal.WidgetMethodSelector.ResolveHttpMethod C# (CSharp) Method

ResolveHttpMethod() private static method

Resolves the HTTP method used to discover which action to execute.
private static ResolveHttpMethod ( WidgetContext context ) : string
context Antaris.AspNetCore.Mvc.Widgets.Infrastructure.WidgetContext The widget context.
return string
        private static string ResolveHttpMethod(WidgetContext context)
        {
            string httpMethod = context.ViewContext?.HttpContext?.Request?.Method;
            if (string.Equals(httpMethod, "get", StringComparison.OrdinalIgnoreCase))
            {
                httpMethod = "Get";
            }
            else
            {
                httpMethod = "Post";
            }

            if (httpMethod == "Post" && !string.IsNullOrEmpty(context.WidgetId))
            {
                // MA - We only want to use Post if we are the active widget.
                // TODO - This needs to come from the value provider.
                var form = context.ViewContext?.HttpContext?.Request?.Form;
                if (!string.Equals(context.WidgetId, form[WidgetConventions.WidgetTarget], StringComparison.CurrentCultureIgnoreCase))
                {
                    httpMethod = "Get";
                }
            }

            return httpMethod;
        }
    }