public ActionResult SaveForm(ViewModelRootContainer postedViewContainer) { DataSelectionViewModel currentViewModel = TempData[TempDataModelKey] as DataSelectionViewModel; // Reconcile changes BindToDataModel(currentViewModel, postedViewContainer); // Save changes foreach (IModelRootInstance instance in currentViewModel.CurrentSubject.Instances) { eavClient.SaveData(instance); } // Get rid of deleted items TrimDataModel(currentViewModel.CurrentContainer); // Refresh the view object currentViewModel.RegenerateViewContainer(); currentViewModel.CurrentViewContainer.DisplayMode = postedViewContainer.DisplayMode; currentViewModel.CurrentViewContainer.Enabled = postedViewContainer.Enabled; if (currentViewModel.CurrentViewContainer.DisplayMode != DisplayMode.Running) { currentViewModel.CurrentViewContainer.SelectedInstanceID = currentViewModel.CurrentViewContainer.Instances.Min(it => it.InstanceID.GetValueOrDefault()); currentViewModel.CurrentViewContainer.CurrentInstance = currentViewModel.CurrentViewContainer.Instances.SingleOrDefault(it => it.InstanceID == currentViewModel.CurrentViewContainer.SelectedInstanceID); } TempData[TempDataModelKey] = currentViewModel; return(RedirectToAction("PostRedirectGetTarget", new { view = currentViewModel.CurrentViewContainer.DisplayMode == DisplayMode.Singleton ? "DisplaySingletonContainer" : (currentViewModel.CurrentViewContainer.DisplayMode == DisplayMode.Recurring ? "DisplayRecurringContainer" : "DisplayRunningContainer") })); }
public ActionResult RetrieveInstance(ViewModelRootContainer postedViewContainer) { DataSelectionViewModel currentViewModel = TempData[TempDataModelKey] as DataSelectionViewModel; // This will keep ASP from holding on to any values when we run the new // instance through our partial view. ModelState.Clear(); // Make sure we keep the posted version to capture any changes currentViewModel.CurrentViewContainer.Instances.Remove(currentViewModel.CurrentViewContainer.Instances.Single(it => it.InstanceID == postedViewContainer.CurrentInstance.InstanceID)); currentViewModel.CurrentViewContainer.Instances.Add(postedViewContainer.CurrentInstance); // Now switch instances currentViewModel.CurrentViewContainer.SelectedInstanceID = postedViewContainer.SelectedInstanceID; currentViewModel.CurrentViewContainer.CurrentInstance = currentViewModel.CurrentViewContainer.Instances.SingleOrDefault(it => it.InstanceID == currentViewModel.CurrentViewContainer.SelectedInstanceID); TempData[TempDataModelKey] = currentViewModel; return(PartialView("SingletonInstance", currentViewModel.CurrentViewContainer)); }
private void BindToDataModel(DataSelectionViewModel currentDataSelectionViewModel, ViewModelRootContainer postedViewContainer) { if (currentDataSelectionViewModel.CurrentViewContainer.DisplayMode != DisplayMode.Running) { currentDataSelectionViewModel.CurrentViewContainer.Instances.Remove(currentDataSelectionViewModel.CurrentViewContainer.Instances.Single(it => it.InstanceID == postedViewContainer.CurrentInstance.InstanceID)); currentDataSelectionViewModel.CurrentViewContainer.Instances.Add(postedViewContainer.CurrentInstance); } else { currentDataSelectionViewModel.CurrentViewContainer = postedViewContainer; } currentDataSelectionViewModel.CurrentViewContainer.Trim(); var dataInstances = currentDataSelectionViewModel.CurrentSubject.Instances.GroupJoin(currentDataSelectionViewModel.CurrentViewContainer.Instances, left => left.InstanceID, right => right.InstanceID, (left, right) => new { ModelInstance = left, ViewInstance = right.FirstOrDefault() }); var viewInstances = currentDataSelectionViewModel.CurrentViewContainer.Instances.GroupJoin(currentDataSelectionViewModel.CurrentSubject.Instances, left => left.InstanceID, right => right.InstanceID, (left, right) => new { ModelInstance = right.FirstOrDefault(), ViewInstance = left }); foreach (var item in dataInstances.Union(viewInstances)) { BindToModelInstance(currentDataSelectionViewModel.CurrentContainer, currentDataSelectionViewModel.CurrentSubject, null, item.ModelInstance, null, item.ViewInstance); } }