private ViewResult InvokeAction(object domainObject, LambdaExpression expression, FormCollection parameters, string viewNameForFailure, string viewNameForSuccess) { INakedObject nakedObject = NakedObjectsContext.GetNakedObject(domainObject); MethodInfo methodInfo = GetAction(expression); return(InvokeAction(nakedObject, methodInfo.Name, parameters, viewNameForFailure, viewNameForSuccess)); }
/// <summary> /// Invoke the action on the domain object with the parameters in the form. Return result and update valid bool to indicate if /// parameters valid. /// </summary> protected T InvokeAction <T>(object domainObject, string actionName, FormCollection parameters, out bool valid) { INakedObject nakedObject = NakedObjectsContext.GetNakedObject(domainObject); IActionSpec action = nakedObject.GetActionLeafNode(actionName); return(InvokeAction <T>(nakedObject, action, parameters, out valid)); }
/// <summary> /// Ensures that parameters in an action dialog contain default values specified in the Model. /// Should be called in a Controller method that sets up a view that will contain an action dialog. /// </summary> /// <example> /// SetUpDefaultParameters(customer, "CreateNewAddress") /// </example> protected void SetUpDefaultParameters(object domainObject, string actionName) { INakedObject nakedObject = NakedObjectsContext.GetNakedObject(domainObject); IActionSpec findOrder = nakedObject.Spec.GetObjectActions().Single(x => x.Id == actionName); SetDefaults(nakedObject, findOrder); }
/// <summary> /// Creates and populates the values in a transient object from a form /// </summary> /// <param name="form">Form to populate from</param> protected T RecreateTransient <T>(FormCollection form) where T : new() { var obj = Container.NewTransientInstance <T>(); INakedObject naked = NakedObjectsContext.GetNakedObject(obj); RefreshTransient(naked, form); return(obj); }
public virtual ActionResult ClearHistory(bool clearAll) { object lastObject = Session.LastObject(NakedObjectsContext, ObjectCache.ObjectFlag.BreadCrumb); Session.ClearCachedObjects(ObjectCache.ObjectFlag.BreadCrumb); if (lastObject == null || clearAll) { return(RedirectToAction(IdHelper.IndexAction, IdHelper.HomeName)); } SetControllerName(lastObject); return(View(NakedObjectsContext.GetNakedObject(lastObject))); }
/// <summary> /// Apply changes from form and attempt to save /// </summary> /// <typeparam name="T"></typeparam> /// <param name="form"></param> /// <param name="obj"></param> /// <returns>true if changes in form are valid and object saved</returns> protected bool SaveObject <T>(FormCollection form, ref T obj) { INakedObject naked = NakedObjectsContext.GetNakedObject(obj); bool result = false; if (ValidateChanges(naked, new ObjectAndControlData() { Form = form })) { if (ApplyChanges(naked, new ObjectAndControlData() { Form = form })) { result = true; } } obj = naked.GetDomainObject <T>(); return(result); }
/// <summary> /// Invoke the action on the domain object with the parameters in the form. Got to appropriate view based on result /// </summary> protected ViewResult InvokeAction(object domainObject, string actionName, FormCollection parameters, String viewNameForFailure, string viewNameForSuccess = null) { INakedObject nakedObject = NakedObjectsContext.GetNakedObject(domainObject); return(InvokeAction(nakedObject, actionName, parameters, viewNameForFailure, viewNameForSuccess)); }
/// <summary> /// Invoke the action on the domain object with the parameters in the form. Return result and update valid bool to indicate if /// parameters valid. /// </summary> protected TResult InvokeAction <TTarget, TParm1, TParm2, TParm3, TParm4, TResult>(TTarget domainObject, Expression <Func <TTarget, Func <TParm1, TParm2, TParm3, TParm4, TResult> > > expression, FormCollection parameters, out bool valid) { return(InvokeAction <TResult>(NakedObjectsContext.GetNakedObject(domainObject), expression, parameters, out valid)); }