public IActionResult GetAll([FromBody] EmployeeSignUpDTO employeeSignUpDTO) { if (employeeSignUpDTO == null) { return(new BadRequestResult()); } var result = _signUpService.NewSignUp(employeeSignUpDTO); if (result == null) { //Internal Server Error return(StatusCode(500)); } return(new JsonResult(result)); }
/// <summary> /// This method adds a new Employee in the system. /// </summary> /// <param name="employeeSignUpDTO">Object that provides the employee sign up details</param> /// <returns>The Employee details that have been added to the system</returns> public EmployeeDTO AddNewEmployee(EmployeeSignUpDTO employeeSignUpDTO) { if (employeeSignUpDTO == null || string.IsNullOrEmpty(employeeSignUpDTO.EmailAddress)) { return(null); } var employee = new Employee { FirstName = employeeSignUpDTO.FirstName, LastName = employeeSignUpDTO.LastName, EmailAddress = employeeSignUpDTO.EmailAddress }; _appDbContext.Employees.Add(employee); _appDbContext.SaveChanges(); return(_mapper.Map <EmployeeDTO>(employee)); }
/// <summary> /// This method is used to Sign Up a new Employee for an Event. /// The employee will only be signed up if the employee is not already signed up for the event. /// </summary> /// <param name="employeeSignUpDTO">EmployeeSignUp object</param> /// <returns>The result of the operation of an Employee's Sign Up</returns> public EmployeeSignUpResultDTO NewSignUp(EmployeeSignUpDTO employeeSignUpDTO) { if (employeeSignUpDTO == null || (string.IsNullOrEmpty(employeeSignUpDTO.FirstName)) || (string.IsNullOrEmpty(employeeSignUpDTO.LastName)) || (string.IsNullOrEmpty(employeeSignUpDTO.EmailAddress)) || (employeeSignUpDTO.EventId == 0)) { return(GetEmployeeSignUpResult(false, _localizer["InvalidData"].Value)); } //Get Employee var employee = GetEmployee(employeeSignUpDTO.EmailAddress); //Add Employee If not exists if (employee == null) { employee = AddNewEmployee(employeeSignUpDTO); } if (employee == null) { return(GetEmployeeSignUpResult(false, _localizer["InvalidData"].Value)); } //Check If Employee is already registered if (IsEmployeeRegisteredForEvent(employeeSignUpDTO.EventId, employee.Id)) { return(GetEmployeeSignUpResult(false, _localizer["AlreadyRegistered"].Value)); } //Sign Up Employee for the Event var employeeSignUp = SignUpNewEmployee(employeeSignUpDTO.EventId, employee.Id, employeeSignUpDTO.Comments); return(GetEmployeeSignUpResult(true, string.Empty, employeeSignUp)); }
/// <summary> /// This method is used by NewSignUp() method to create an object that specifies the result of the Sign Up operation. /// </summary> /// <param name="result">Result of the operation</param> /// <param name="error">Eror Message</param> /// <param name="employeeSignUpDTO">Employee Sign Up object</param> /// <returns></returns> private EmployeeSignUpResultDTO GetEmployeeSignUpResult(bool result, string error, EmployeeSignUpDTO employeeSignUpDTO = null) { return(new EmployeeSignUpResultDTO { Result = result, ErrorMessage = error, EmployeeSignUp = employeeSignUpDTO }); }
/// <summary> /// This method adds a new employee to the system /// </summary> /// <param name="employeeSignUpDTO">The EmployeeSignUp object</param> /// <returns>The Employee object</returns> private EmployeeDTO AddNewEmployee(EmployeeSignUpDTO employeeSignUpDTO) { return(_employeeService.AddNewEmployee(employeeSignUpDTO)); }