public static ModelGraph FromDirty(IEnumerable <Model> models) { var graph = new ModelGraph(); Stack <Model> parentStack = new Stack <Model> (); Stack <IEnumerable <Model> > modelsStack = new Stack <IEnumerable <Model> > (); parentStack.Push(null); modelsStack.Push(models); Model parent; while (parentStack.Count > 0) { parent = parentStack.Pop(); models = modelsStack.Pop() .Where((m) => m != null && (m.IsDirty || m.RemoteId == null || m.DeletedAt != null)); foreach (var model in models) { parentStack.Push(model); modelsStack.Push(model.GetAllForeignModels().Values); graph.Add(model, parent); } } return(graph); }
public static ModelGraph FromDirty (IEnumerable<Model> models) { var graph = new ModelGraph (); Stack<Model> parentStack = new Stack<Model> (); Stack<IEnumerable<Model>> modelsStack = new Stack<IEnumerable<Model>> (); parentStack.Push (null); modelsStack.Push (models); Model parent; while (parentStack.Count > 0) { parent = parentStack.Pop (); models = modelsStack.Pop () .Where ((m) => m != null && (m.IsDirty || m.RemoteId == null || m.DeletedAt != null)); foreach (var model in models) { parentStack.Push (model); modelsStack.Push (model.GetAllForeignModels ().Values); graph.Add (model, parent); } } return graph; }