private void OnOkCommand(object p) { EDbActionResult res = AddNewEmployee(); if ((res == EDbActionResult.SuccessAdd) || (res == EDbActionResult.SuccessChange)) { OperationText = (res == EDbActionResult.SuccessAdd) ? "Сотрудник добавлен в базу." : "Данные сохранены."; SetOperationTextColor(Colors.Green); } else if (res == EDbActionResult.FailAlreadyExists) { OperationText = "Такой сотрудник уже занесен в базу."; SetOperationTextColor(Colors.Red); } else if (res == EDbActionResult.FailEmployeeType) { OperationText = "Установка категории Employee невозможна: у сотрудника есть подчиненные."; SetOperationTextColor(Colors.Red); } else if (res == EDbActionResult.FailManagerIsSubordinate) { OperationText = ERROR_MESSAGE_MANAGER_CONFLICT; SetOperationTextColor(Colors.Red); } else { OperationText = ""; SetOperationTextColor(Colors.Black); } }
private EDbActionResult AddNewEmployee() { EDbActionResult res = EDbActionResult.Nothing; if (mAddingMode) { var aAddRes = mEmployeeListDBConfiguration.CreateNewEmployee(out Employee aEmployee, EmployeeListDBConfiguration.EEmployeeUpdateOption.SaveChanges, mSelectedSalaryPlanItem.Id, mLastName, mFirstName, mMiddleName, mEmploymentDate, mSelectedManagerItem); if (aAddRes == EmployeeListDBConfiguration.EEmployeeUpdateResult.Success) { res = EDbActionResult.SuccessAdd; mResultSalaryDateChanged = true; mEmployeesItemsSource = new ObservableCollection <Employee>(mEmployeeListDBConfiguration.EmployeeListDB.Employees); RaisePropertyChanged("EmployeesItemsSource"); } else if (aAddRes == EmployeeListDBConfiguration.EEmployeeUpdateResult.FailAlreadyExists) { res = EDbActionResult.FailAlreadyExists; } } else { var aEmployee = mSelectedEmployeesItem; if (aEmployee != null) { var aAddRes = mEmployeeListDBConfiguration.UpdateEmployee(aEmployee, EmployeeListDBConfiguration.EEmployeeUpdateOption.SaveChanges, mSelectedSalaryPlanItem.Id, mLastName, mFirstName, mMiddleName, mEmploymentDate, mSelectedManagerItem); if (aAddRes == EmployeeListDBConfiguration.EEmployeeUpdateResult.Success) { res = EDbActionResult.SuccessChange; mResultSalaryDateChanged = true; mEmployeesItemsSource = new ObservableCollection <Employee>(mEmployeeListDBConfiguration.EmployeeListDB.Employees); RaisePropertyChanged("EmployeesItemsSource"); } else { switch (aAddRes) { case EmployeeListDBConfiguration.EEmployeeUpdateResult.FailEmployeeType: res = EDbActionResult.FailEmployeeType; break; case EmployeeListDBConfiguration.EEmployeeUpdateResult.FailManagerIsSubordinate: res = EDbActionResult.FailManagerIsSubordinate; break; } } } } return(res); }