public EmployeeViewModel() { this._projectCatalog = ProjectCatalog.Instance; this._employeeCatalog = EmployeeCatalog.Instance; this._projectsForEmployee = ProjectForEmployeesCatalog.Instance; this._canEdit = false; this.DeleteCommand = new RelayCommand <Employee>( () => { this._employeeCatalog.Remove( this ._selectedEmployee); this._selectedEmployee = null; this.OnPropertyChanged(nameof(this.EmployeeList)); }, employee => this._employeeCatalog.EmployeeList.Contains( this .SelectedEmployee)); this.UpdateCommand = new RelayCommand <Employee>( () => { int id = this._selectedEmployee.EmployeeId; this._employeeCatalog.Update( this ._selectedEmployee); this.OnPropertyChanged(nameof(this.EmployeeList)); this.SelectedEmployee = this.EmployeeList.Find( employee => employee.EmployeeId == id); }, employee => this.Edit); this.RefreshCommand = new RelayCommand <bool>( () => { this._projectCatalog.Load(); this._employeeCatalog.Load(); this._selectedEmployee = null; this.OnPropertyChanged(nameof(this.EmployeeList)); }); }
public ProjectViewModel() { this._projectCatalog = ProjectCatalog.Instance; this._employeeCatalog = EmployeeCatalog.Instance; this._costumerCatalog = CostumerCatalog.Instance; this._projectForEmployeesCatalog = ProjectForEmployeesCatalog.Instance; this._addEmployee = new Employee(); this._projectForEmployee = new ProjectsForEmployee(); this.DeleteCommand = new RelayCommand <Project>( () => { this._projectCatalog.Remove(this.SelectedProject); this._selectedProject = null; this.OnPropertyChanged(nameof(this.ProjectList)); }, project => this.SelectedProject != null); this.UpdateCommand = new RelayCommand <Project>( () => { int id = this._selectedProject.ProjectId; this._projectCatalog.Update(this._selectedProject); this.OnPropertyChanged(nameof(this.ProjectList)); this.SelectedProject = this.ProjectList.Find( project => project.ProjectId == id); foreach (ProjectsForEmployee projectsForEmployee in this.EmployeesForProject) { this._projectForEmployeesCatalog.Update( projectsForEmployee); this._employeeCatalog.Load(); } }, project => this.Edit); this.AddEmployeeCommand = new RelayCommand <Employee>( () => { this._projectForEmployee.ProjectId = this._selectedProject.ProjectId; this._projectForEmployee.EmployeeId = this._addEmployee.EmployeeId; this._projectForEmployee.IsLeader = false; this._projectForEmployeesCatalog.Add( this ._projectForEmployee); this._employeeCatalog.Load(); this._addEmployee = new Employee(); this.OnPropertyChanged( nameof( this.AddEmployeeName )); this.OnPropertyChanged( nameof( this .EmployeesForProject )); this.AddEmployeeCommand .RaiseCanExecuteChanged(); }, addEmployee => { if (this._addEmployee.Name == null || this.EmployeesForProject.Exists( employee => employee .EmployeeId == this ._addEmployee .EmployeeId) ) { return(false); } if (this._employeeCatalog.EmployeeList.Exists( employee => employee .Name == this ._addEmployee .Name) && this.Edit) { return(true); } return(false); }); this.DeleteEmployeeCommand = new RelayCommand <Employee>( () => { this._projectForEmployeesCatalog.Remove( this ._selectedEmployee .ProjectsForEmployees .First( employee => employee .ProjectId == this ._selectedProject .ProjectId)); this._employeeCatalog.Load(); this._selectedEmployee = null; this.OnPropertyChanged( nameof( this .EmployeesForProject )); this.DeleteEmployeeCommand .RaiseCanExecuteChanged(); }, employee => this._selectedEmployee != null && this._selectedProject != null && this.Edit); this._canEdit = false; this.RefreshCommand = new RelayCommand <bool>( () => { this._projectCatalog.Load(); this._employeeCatalog.Load(); this._costumerCatalog.Load(); this.OnPropertyChanged(nameof(this.ProjectList)); this.OnPropertyChanged(nameof(this.SelectedProject)); this.OnPropertyChanged( nameof(this.EmployeesForProject )); }); }