Ejemplo n.º 1
0
        public JsonResult Create(ManageViewModel viewModel)
        {
            if (!ModelState.IsValid)
                return Json(new { error = true, message = "There were errors in the submission" });

            try
            {
                // Build the employee object
                var employee = new Employee()
                {
                    Id = viewModel.Id,
                    Name = viewModel.Name,
                    Email = viewModel.Email,
                    Password = viewModel.Password
                };

                // Add the employee
                _userRepository.CreateEmployee(employee);

                return Json(new { error = false, message = "Employee successfully created!" });

            }
            catch (EmployeeExistsException)
            {
                // If the employee already exists, display error
                return Json(new { error = true, message = "Employee already exists" });
            }
        }
Ejemplo n.º 2
0
        public void DeleteEmployee(Employee employee)
        {
            foreach (var emp in _dbContext.Employees.Where(e => e.Id == employee.Id))
            {
                foreach (var employeeRole in emp.Roles.ToList())
                {
                    emp.Roles.Remove(employeeRole);
                }
            }

            _dbContext.Employees.Remove(employee);
            _dbContext.SaveChanges();
        }
Ejemplo n.º 3
0
 public void CreateEmployee(Employee employee)
 {
     
 }