Ejemplo n.º 1
0
        void OnEmployeeAddedToRepository(object sender, EmployeeAddedEventArgs e)
        {
            // TODO: IDK if we should pass true or false as the third param.
            var viewModel = new EmployeeWrapperViewModel(e.NewEmployee, _employeeRepository, false);

            this.AllEmployees.Add(viewModel);
        }
Ejemplo n.º 2
0
        private void ShowViewDialog(object id)
        {
            if (!(id is int))
            {
                throw new ArgumentException(Resources.EmployeeWrapperViewModel_Exception_ViewWrongParam);
            }

            var modal = new Window();
            var view  = new SingleEmployeeView();

            var employeeToShow = GetEmployeeByID((int)id);

            if (employeeToShow == null)
            {
                throw new ArgumentNullException(String.Format(Resources.EmployeeWrapperViewModel_Exception_EmployeeIDNotFound, (int)id));
            }

            var currentEmployee = new EmployeeWrapperViewModel(Employee.CreateNewEmployee(), _employeeRepository, false);

            CopyEmployeeFields(employeeToShow, currentEmployee);

            // Modal's chrome properties
            modal.Title  = (currentEmployee.Gender == "Mujer" ? "Empleada: " : "Empleado: ") + currentEmployee.FullName;
            modal.Height = 500;
            modal.Width  = 400;

            modal.DataContext = currentEmployee;
            modal.Content     = view;

            modal.Show();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Saves the employee after clicking the Save button in the modal.
 /// </summary>
 /// <param name="newData">The wrapper of a temporal Employee object.</param>
 /// <param name="employee">The employee in the repository that is going to be actually saved</param>
 /// <param name="original">The original context where the employee resides, so it can nortify changes.</param>
 void SaveEmployeeBeingEdited(EmployeeWrapperViewModel newData, Employee employee, EmployeeWrapperViewModel original)
 {
     employee.FirstName         = newData.FirstName;
     employee.LastName          = newData.LastName;
     employee.Gender            = newData._employee.Gender;
     employee.Birthdate.Day     = newData.Day;
     employee.Birthdate.Month   = newData.Month;
     employee.Birthdate.Year    = newData.Year;
     employee.Email             = newData.Email;
     employee.Phone             = newData.Phone;
     employee.Pay               = newData.Pay;
     employee.WorkTime          = newData.WorkTime;
     employee.Address           = newData.Address;
     employee.UserType          = newData.UserType;
     employee.CurrentlyEmployed = newData.CurrentlyEmployed;
     //original.OnPropertyChanged("FirstName");
     original.OnPropertyChanged("DisplayName");
     original.OnPropertyChanged("Gender");
     original.OnPropertyChanged("Birthdate");
     original.OnPropertyChanged("Email");
     original.OnPropertyChanged("Phone");
     original.OnPropertyChanged("PrettyPay");
     original.OnPropertyChanged("WorkTime");
     original.OnPropertyChanged("Address");
     original.OnPropertyChanged("UserType");
     original.OnPropertyChanged("CurrentlyEmployed");
     // TODO: Do a thorough testing of the app.
     //newData.CleanForm();
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Method that shows a modal dialog that allow us to edit an employee.
        /// Currently it's using the Show() so it doesn't blocks.
        /// </summary>
        /// <param name="id">Employee's ID</param>
        void ShowEditDialog(object id)
        {
            if (!(id is int))
            {
                throw new ArgumentException(Resources.EmployeeWrapperViewModel_Exception_EditWrongParam);
            }
            _isEditingUser = true;
            Window modal = new Window();
            // Create the forms to edit
            var view = new AddEmployeeView();

            modal.Width  = 500;
            modal.Height = 400;
            modal.WindowStartupLocation = WindowStartupLocation.CenterScreen;

            _isModalSpawned = true; // States a modal is currently being used.
            OnPropertyChanged("DeleteToolTip");
            modal.Activated   += Modal_Activated;
            modal.Deactivated += Modal_Deactivated;
            modal.Closed      += Modal_Closed;

            // Search for the employee by id
            var listEmp        = _employeeRepository.GetEmployees();
            var employeeEdited = (from emps in listEmp where emps.ID.Equals(id) select emps).ToList();

            _employeeBeingEdited = employeeEdited[0];
            _orignalData         = this;

            Debug.Print("Actual employee before editing");
            PrintEmployeeFields(employeeEdited[0]);

            // Initialize the Employee object that's going to be used as a temporal.
            if (!_editingCurrentEmployeeIsInitialized)
            {
                _editingCurrentEmployee = new EmployeeWrapperViewModel(Employee.CreateNewEmployee(), _employeeRepository, false);
                _editingCurrentEmployeeIsInitialized = true;
            }

            CopyEmployeeFields(employeeEdited[0], _editingCurrentEmployee);
            Debug.Print("Editing Current Employee");
            PrintEmployeeFields(_editingCurrentEmployee._employee);
            modal.DataContext = _editingCurrentEmployee;

            modal.Content = view;
            modal.Title   = "Edit Employee";
            //modal.ShowDialog();

            modal.Show();

            // Check if the fields are different to the original Employee element, if so:
            // 1. The Save button can performs.
            // 2. If the users close the window without saving ask him if he wanna save
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Copies the employee currently being edited to a temporal variable so it can be populated
        /// all the fields and Comboboxes of the edit modal dialog.
        /// </summary>
        /// <param name="employee"></param>
        /// <param name="temp"></param>
        void CopyEmployeeFields(Employee employee, EmployeeWrapperViewModel temp)
        {
            temp.LastUserSaved    = null;
            _temporalEmployeeID   = employee.ID;
            temp.FirstName        = employee.FirstName;
            temp.LastName         = employee.LastName;
            temp._employee.Gender = employee.Gender;
            temp.Day                         = employee.Birthdate.Day;
            temp.Birthdate                   = employee.Birthdate;
            temp.Month                       = employee.Birthdate.Month;
            temp.Year                        = employee.Birthdate.Year;
            temp.Email                       = employee.Email;
            temp.Phone                       = employee.Phone;
            temp.Pay                         = employee.Pay;
            temp._employee.WorkTime          = employee.WorkTime;
            temp.Address                     = employee.Address;
            temp.WorkTimeType                = employee.WorkTime;
            temp._employee.CurrentlyEmployed = employee.CurrentlyEmployed; // Bypassed to avoid the validation.

            /* _selectedUserType assignment to bypass the set accessor of UserType property and therefore
             * the CanChangeUser validation. This caused to show the modal: "Can't edit User type because it's the last admin".
             * Happened when we open the edit view of the last admin, closed it, and then open any other user.
             */
            temp._selectedUserType = employee.UserType;

            temp.UserType = employee.UserType;

            // TODO: Here put default values for the comboboxes Birthdate and Jornada if null.
            // TODO: I think they're some validate functions that repeats this functionality?
            // Gender == true means Female
            if (employee.Gender)
            {
                temp.GenderType = Resources.EmployeeWrapperViewModel_GenderTypeOptions_Female;
            }
            else
            {
                temp.GenderType = Resources.EmployeeWrapperViewModel_GenderTypeOptions_Male;
            }

            if (String.IsNullOrEmpty(temp.Day) || String.IsNullOrEmpty(temp.Month) || String.IsNullOrEmpty(temp.Year))
            {
                temp.Day   = Resources.BirthDate_Combobox_Day;
                temp.Month = Resources.BirthDate_Combobox_Month;
                temp.Year  = Resources.BirthDate_Combobox_Year;
            }

            // TODO: The following statement can be wrapped into a IsValid function for a WorkTime value.
            if (String.IsNullOrEmpty(employee.WorkTime) ||
                employee.WorkTime != Resources.EmployeeWrapperViewModel_WorkingTimeOptions_FullTime &&
                employee.WorkTime != Resources.EmployeeWrapperViewModel_WorkingTimeOptions_PartTime)
            {
                temp._selectedWorkTime = Resources.EmployeeWrapperViewModel_ComboboxValue_NotSpecified;
            }

            if (String.IsNullOrEmpty(employee.UserType) ||
                employee.UserType != Resources.EmployeeWrapperViewModel_UserTypeOptions_StandardUser &&
                employee.UserType != Resources.EmployeeWrapperViewModel_UserTypeOptions_Administrator &&
                employee.UserType != Resources.EmployeeWrapperViewModel_UserTypeOptions_Developer
                )
            {
                temp._selectedUserType = Resources.EmployeeWrapperViewModel_ComboboxValue_NotSpecified;
            }
        }