// Shows how view can get value of a specified field of any ModelA. internal string TextA(IModelA ia) { var a = (ModelA)ia; // TBD: Or maybe pass an empty string when missing. return(a != null ? a.TextA : null); }
public IModelA LoadA(int id) { IModelA modelA = _modelFactory.CreateModelA(); // fill modelA with data from database return(modelA); }
// Return "true" if succeeds. internal bool SetCurrentModelAByIndex(int index) { IModelA desiredA = GetOneModelA(index); if (desiredA != null) { CurrentA = desiredA; return(true); } else { return(false); } }
// --- represents a method used within view's workflow. --- public void SomeMethod() { // E.g., based on user selection, make a specified ModelA be "current". // (In practice, it would take a more complex scenario for view to want to hold an IModelA.) // (In this simple case, View could hold an index, call SetCurrentModelAByIndex, not need an IModelA object.) IModelA desiredA = vm.GetOneModelA(1); if (desiredA != null) { vm.CurrentA = desiredA; } else { // ... message to user ... } }
internal void SetCurrentModelA(IModelA desiredA) { // By design, IModelA always holds a ModelA (or null), so this cast always succeeds. _a = (ModelA)desiredA; }