public ActionResult Create(EmployeeViewModel employeeViewModel)
        {
            try
            {
                dbManager.AddEmployee(employeeViewModel.ToEntity());

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMsg = ex.Message;
                return(View("Error"));
            }
        }
Exemple #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            bool   notEmptyTextBoxes = !string.IsNullOrEmpty(textBox1.Text) && !string.IsNullOrEmpty(textBox2.Text) && !string.IsNullOrEmpty(textBox3.Text);
            string personStatus      = (string)cbAdd.SelectedItem;

            if (notEmptyTextBoxes)
            {
                Person person = new Person();

                switch (personStatus)
                {
                case "Співробітник":
                {
                    AddEmployee addEmployee = new AddEmployee();
                    addEmployee.Person.Name       = textBox1.Text;
                    addEmployee.Person.Surname    = textBox2.Text;
                    addEmployee.Person.Patronymic = textBox3.Text;

                    addEmployee.ShowDialog();

                    if (addEmployee.IsAdded)
                    {
                        person = addEmployee.Person;
                        if (dbManager.AddEmployee(person))
                        {
                            MessageBox.Show("Дані успішно додані", "Бухгалтерія університету", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            ClearTextBoxes(textBox1, textBox2, textBox3);
                        }
                        else
                        {
                            MessageBox.Show("Дані не були додані, помилка на стороні серверу", "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Дані не були додані, заповнення відмінено чи виникла помилка", "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    break;
                }

                case "Студент":
                {
                    AddStudent addStudent = new AddStudent();
                    addStudent.Person.Name       = textBox1.Text;
                    addStudent.Person.Surname    = textBox2.Text;
                    addStudent.Person.Patronymic = textBox3.Text;

                    addStudent.ShowDialog();

                    if (addStudent.IsAdded)
                    {
                        person = addStudent.Person;
                        if (dbManager.AddStudent(person))
                        {
                            MessageBox.Show("Дані успішно додані", "Бухгалтерія університету", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            ClearTextBoxes(textBox1, textBox2, textBox3);
                        }
                        else
                        {
                            MessageBox.Show("Дані не були додані, помилка на стороні серверу", "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Дані не були додані, заповнення відмінено чи виникла помилка", "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    break;
                }
                }
            }
            else
            {
                MessageBox.Show("Всі текстові поля повинні бути заповнені!", "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }