private ActionResult Find(ObjectAndControlData controlData) { string spec = controlData.DataDict["spec"]; string contextObjectId = controlData.DataDict["contextObjectId"]; string propertyName = controlData.DataDict["propertyName"]; string contextActionId = controlData.DataDict["contextActionId"]; var objectSet = Session.CachedObjectsOfType(NakedObjectsContext, NakedObjectsContext.MetamodelManager.GetSpecification(spec)).ToList(); if (!objectSet.Any()) { Log.InfoFormat("No Cached objects of type {0} found", spec); NakedObjectsContext.MessageBroker.AddWarning("No objects of appropriate type viewed recently"); } var contextNakedObject = FilterCollection(NakedObjectsContext.GetNakedObjectFromId(contextObjectId), controlData); var contextAction = string.IsNullOrEmpty(contextActionId) ? null : NakedObjectsContext.GetActionFromId(contextActionId); if (objectSet.Count == 1) { var selectedItem = new Dictionary <string, string> { { propertyName, NakedObjectsContext.GetObjectId(objectSet.Single()) } }; return(SelectSingleItem(contextNakedObject, contextAction, controlData, selectedItem)); } return(View(Request.IsAjaxRequest() ? "PropertyEdit" : "FormWithSelections", new FindViewModel { ActionResult = objectSet, ContextObject = contextNakedObject.Object, ContextAction = contextAction, PropertyName = propertyName })); }
private ActionResult ActionAsFind(ObjectAndControlData controlData) { string targetActionId = controlData.DataDict["targetActionId"]; string targetObjectId = controlData.DataDict["targetObjectId"]; string contextObjectId = controlData.DataDict["contextObjectId"]; string propertyName = controlData.DataDict["propertyName"]; string contextActionId = controlData.DataDict["contextActionId"]; INakedObject targetNakedObject = NakedObjectsContext.GetNakedObjectFromId(targetObjectId); INakedObject contextNakedObject = FilterCollection(NakedObjectsContext.GetNakedObjectFromId(contextObjectId), controlData); IActionSpec targetAction = NakedObjectsContext.GetActions(targetNakedObject).Single(a => a.Id == targetActionId); IActionSpec contextAction = string.IsNullOrEmpty(contextActionId) ? null : NakedObjectsContext.GetActionFromId(contextActionId); SetContextObjectAsParameterValue(targetAction, contextNakedObject); if (targetAction.ParameterCount == 0) { INakedObject result = Execute(targetAction, targetNakedObject, new INakedObject[] {}); IEnumerable resultAsEnumerable = GetResultAsEnumerable(result, contextAction, propertyName); if (resultAsEnumerable.Cast <object>().Count() == 1 && result.ResolveState.IsPersistent()) { var selectedItem = new Dictionary <string, string> { { propertyName, NakedObjectsContext.GetObjectId(resultAsEnumerable.Cast <object>().Single()) } }; return(SelectSingleItem(contextNakedObject, contextAction, controlData, selectedItem)); } string view = Request.IsAjaxRequest() ? "PropertyEdit" : "FormWithSelections"; return(View(view, new FindViewModel { ActionResult = resultAsEnumerable, TargetObject = targetNakedObject.Object, ContextObject = contextNakedObject.Object, TargetAction = targetAction, ContextAction = contextAction, PropertyName = propertyName })); } SetDefaults(targetNakedObject, targetAction); return(View(Request.IsAjaxRequest() ? "PropertyEdit" : "FormWithFinderDialog", new FindViewModel { TargetObject = targetNakedObject.Object, ContextObject = contextNakedObject.Object, TargetAction = targetAction, ContextAction = contextAction, PropertyName = propertyName })); }
private ActionResult InvokeActionAsFind(ObjectAndControlData controlData) { string targetActionId = controlData.DataDict["targetActionId"]; string targetObjectId = controlData.DataDict["targetObjectId"]; string contextObjectId = controlData.DataDict["contextObjectId"]; string propertyName = controlData.DataDict["propertyName"]; string contextActionId = controlData.DataDict["contextActionId"]; INakedObject targetNakedObject = NakedObjectsContext.GetNakedObjectFromId(targetObjectId); INakedObject contextNakedObject = FilterCollection(NakedObjectsContext.GetNakedObjectFromId(contextObjectId), controlData); IActionSpec targetAction = NakedObjectsContext.GetActions(targetNakedObject).Single(a => a.Id == targetActionId); IActionSpec contextAction = string.IsNullOrEmpty(contextActionId) ? null : NakedObjectsContext.GetActionFromId(contextActionId); SetContextObjectAsParameterValue(targetAction, contextNakedObject); if (ValidateParameters(targetNakedObject, targetAction, controlData)) { IEnumerable <INakedObject> parms = GetParameterValues(targetAction, controlData); INakedObject result = targetAction.Execute(targetNakedObject, parms.ToArray()); if (result != null) { IEnumerable resultAsEnumerable = !result.Spec.IsCollection ? new List <object> { result.Object } : (IEnumerable)result.Object; if (resultAsEnumerable.Cast <object>().Count() == 1) { var selectedItem = new Dictionary <string, string> { { propertyName, NakedObjectsContext.GetObjectId(resultAsEnumerable.Cast <object>().Single()) } }; return(SelectSingleItem(contextNakedObject, contextAction, controlData, selectedItem)); } string view = Request.IsAjaxRequest() ? "PropertyEdit" : "FormWithSelections"; return(View(view, new FindViewModel { ActionResult = resultAsEnumerable, TargetObject = targetNakedObject.Object, ContextObject = contextNakedObject.Object, TargetAction = targetAction, ContextAction = contextAction, PropertyName = propertyName })); } } return(View(Request.IsAjaxRequest() ? "PropertyEdit" : "FormWithFinderDialog", new FindViewModel { TargetObject = targetNakedObject.Object, ContextObject = contextNakedObject.Object, TargetAction = targetAction, ContextAction = contextAction, PropertyName = propertyName })); }
private ActionResult InvokeActionAsSave(ObjectAndControlData controlData) { var form = controlData.Form; string targetActionId = controlData.DataDict["targetActionId"]; string targetObjectId = controlData.DataDict["targetObjectId"]; string contextObjectId = controlData.DataDict["contextObjectId"]; string propertyName = controlData.DataDict["propertyName"]; string contextActionId = controlData.DataDict["contextActionId"]; string subEditObjectId = controlData.DataDict["subEditObjectId"]; INakedObject targetNakedObject = NakedObjectsContext.GetNakedObjectFromId(targetObjectId); INakedObject contextNakedObject = FilterCollection(NakedObjectsContext.GetNakedObjectFromId(contextObjectId), controlData); IActionSpec targetAction = NakedObjectsContext.GetActions(targetNakedObject).Single(a => a.Id == targetActionId); IActionSpec contextAction = string.IsNullOrEmpty(contextActionId) ? null : NakedObjectsContext.GetActionFromId(contextActionId); INakedObject subEditObject = NakedObjectsContext.GetNakedObjectFromId(subEditObjectId); if (ValidateChanges(subEditObject, controlData)) { ApplyChanges(subEditObject, controlData); } // tempting to try to associate the new object at once - however it is still transient until the end of the // transaction and so association may not work (possible persistent to transient). By doing this we split into two transactions // and so all OK. IEnumerable resultAsEnumerable = new List <object> { subEditObject.Object }; return(View(Request.IsAjaxRequest() ? "PropertyEdit" : "FormWithSelections", new FindViewModel { ActionResult = resultAsEnumerable, TargetObject = targetNakedObject.Object, ContextObject = contextNakedObject.Object, TargetAction = targetAction, ContextAction = contextAction, PropertyName = propertyName })); }