public virtual ActionResult EditObject(ObjectAndControlData controlData, FormCollection form) {
            Decrypt(form);
            controlData.Form = form;
            var nakedObject = controlData.GetNakedObject(Facade);
            SetExistingCollectionFormats(form);

            if (nakedObject.IsNotPersistent) {
                RefreshTransient(nakedObject, form);
            }

            switch (controlData.SubAction) {
                case (ObjectAndControlData.SubActionType.Action):
                    SetNewCollectionFormats(controlData);
                    return ActionOnNotPersistentObject(controlData);
                case (ObjectAndControlData.SubActionType.None):
                    AddAttemptedValuesNew(nakedObject, controlData);
                    return View("ObjectEdit", nakedObject.GetDomainObject());
                case (ObjectAndControlData.SubActionType.Pager):
                    SetNewCollectionFormats(controlData);
                    return AppropriateView(controlData, nakedObject);
                case (ObjectAndControlData.SubActionType.Redisplay):
                    return Redisplay(controlData);
            }
            Log.ErrorFormat("SubAction handling not implemented in EditObject for {0}", controlData.SubAction.ToString());
            throw new NotImplementedException(controlData.SubAction.ToString());
        }
Exemple #2
0
 public virtual ActionResult Details(ObjectAndControlData controlData) {
     Assert.AssertTrue(controlData.SubAction == ObjectAndControlData.SubActionType.Details ||
                       controlData.SubAction == ObjectAndControlData.SubActionType.None);
     INakedObject nakedObject = FilterCollection(controlData.GetNakedObject(), controlData);
     SetNewCollectionFormats(controlData);
     return AppropriateView(controlData, nakedObject);
 }
        public virtual ActionResult Details(ObjectAndControlData controlData) {
            Debug.Assert(controlData.SubAction == ObjectAndControlData.SubActionType.Details ||
                         controlData.SubAction == ObjectAndControlData.SubActionType.None);

            var nakedObject = controlData.GetNakedObject(Facade);
            nakedObject = FilterCollection(nakedObject, controlData);
            SetNewCollectionFormats(controlData);
            return AppropriateView(controlData, nakedObject);
        }
        public virtual ActionResult Details(ObjectAndControlData controlData, FormCollection form) {
            Decrypt(form);
            controlData.Form = form;
            Debug.Assert(controlData.SubAction == ObjectAndControlData.SubActionType.Redisplay ||
                         controlData.SubAction == ObjectAndControlData.SubActionType.Details ||
                         controlData.SubAction == ObjectAndControlData.SubActionType.Cancel ||
                         controlData.SubAction == ObjectAndControlData.SubActionType.None);
            var nakedObject = FilterCollection(controlData.GetNakedObject(Facade), controlData);
            SetExistingCollectionFormats(form);
            SetNewCollectionFormats(controlData);

            nakedObject.SetIsNotQueryableState(true);

            if (controlData.SubAction == ObjectAndControlData.SubActionType.Cancel && nakedObject.IsTransient && nakedObject.IsUserPersistable) {
                // remove from cache and return to last object 
                Session.RemoveFromCache(Facade, nakedObject, ObjectCache.ObjectFlag.BreadCrumb);
                return AppropriateView(controlData, null);
            }
            string property = DisplaySingleProperty(controlData, controlData.DataDict);
            return AppropriateView(controlData, nakedObject, null, property);
        }
