private bool ValidateParameters(ActionContext actionContext, IDictionary <string, object> rawParms) { if (rawParms.Any(kvp => !actionContext.Action.GetParameters(actionContext.Target).Select(p => p.getId()).Contains(kvp.Key))) { throw new BadRequestNOSException("Malformed arguments"); } bool isValid = true; var orderedParms = new Dictionary <string, ParameterContext>(); // setup orderedparms foreach (NakedObjectActionParameter parm in actionContext.Action.GetParameters(actionContext.Target)) { orderedParms[parm.getId()] = new ParameterContext(); object value = rawParms.ContainsKey(parm.getId()) ? rawParms[parm.getId()] : null; orderedParms[parm.getId()].ProposedValue = value; orderedParms[parm.getId()].Parameter = parm; orderedParms[parm.getId()].Action = actionContext.Action; } //check for individual parameter validity, including parsing of text input foreach (NakedObjectActionParameter parm in actionContext.Action.GetParameters(actionContext.Target)) { try { Naked valueNakedObject = GetValue(parm.getSpecification(), rawParms.ContainsKey(parm.getId()) ? rawParms[parm.getId()] : null); orderedParms[parm.getId()].ProposedNakedObject = valueNakedObject; } catch (Exception) { isValid = false; orderedParms[parm.getId()].Reason = "Invalid Entry"; // i18n } } actionContext.VisibleParameters = orderedParms.Select(p => p.Value).ToArray(); // check for validity of whole set, including any 'co-validation' involving multiple parameters if (isValid) { Consent consent = actionContext.Action.isParameterSetValid(actionContext.Target, orderedParms.Select(kvp => kvp.Value.ProposedNakedObject).ToArray()); if (!consent.isAllowed()) { foreach (ParameterContext p in actionContext.VisibleParameters) { p.Reason = consent.getReason(); } actionContext.Reason = consent.getReason(); actionContext.ErrorCause = Cause.Disabled; isValid = false; } } return(isValid); }
private bool ConsentHandler(Consent consent, Context context, Cause cause) { if (consent.isVetoed()) { context.Reason = consent.getReason(); context.ErrorCause = cause; return(false); } return(true); }