public static void Insert(OrgChartShape shape) { if (!UpdateDatabase) { var first = All().OrderByDescending(e => e.Id).FirstOrDefault(); var id = 0; if (first != null) { id = first.Id; } shape.Id = id + 1; All().Insert(0, shape); } else { using (var db = new SampleEntities()) { db.OrgChartShapes.AddObject(shape); db.SaveChanges(); } } }
public static void Delete(OrgChartShape shape) { if (!UpdateDatabase) { var target = One(p => p.Id == shape.Id); if (target != null) { All().Remove(target); } } else { using (var db = new SampleEntities()) { db.OrgChartShapes.Attach(shape); db.OrgChartShapes.DeleteObject(shape); db.SaveChanges(); } } }
public static void Update(OrgChartShape shape) { if (!UpdateDatabase) { var target = One(e => e.Id == shape.Id); if (target != null) { target.JobTitle = shape.JobTitle; target.Color = shape.Color; } } else { using (var db = new SampleEntities()) { db.OrgChartShapes.Attach(shape); db.ObjectStateManager.ChangeObjectState(shape, EntityState.Modified); db.SaveChanges(); } } }