public void RemoveActiveVM(int _dashboardId, string _vmId) { using (var context = new CADContext()) { ActiveVM vm = context.ActiveVMs.FirstOrDefault(iv => iv.DashboardId == _dashboardId && iv.VMId == _vmId); if (vm != null) { context.ActiveVMs.Remove(vm); context.SaveChanges(); } } }
public void AddActiveVM(int _dashboardId, string _vmId) { using (var context = new CADContext()) { ActiveVM vm = context.ActiveVMs.FirstOrDefault(iv => iv.DashboardId == _dashboardId && iv.VMId == _vmId); if (vm == null) { vm = new ActiveVM(); vm.DashboardId = _dashboardId; vm.VMId = _vmId; context.ActiveVMs.Add(vm); context.SaveChanges(); vm = null; } } }