Ejemplo n.º 1
0
        private void btnEmployeeEdit_Click(object sender, EventArgs e)
        {
            EmployeeForm form            = new EmployeeForm();
            var          listofEmployees = managementService.GetEmployees(0, 0).Select(x => new ManagerComboBoxItem(x.Name + " " + x.LastName + "(" + x.Id + ")", x.Id)).ToList();

            form.comboManager.Items.AddRange(listofEmployees.ToArray());
            var selected   = gridEmployee.SelectedRows[0];
            int employeeId = int.Parse(selected.Cells[0].Value.ToString());
            var toEdit     = managementService.GetEmployee(employeeId.ToString());

            form.textId.Text              = toEdit.Id.ToString();
            form.textLastname.Text        = toEdit.LastName;
            form.textName.Text            = toEdit.Name;
            form.textEmail.Text           = toEdit.Email;
            form.checkUserAccount.Visible = false;
            var manager = managementService.GetEmployeeManager(employeeId.ToString());

            form.comboManager.Text    = manager == null ? "" : listofEmployees.Where(x => (int)x.Value == manager.Id).Single().ToString();
            form.comboManager.Enabled = false;
            if (DialogResult.OK == form.ShowDialog(this))
            {
                central.dto.Employee updateEmployee = new Employee(int.Parse(form.textId.Text), form.textName.Text, form.textLastname.Text, form.textEmail.Text);
                var employee = managementService.UpdateEmployee(form.textId.Text, updateEmployee);
                UpdateGridEmployees();
            }
        }
Ejemplo n.º 2
0
        private void btnAddEmployee_Click(object sender, EventArgs e)
        {
            EmployeeForm form            = new EmployeeForm();
            var          listofEmployees = managementService.GetEmployees(0, 0).Select(x => new ManagerComboBoxItem(x.Name + " " + x.LastName + "(" + x.Id + ")", x.Id)).ToList();

            form.comboManager.Items.AddRange(listofEmployees.ToArray());
            if (DialogResult.OK == form.ShowDialog(this))
            {
                var            managerText    = form.comboManager.Text;
                var            manager        = listofEmployees.Where(t => t.ToString() == managerText).SingleOrDefault();
                CreateEmployee createEmployee = new CreateEmployee(form.textName.Text, form.textLastname.Text, form.textEmail.Text, manager == null ? 0 : (int)manager.Value);
                var            project        = managementService.CreateEmployee(createEmployee);
                UpdateGridEmployees();
            }
        }