Esempio n. 1
0
        public FunctionCommand(MethodInfo command, object?obj = null, int?requiredParameters = null)
        {
            internCommand    = command;
            CommandParameter = PrecomputeTypes(command.GetParameters());
            CommandReturn    = command.ReturnType;
            if (CommandReturn.IsConstructedGenericType && CommandReturn.GetGenericTypeDefinition() == typeof(Task <>))
            {
                taskValueProp = CommandReturn.GetProperty(nameof(Task <object> .Result));
            }
            isPlainTask = CommandReturn == typeof(Task);

            callee = obj;

            NormalParameters   = CommandParameter.Count(p => p.Kind.IsNormal());
            RequiredParameters = requiredParameters ?? CommandParameter.Count(p => !p.Optional && p.Kind.IsNormal());
        }
Esempio n. 2
0
        protected IHttpActionResult ProcessResult(CommandReturn methodReturn)
        {
            if (methodReturn.Success)
            {
                if (methodReturn.Data != null)
                {
                    return(Ok(methodReturn.Data));
                }
                // Retorna 200 OK
                return(Ok());
            }

            var errorMsgs = methodReturn.Failures.Select(x => (x.PropertyName.IsEmpty() ? "" : ": " + x.PropertyName) + x.ErrorMessage);
            var messages  = string.Join("<br>", errorMsgs);

            return(ResponseMessage(new HttpResponseMessage(HttpStatusCode.Unauthorized)
            {
                ReasonPhrase = messages
            }));
        }