Ejemplo n.º 1
0
        public IActionResult Register(EmployeeModel employeeModel)
        {
            if (employeesLogic.isUsernameExists(employeeModel.Username))
            {
                return(BadRequest("Username already taken"));
            }

            employeesLogic.AddEmployee(employeeModel);

            employeeModel.JwtToken = jwtHelper.GetJwtToken(employeeModel.Username, employeeModel.Role);

            return(Created("api/employees/" + employeeModel.EmployeeId, employeeModel));
        }
Ejemplo n.º 2
0
        public IActionResult AddEmployee(EmployeeModel employeeModel)
        {
            try
            {
                if (logic.isUsernameExists(employeeModel.Username))
                {
                    return(BadRequest("Username allready taken"));
                }

                EmployeeModel addedEmployee = logic.AddEmployee(employeeModel);
                return(Created("api/employees/" + addedEmployee.EmployeeId, addedEmployee));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }