コード例 #1
0
        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));
        }
コード例 #2
0
        /// <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));
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
        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)));
        }
コード例 #6
0
        /// <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);
        }
コード例 #7
0
        /// <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));
        }
コード例 #8
0
 /// <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));
 }