Exemplo n.º 1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dataGridView.CurrentRow != null)
            {
                switch (_eFrmType)
                {
                case EFrmType.employees:
                    EmployeeModel employee    = (EmployeeModel)dataGridView.CurrentRow.DataBoundItem;
                    List <string> departments = _departmentsLogic.UserExistInDepartment(employee.ID);
                    string        message     = _departmentsLogic.GetDepartmentsOfHeadEmployee(departments);

                    if (departments.Count == 0)
                    {
                        _employeesLogic.DeleteEmployee(employee.ID);
                        RefreshGrid();
                    }
                    else
                    {
                        MessageBox.Show(message, "Vymazanie zamestnanca");
                    }
                    break;

                case EFrmType.departments:
                    DepartmentModel        department      = (DepartmentModel)dataGridView.CurrentRow.DataBoundItem;
                    List <DepartmentModel> departmentsList = _departmentsLogic.GetDepartments();

                    //check if department have child departments
                    departmentsList = departmentsList.Where(dep => dep.ParentDepartmentID == department.ID).ToList();
                    if (departmentsList.Count == 0)
                    {
                        int number = _departmentsLogic.DeleteDepartment(department);
                        if (number == 0)
                        {
                            MessageBox.Show("Nie je možné vymazať oddelenie, pretože má priradených zamestnancov");
                        }
                        RefreshGrid();
                    }
                    else
                    {
                        MessageBox.Show("Nie je možné vymazať oddelenie, pokiaľ má podriadené oddelenia");
                    }
                    break;
                }
            }
        }
Exemplo n.º 2
0
        public ActionResult Delete(int id, int roleId)
        {
            try
            {
                EmployeesLogic.DeleteEmployee(id);
            }
            catch (Exception e)
            {
                LogsLogic.InsertLog(new Log()
                {
                    Message    = e.Message,
                    StackTrace = e.StackTrace,
                    StoryName  = "ManagementProject/Users/Delete",
                    Parameters = "id = " + id.ToString() + " & roleId = " + roleId.ToString()
                });
            }
            if (roleId == 8)
            {
                return(RedirectToAction("DeveloperIndex"));
            }

            return(RedirectToAction("Index"));
        }