Beispiel #1
0
 public ActionResult Create(CreateEmployeModel createEmployeModel)
 {
     try
     {
         if (createEmployeModel.employee.CompanyDepartment_ID == null)
         {
             ModelState.AddModelError(nameof(createEmployeModel.employee.CompanyDepartment_ID), "Department can not be empty. Please select one.");
         }
         if (ModelState.IsValid)
         {
             employeeService.InsertNewEmployee(createEmployeModel.employee);
             return(RedirectToAction("Index"));
         }
         else
         {
             List <CompanyDepartment> departments = departmentService.GetAllDepartments();
             createEmployeModel.departments = departments;
             return(View(createEmployeModel));
         }
     }
     catch (Exception ex)
     {
         return(ShowExceptionMessage(ex));
     }
 }
Beispiel #2
0
 public ActionResult Edit(CreateEmployeModel employeeModel)
 {
     try
     {
         if (employeeModel.employee.CompanyDepartment_ID == null)
         {
             ModelState.AddModelError(nameof(employeeModel.employee.CompanyDepartment_ID), "Department can not be empty. Please select one.");
         }
         if (ModelState.IsValid)
         {
             //CompanyDepartment department = departmentService.GetDepartmentByID(employeeModel.employee.CompanyDepartment_ID);
             //employeeModel.employee.companyDepartment = department;
             string result = employeeService.EditExistingEmployee(employeeModel.employee);
             return(RedirectToAction("Index"));
         }
         else
         {
             return(View(employeeModel));
         }
     }
     catch (Exception ex)
     {
         return(ShowExceptionMessage(ex));
     }
 }
Beispiel #3
0
        //// GET: Employee/Details/5
        //public ActionResult Details(Guid id)
        //{
        //    return View(employeeService.GetEmployeeByID(id));
        //}

        // GET: Employee/Create
        public ActionResult Create()
        {
            try
            {
                CreateEmployeModel       createEmployeModel = new CreateEmployeModel();
                List <CompanyDepartment> departments        = departmentService.GetAllDepartments();
                createEmployeModel.departments = departments;
                return(View(createEmployeModel));
            }
            catch (Exception ex)
            {
                return(ShowExceptionMessage(ex));
            }
        }
Beispiel #4
0
 // GET: Employee/Edit/5
 public ActionResult Edit(Guid id)
 {
     try
     {
         CreateEmployeModel createEmployeModel = new CreateEmployeModel();
         CompanyEmployee    employee           = employeeService.GetEmployeeByID(id);
         createEmployeModel.employee = employee;
         List <CompanyDepartment> departments = departmentService.GetAllDepartments();
         createEmployeModel.departments = departments;
         createEmployeModel.employee.companyDepartment = departments.Find(x => x.ID == createEmployeModel.employee.CompanyDepartment_ID);
         return(View(createEmployeModel));
     }
     catch (Exception ex)
     {
         return(ShowExceptionMessage(ex));
     }
 }