Beispiel #1
0
        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)));
        }