Exemple #5
0
        public virtual ActionResult Details(ObjectAndControlData controlData, FormCollection form) {
            Decrypt(form);
            controlData.Form = form;
            Assert.AssertTrue(controlData.SubAction == ObjectAndControlData.SubActionType.Redisplay ||
                              controlData.SubAction == ObjectAndControlData.SubActionType.Details ||
                              controlData.SubAction == ObjectAndControlData.SubActionType.Cancel ||
                              controlData.SubAction == ObjectAndControlData.SubActionType.None);
            INakedObject nakedObject = FilterCollection(controlData.GetNakedObject(), controlData);
            SetExistingCollectionFormats(nakedObject, form);
            SetNewCollectionFormats(controlData);
            nakedObject.SetNotQueryable(true);

            if (controlData.SubAction == ObjectAndControlData.SubActionType.Cancel &&
                nakedObject.ResolveState.IsTransient() &&
                nakedObject.Specification.Persistable == Persistable.USER_PERSISTABLE) {
                // remove from cache and return to last object 
                Session.RemoveFromCache(nakedObject, ObjectCache.ObjectFlag.BreadCrumb);
                return AppropriateView(controlData, null);
            }
            string property = DisplaySingleProperty(controlData, controlData.DataDict);
            return AppropriateView(controlData, nakedObject, null, property);
        }
 private ActionResult Select(ObjectAndControlData controlData) {
     return SelectSingleItem(controlData.GetNakedObject(Facade), null, controlData, controlData.DataDict);
 }
 private ActionResult ApplyEditAction(ObjectAndControlData controlData) {
     var nakedObject = controlData.GetNakedObject(Facade);
     var ok = ApplyEdit(nakedObject, controlData);
     if (ok) {
         string targetActionId = controlData.DataDict["targetActionId"];
         var oid = Facade.OidTranslator.GetOidTranslation(nakedObject);
         var targetAction = Facade.GetObjectAction(oid, targetActionId).Action;
         return ExecuteAction(controlData, nakedObject, targetAction);
     }
     return View("ViewModel", nakedObject.GetDomainObject());
 }
 private ActionResult Redisplay(ObjectAndControlData controlData) {
     SetNewCollectionFormats(controlData);
     var property = DisplaySingleProperty(controlData, controlData.DataDict);
     var isEdit = bool.Parse(controlData.DataDict["editMode"]);
     var nakedObject = controlData.GetNakedObject(Facade);
     return property == null ? View(isEdit ? "ObjectEdit" : "ObjectView", nakedObject.GetDomainObject()) :
         View(isEdit ? "PropertyEdit" : "PropertyView", new PropertyViewModel(nakedObject.GetDomainObject(), property));
 }
 private ActionResult ApplyEdit(ObjectAndControlData controlData) {
     var nakedObject = controlData.GetNakedObject(Facade);
     var viewName = ApplyEdit(nakedObject, controlData) ? "ObjectView" : "ObjectEdit";
     return View(viewName, nakedObject.GetDomainObject());
 }
        private ActionResult ApplyEditAndClose(ObjectAndControlData controlData) {
            var nakedObject = controlData.GetNakedObject(Facade);
            if (ApplyEdit(nakedObject, controlData)) {
                // last object or home
                object lastObject = Session.LastObject(Facade, ObjectCache.ObjectFlag.BreadCrumb);
                if (lastObject == null) {
                    return RedirectHome();
                }

                nakedObject = Facade.GetObject(lastObject);
                return AppropriateView(controlData, nakedObject);
            }
            return View("ObjectEdit", nakedObject.GetDomainObject());
        }
Exemple #11
0
 public virtual ActionResult Action(ObjectAndControlData controlData) {
     return View("ActionDialog", new FindViewModel {
         ContextObject = controlData.GetNakedObject().Object,
         ContextAction = controlData.GetAction()
     });
 }
 public virtual ActionResult EditObject(ObjectAndControlData controlData) {
     Debug.Assert(controlData.SubAction == ObjectAndControlData.SubActionType.None);
     return View("ObjectEdit", controlData.GetNakedObject(Facade).GetDomainObject());
 }
