コード例 #1
0
        public EmployeesListViewModel()
        {
            if (DesignerProperties.GetIsInDesignMode(
                new System.Windows.DependencyObject())) return;

            try
            {
                var employees = db.Employees.Include(e => e.Suburb);
                Employees = new ObservableCollection<Employee>(employees.ToList());
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message.ToString());
            }
            try
            {
                var suburbs = db.Suburbs.ToList();
                Suburbs = new ObservableCollection<Suburb>(suburbs);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message.ToString());
            }

            _newEmployee = new Employee();
            _searchResults = new ObservableCollection<Employee>();

            DeleteEmployeeCommand = new RelayCommand<Employee>(onDeleteEmployee);
            UpdateEmployeeCommand = new RelayCommand<Employee>(onUpdateEmployee);
            AddEmployeeCommand = new RelayCommand<Employee>(onAddEmployee);
            FindEmployeesCommand = new RelayCommand<string>(onFindEmployees);
            SelectEmployeeCommand = new RelayCommand<Employee>(onSelectEmployee);
        }
コード例 #2
0
        public void onUpdateEmployee(Employee emp)
        {
            var employee = emp;

            if (employee != null)
            {
                db.Entry(employee).State = EntityState.Modified;
                db.SaveChanges();
                Employees = UpdateEmployeesCollection(Employees);

                MessageBoxResult msgBox = MessageBox.Show("Changes Saved", "Success");

            }
        }
コード例 #3
0
        public void onDeleteEmployee(Employee emp)
        {
            if (emp != null)
            {
                MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure you wish to delete this employee?", "Confirm Delete", System.Windows.MessageBoxButton.YesNo);

                if (messageBoxResult == MessageBoxResult.Yes)
                {
                    int employeeid = emp.employeeID;
                    Employee empToRemove = (Employee)Employees.Single(e => e.employeeID == employeeid);

                    db.Employees.Remove(empToRemove);
                    db.SaveChanges();
                    Employees = UpdateEmployeesCollection(Employees);
                }
            }
        }
コード例 #4
0
 public void onSelectEmployee(Employee emp)
 {
     SelectedEmployee = emp;
 }
コード例 #5
0
        public void onAddEmployee(Employee emp)
        {
            var newEmployee = emp;
            var empSub = from s in db.Suburbs where s.suburbID == emp.suburbID select s;
            newEmployee.Suburb = (Suburb)empSub.Single();

            if (newEmployee != null)
            {
                db.Employees.Add(newEmployee);
                db.SaveChanges();
                Employees = UpdateEmployeesCollection(Employees);
                MessageBoxResult msgBox = MessageBox.Show("Employee Added", "Success");
            }
        }