Пример #1
0
        // Employees - Add new employee with selected types
        private async void AddNewEmployeeBtn_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(tbUsername.Text) ||
                string.IsNullOrWhiteSpace(tbPassword.Text))
            {
                MessageBox.Show("Invalid input");
                return;
            }

            var parameters  = new List <object>();
            var newEmployee = new Employee
            {
                Username = tbUsername.Text,
                Password = tbPassword.Text
            };

            foreach (var item in chkListBoxEmployeeType.CheckedItems)
            {
                newEmployee.Types.Add((EmployeeType)item);
            }

            if (newEmployee.Types.Count <= 0)
            {
                MessageBox.Show("Add a type");
                return;
            }

            newEmployee.Types.ForEach(type => parameters.Add(InsertParameters(newEmployee, type)));

            try
            {
                await _repo.CreateNewEmployee(parameters);
            }
            catch (System.Data.SqlClient.SqlException)
            {
                MessageBox.Show("Username already exist");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            ClearEmployeeTextBoxes();
            GetEmployeesBtn_Click(sender, e);
        }