Exemple #13
0
        protected string DisplaySingleProperty(ObjectAndControlData controlData, IDictionary<string, string> data) {
            if (Request.IsAjaxRequest()) {
                if (controlData.SubAction == ObjectAndControlData.SubActionType.Redisplay) {
                    IEnumerable<INakedObjectAssociation> assocs = controlData.GetNakedObject().Specification.Properties.Where(p => p.IsCollection);
                    INakedObjectAssociation item = assocs.SingleOrDefault(a => data.ContainsKey(a.Id));
                    return item == null ? null : item.Id;
                }
                if (controlData.ActionId == null) {
                    IEnumerable<INakedObjectAssociation> assocs = controlData.GetNakedObject().Specification.Properties.Where(p => !p.IsCollection);
                    INakedObjectAssociation item = assocs.SingleOrDefault(a => data.ContainsKey(a.Id));
                    return item == null ? null : item.Id;
                }
                {
                    IEnumerable<INakedObjectActionParameter> parms = controlData.GetAction().Parameters;
                    INakedObjectActionParameter item = parms.SingleOrDefault(p => data.ContainsKey(p.Id));
                    return item == null ? null : item.Id;
                }
            }

            return null;
        }
        internal ActionResult AppropriateView(ObjectAndControlData controlData, IObjectFacade nakedObject, IActionFacade action = null, string propertyName = null) {
            if (nakedObject == null) {
                // no object to go to 
                // if action on object go to that object. 
                // if action on collection go to collection 
                // if action on service go to last object 

                nakedObject = controlData.GetNakedObject(Facade);

                if (nakedObject.Specification.IsService) {
                    object lastObject = Session.LastObject(Facade, ObjectCache.ObjectFlag.BreadCrumb);
                    if (lastObject == null) {
                        return RedirectHome();
                    }

                    nakedObject = Facade.GetObject(lastObject);                  
                }

                if (nakedObject.IsCollectionMemento) {
                    // if we have returned null and existing object is collection memento need to make 
                    // sure action remains action from original collectionMemento.
                    action = nakedObject.MementoAction;
                }

            }

            if (nakedObject.Specification.IsCollection && !nakedObject.Specification.IsParseable) {
                int collectionSize = nakedObject.Count();
                if (collectionSize == 1) {
                    // remove any paging data - to catch case where custom page has embedded standalone collection as paging data will confuse rendering 
                    ViewData.Remove(IdConstants.PagingData);
                    // is this safe TODO !!
                    return View("ObjectView", nakedObject.ToEnumerable().First().GetDomainObject());
                }

                nakedObject = Page(nakedObject, collectionSize, controlData);
                // todo is there a better way to do this ?
                action = action ?? nakedObject.MementoAction;
                int page, pageSize;
                CurrentlyPaging(controlData, collectionSize, out page, out pageSize);
                var format = ViewData["NofCollectionFormat"] as string;
                return View("StandaloneTable", ActionResultModel.Create(Facade, action, nakedObject, page, pageSize, format));
            }
            // remove any paging data - to catch case where custom page has embedded standalone collection as paging data will confuse rendering   
            ViewData.Remove(IdConstants.PagingData);

            if (controlData.DataDict.Values.Contains("max")) {
                // maximizing an inline object - do not update history
                ViewData.Add("updateHistory", false);
            }

            return propertyName == null ? View(nakedObject.IsNotPersistent ? "ObjectView" : "ViewNameSetAfterTransaction", nakedObject.GetDomainObject()) :
                View(nakedObject.IsNotPersistent ? "PropertyView" : "ViewNameSetAfterTransaction", new PropertyViewModel(nakedObject.GetDomainObject(), propertyName));
        }
        private ActionResult SelectOnAction(ObjectAndControlData controlData) {
            var nakedObjectAction = controlData.GetAction(Facade);
            var contextNakedObject = FilterCollection(controlData.GetNakedObject(Facade), controlData);

            return SelectSingleItem(contextNakedObject, nakedObjectAction, controlData, controlData.DataDict);
        }
Exemple #16
0
 private ActionResult InitialAction(ObjectAndControlData controlData) {
     CheckConcurrency(controlData.GetNakedObject(), null, controlData, (z, x, y) => IdHelper.GetConcurrencyActionInputId(x, controlData.GetAction(), y));
     return ExecuteAction(controlData, controlData.GetNakedObject(), controlData.GetAction());
 }
Exemple #17
0
 public virtual ActionResult EditObject(ObjectAndControlData controlData) {
     Assert.AssertTrue(controlData.SubAction == ObjectAndControlData.SubActionType.None);
     return View("ObjectEdit", controlData.GetNakedObject().Object);
 }
Exemple #18
0
        private ActionResult SelectOnAction(ObjectAndControlData controlData) {
            INakedObjectAction nakedObjectAction = controlData.GetAction();
            INakedObject contextNakedObject = FilterCollection(controlData.GetNakedObject(), controlData);

            return SelectSingleItem(contextNakedObject, nakedObjectAction, controlData, controlData.DataDict);
        }
Exemple #19
0
 private ActionResult ApplyEditAction(ObjectAndControlData controlData) {
     var ok = ValidateChanges(controlData.GetNakedObject(), controlData) && ApplyChanges(controlData.GetNakedObject(), controlData);
     if (ok) {
         string targetActionId = controlData.DataDict["targetActionId"];          
         INakedObjectAction targetAction = FrameworkHelper.GetActions(controlData.GetNakedObject()).Single(a => a.Id == targetActionId);
         return ExecuteAction(controlData, controlData.GetNakedObject(), targetAction);
     }
     return View("ViewModel", controlData.GetNakedObject().Object);
 }
Exemple #20
0
        private ActionResult ApplyEdit(ObjectAndControlData controlData) {
            string viewName = "ObjectEdit";
            if (ValidateChanges(controlData.GetNakedObject(), controlData)) {
                viewName = ApplyChanges(controlData.GetNakedObject(), controlData) ? "ObjectView" : "ObjectEdit";
            }

            return View(viewName, controlData.GetNakedObject().Object);
        }
