示例#1
0
        public CreateProjectViewModel()
        {
            this._factory         = new ProjectFactory();
            this._costumerCatalog = CostumerCatalog.Instance;

            this.AddCommand = new RelayCommand <Project>(
                this._factory.Create,
                project => this._factory.CanCreate(this._factory.NewProject));
        }
示例#2
0
        public CostumerViewModel()
        {
            this._projectCatalog  = ProjectCatalog.Instance;
            this._costumerCatalog = CostumerCatalog.Instance;
            this.OnPropertyChanged(nameof(this.CostumerList));

            this.DeleteCustomerCommand = new RelayCommand <Costumer>(
                () =>
            {
                this._costumerCatalog.Remove(
                    this
                    ._selectedCostumer);
                this._selectedCostumer = null;
                this.OnPropertyChanged(
                    nameof(
                        this.CostumerList
                        ));
            },
                costumer => this.ProjectsForCostumer.Count == 0);
            this.UpdateCustomerCommand = new RelayCommand <Costumer>(
                () =>
            {
                int id = this._selectedCostumer.CostumerId;
                this._costumerCatalog.Update(
                    this
                    ._selectedCostumer);
                this.OnPropertyChanged(
                    nameof(
                        this.CostumerList
                        ));
                this.SelectedCostumer =
                    this.CostumerList.Find(
                        costumer =>
                        costumer
                        .CostumerId
                        == id);
            },
                costumer => this.Edit);
            this.Edit           = false;
            this.RefreshCommand = new RelayCommand <bool>(
                () =>
            {
                this._projectCatalog.Load();
                this._costumerCatalog.Load();
                this.OnPropertyChanged(nameof(this.CostumerList));
                this.OnPropertyChanged(nameof(this.SelectedCostumer));
                this.OnPropertyChanged(
                    nameof(this.ProjectsForCostumer
                           ));
            });
        }
        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
                           ));
            });
        }
 public CostumerFactory()
 {
     this.NewCostumer      = new Costumer();
     this._costumerCatalog = CostumerCatalog.Instance;
 }