예제 #1
0
        public void AlterEmployee()
        {
            int      id       = EmployeeView.RequestId();
            Employee employee = _repository.GetById(id);

            if (employee != null)
            {
                EmployeeVm employeeVm = new EmployeeVm()
                {
                    Name = employee.Name, Country = employee.Country, HourlyRate = employee.HourlyRate.ToString(), HoursWorked = employee.HoursWorked.ToString()
                };

                if (EmployeeView.ShowAlterEmployeeView(employeeVm))
                {
                    employee.Name        = employeeVm.Name;
                    employee.Country     = employeeVm.Country;
                    employee.HourlyRate  = double.Parse(employeeVm.HourlyRate);
                    employee.HoursWorked = int.Parse(employeeVm.HoursWorked);

                    try
                    {
                        _repository.Add(employee);
                        EmployeeView.ShowMessage("Funcionário alterado com sucesso.");
                    }
                    catch (Exception e)
                    {
                        EmployeeView.ShowMessage("Erro ao alterar o Funcionário.");
                    }
                }
            }
            else
            {
                EmployeeView.ShowMessage("Funcionário não encontrado.");
            }
        }