Exemple #21
0
        private ActionResult ApplyAction(ObjectAndControlData controlData) {
            var targetNakedObject = FilterCollection(controlData.GetNakedObject(), controlData);
            var targetAction = controlData.GetAction();

            CheckConcurrency(targetNakedObject, null, controlData, (z, x, y) => IdHelper.GetConcurrencyActionInputId(x, targetAction, y));

            if (targetNakedObject.IsNotPersistent()) {
                RefreshTransient(targetNakedObject, controlData.Form);
            }

            // do after any parameters set by contributed action so this takes priority
            SetSelectedParameters(targetAction);
            if (ValidateParameters(targetNakedObject, targetAction, controlData)) {
                targetNakedObject.SetNotQueryable(targetAction.IsContributedMethod);
                var parms = GetParameterValues(targetAction, controlData);
                return AppropriateView(controlData, Execute(targetAction, targetNakedObject, parms.ToArray()), targetAction);
            }
            var property = DisplaySingleProperty(controlData, controlData.DataDict);
            return View(property == null ? "ActionDialog" : "PropertyEdit", new FindViewModel { ContextObject = targetNakedObject.Object, ContextAction = targetAction, PropertyName = property });
        }
        public virtual ActionResult Action(ObjectAndControlData controlData) {
            var no = controlData.GetNakedObject(Facade);
            var action = controlData.GetAction(Facade);

            return View("ActionDialog", new FindViewModel {
                ContextObject = no.GetDomainObject(),
                ContextAction = action
            });
        }
 private ActionResult InitialAction(ObjectAndControlData controlData) {
     var nakedObject = controlData.GetNakedObject(Facade);
     var nakedObjectAction = controlData.GetAction(Facade);
     CheckConcurrency(nakedObject, null, controlData, (z, x, y) => IdHelper.GetConcurrencyActionInputId(x, nakedObjectAction, y));
     return ExecuteAction(controlData, nakedObject, nakedObjectAction);
 }
        public virtual ActionResult Edit(ObjectAndControlData controlData, FormCollection form) {
            Decrypt(form);
            controlData.Form = form;
            AddFilesToControlData(controlData);

            var nakedObject = controlData.GetNakedObject(Facade);
            RefreshTransient(nakedObject, form);
            SetExistingCollectionFormats(form);
            AddAttemptedValuesNew(nakedObject, controlData);

            switch (controlData.SubAction) {
                case (ObjectAndControlData.SubActionType.Find):
                    return Find(controlData);
                case (ObjectAndControlData.SubActionType.Select):
                    return Select(controlData);
                case (ObjectAndControlData.SubActionType.ActionAsFind):
                    return ActionAsFind(controlData);
                case (ObjectAndControlData.SubActionType.InvokeActionAsFind):
                    return InvokeActionAsFind(controlData);
                case (ObjectAndControlData.SubActionType.InvokeActionAsSave):
                    return InvokeActionAsSave(controlData);
                case (ObjectAndControlData.SubActionType.Redisplay):
                    return Redisplay(controlData);
                case (ObjectAndControlData.SubActionType.None):
                    return ApplyEdit(controlData);
                case (ObjectAndControlData.SubActionType.SaveAndClose):
                    return ApplyEditAndClose(controlData);
                case (ObjectAndControlData.SubActionType.Action):
                    return ApplyEditAction(controlData);
            }
            Log.ErrorFormat("SubAction handling not implemented in Edit for {0}", controlData.SubAction.ToString());
            throw new NotImplementedException(controlData.SubAction.ToString());
        }
        private ActionResult ApplyAction(ObjectAndControlData controlData) {
            var targetNakedObject = FilterCollection(controlData.GetNakedObject(Facade), controlData);
            var targetAction = controlData.GetAction(Facade);

            CheckConcurrency(targetNakedObject, null, controlData, (z, x, y) => IdHelper.GetConcurrencyActionInputId(x, targetAction, y));

            if (targetNakedObject.IsNotPersistent) {
                RefreshTransient(targetNakedObject, controlData.Form);
            }

            // do after any parameters set by contributed action so this takes priority
            SetSelectedParameters(targetAction);

            var ac = GetParameterValues(targetAction, controlData);
            ActionResultContextFacade ar;

            if (targetNakedObject.Specification.IsCollection && !targetNakedObject.Specification.IsParseable) {
                var oids = targetNakedObject.ToEnumerable().Select(no => Facade.OidTranslator.GetOidTranslation(no)).ToArray();
                var spec = targetNakedObject.ElementSpecification;

                ar = Facade.ExecuteListAction(oids, spec, targetAction.Id, ac);
            }
            else {
                var oid = Facade.OidTranslator.GetOidTranslation(targetNakedObject);
                ar = Facade.ExecuteObjectAction(oid, targetAction.Id, ac);
            }

            if (!HasError(ar)) {
                targetNakedObject.SetIsNotQueryableState(targetAction.IsContributed);
                return AppropriateView(controlData, GetResult(ar), targetAction);
            }

            foreach (var parm in ar.ActionContext.VisibleParameters) {
                if (!string.IsNullOrEmpty(parm.Reason)) {
                    ModelState.AddModelError(IdHelper.GetParameterInputId(targetAction, parm.Parameter), parm.Reason);
                }
            }

            if (!(string.IsNullOrEmpty(ar.ActionContext.Reason))) {
                ModelState.AddModelError("", ar.ActionContext.Reason);
            }

            var property = DisplaySingleProperty(controlData, controlData.DataDict);
            return View(property == null ? "ActionDialog" : "PropertyEdit", new FindViewModel {ContextObject = targetNakedObject.GetDomainObject(), ContextAction = targetAction, PropertyName = property});
        }
