public static void Insert(GanttDependencyModel dependency) { if (!UpdateDatabase) { var first = All().OrderByDescending(e => e.ID).FirstOrDefault(); var id = 0; if (first != null) { id = first.ID; } dependency.ID = id + 1; All().Insert(0, dependency); } else { using (var db = new SampleEntities()) { var entity = dependency.ToEntity(); db.GanttDependencies.AddObject(entity); db.SaveChanges(); dependency.ID = entity.ID; } } }
public static void Update(GanttDependencyModel dependency) { if (!UpdateDatabase) { var target = One(e => e.ID == dependency.ID); if (target != null) { target.Type = dependency.Type; target.PredecessorID = dependency.PredecessorID; target.SuccessorID = dependency.SuccessorID; } } else { using (var db = new SampleEntities()) { var entity = dependency.ToEntity(); db.GanttDependencies.Attach(entity); db.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified); db.SaveChanges(); } } }
public static void Delete(GanttDependencyModel dependency) { if (!UpdateDatabase) { var target = One(p => p.ID == dependency.ID); if (target != null) { All().Remove(target); } } else { using (var db = new SampleEntities()) { var entity = dependency.ToEntity(); db.GanttDependencies.Attach(entity); db.GanttDependencies.DeleteObject(entity); db.SaveChanges(); } } }
public static void Insert(GanttDependencyModel dependency) { if (!UpdateDatabase) { var first = All().OrderByDescending(e => e.ID).FirstOrDefault(); var id = 0; if (first != null) { id = first.ID; } dependency.ID = id + 1; All().Insert(0, dependency); } else { using (var db = new SampleEntities()) { var entity = dependency.ToEntity(); db.GanttDependencies.AddObject(entity); db.SaveChanges(); dependency.ID = entity.ID; } } }
public static void Delete(GanttDependencyModel dependency) { if (!UpdateDatabase) { var target = One(p => p.ID == dependency.ID); if (target != null) { All().Remove(target); } } else { using (var db = new SampleEntities()) { var entity = dependency.ToEntity(); db.GanttDependencies.Attach(entity); db.GanttDependencies.DeleteObject(entity); db.SaveChanges(); } } }
public static void Update(GanttDependencyModel dependency) { if (!UpdateDatabase) { var target = One(e => e.ID == dependency.ID); if (target != null) { target.Type = dependency.Type; target.PredecessorID = dependency.PredecessorID; target.SuccessorID = dependency.SuccessorID; } } else { using (var db = new SampleEntities()) { var entity = dependency.ToEntity(); db.GanttDependencies.Attach(entity); db.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified); db.SaveChanges(); } } }