/// <summary> /// returns employees with position from BD /// <example> /// <code> /// IQueryable<EmployAndPosition> t = BoardDB.GetEmployeesAndPosition(); /// </code> /// </example> /// </summary> public static IQueryable <EmployAndPosition> GetEmployeesAndPosition() { var positions = BoardDB.GetPositions(); var employees = BoardDB.GetEmployees(); return(employees .Join(positions, employ => employ.positionId, position => position.positionId, (e, p) => new EmployAndPosition(e, p))); }
///<summary> /// Get Positions from DB and add them to Board.PositionsList Dictionary /// <example> /// <code> /// Board.GetPositions(); /// </code> /// </example> /// </summary> public static void GetPositions() { Board.PositionsList.Clear(); var positions = BoardDB.GetPositions(); foreach (var p in positions) { if (p.positionId != 0) { Board.PositionsList.Add(p); } } }
private void btnAdd_Click(object sender, RoutedEventArgs e) { try { string name = txtName.Text; var position = new Position(name); BoardDB.GetPositions().Add(position); if (BoardDB.GetDB().SaveChanges() == 1) { Board.PositionsList.Add(position); this.NavigationService.GoBack(); } else { lblError.Content = "Błąd dodawania"; } } catch (InvalidOperationException err) { lblError.Content = err.Message; } }
private void btnRemove_Click(object sender, RoutedEventArgs e) { int index = ListOfPositions.SelectedIndex; if (index >= 0) { var position = Board.PositionsList[index]; if (position.positionId != 0) { BoardDB.GetPositions().Remove(position); if (BoardDB.GetDB().SaveChanges() == 1) { Board.PositionsList.RemoveAt(index); } } else { lblError.Content = "Nie można usunąć"; } } }