Exemple #26
0
        internal ActionResult AppropriateView(ObjectAndControlData controlData, INakedObject nakedObject, INakedObjectAction action = null, string propertyName = null) {
            if (nakedObject == null) {
                // no object to go to 
                // if action on object go to that object. 
                // if action on collection go to collection 
                // if action on service go to last object 

                nakedObject = controlData.GetNakedObject();

                if (nakedObject.Specification.IsService) {
                    object lastObject = Session.LastObject(ObjectCache.ObjectFlag.BreadCrumb);
                    if (lastObject == null) {
                        TempData[IdHelper.NofMessages] = NakedObjectsContext.MessageBroker.Messages;
                        TempData[IdHelper.NofWarnings] = NakedObjectsContext.MessageBroker.Warnings;
                        return RedirectToAction(IdHelper.IndexAction, IdHelper.HomeName);
                    }

                    nakedObject = FrameworkHelper.GetNakedObject(lastObject);
                }
            }

            if (nakedObject.Specification.IsCollection && !nakedObject.Specification.IsParseable) {
                var collection = nakedObject.GetAsQueryable();
                int collectionSize = collection.Count();
                if (collectionSize == 1) {
                    // remove any paging data - to catch case where custom page has embedded standalone collection as paging data will confuse rendering 
                    ViewData.Remove(IdHelper.PagingData);
                    return View("ObjectView", collection.First());
                }

                nakedObject = Page(nakedObject, collectionSize, controlData, nakedObject.IsNotQueryable());
                action = action ?? ((CollectionMemento)nakedObject.Oid).Action;
                int page, pageSize;
                CurrentlyPaging(controlData, collectionSize, out page, out pageSize);
                var format = ViewData["NofCollectionFormat"] as string;
                return View("StandaloneTable", ActionResultModel.Create(action, nakedObject, page, pageSize, format));
            }
            // remove any paging data - to catch case where custom page has embedded standalone collection as paging data will confuse rendering   
            ViewData.Remove(IdHelper.PagingData);

            if (controlData.DataDict.Values.Contains("max")) {
                // maximizing an inline object - do not update history
                ViewData.Add("updateHistory", false);
            }

            return propertyName == null ? View(nakedObject.IsNotPersistent() ? "ObjectView" : "ViewNameSetAfterTransaction", nakedObject.Object) :
                                          View(nakedObject.IsNotPersistent() ? "PropertyView" : "ViewNameSetAfterTransaction", new PropertyViewModel(nakedObject.Object, propertyName));
        }
        protected string DisplaySingleProperty(ObjectAndControlData controlData, IDictionary<string, string> data) {
            if (Request.IsAjaxRequest()) {
                var nakedObject = controlData.GetNakedObject(Facade);
                if (controlData.SubAction == ObjectAndControlData.SubActionType.Redisplay) {
                    var assocs = nakedObject.Specification.Properties.Where(p => p.IsCollection && !p.Specification.IsParseable);
                    var item = assocs.SingleOrDefault(a => data.ContainsKey(a.Id));
                    return item == null ? null : item.Id;
                }
                if (controlData.ActionId == null) {
                    var assocs = nakedObject.Specification.Properties.Where(p => !p.IsCollection || p.Specification.IsParseable);
                    var item = assocs.SingleOrDefault(a => data.ContainsKey(a.Id));
                    return item == null ? null : item.Id;
                }
                {
                    var parms = controlData.GetAction(Facade).Parameters;
                    var item = parms.SingleOrDefault(p => data.ContainsKey(p.Id));
                    return item == null ? null : item.Id;
                }
            }

            return null;
        }