public void RemoveItem <T>(object item) where T : class { using (var db = new MediaPlayerDbContext()) { db.Remove(item as T); db.SaveChanges(); } }
public int AddItem <T>(object item) where T : class { using (var db = new MediaPlayerDbContext()) { db.Add(item as T); db.SaveChanges(); return((item is AbstractObjectWithID) ? (item as AbstractObjectWithID).Id : 0); } }
public void UpdateItem <T>(object item) where T : class { using (var db = new MediaPlayerDbContext()) { if (item is Tag) { var tag = item as Tag; if (tag.ParentTag != null && tag.ParentTag.Id < 0) { tag.ParentTag = null; db.Entry(item).Reference("ParentTag").IsModified = true; } } db.Update(item as T); db.SaveChanges(); } }