public async Task <ActionResult> AddNewEmployee([FromBody] AddNewEmployeeRequest employee) { try { var response = await _employeeService.AddNewEmployeeAsync(employee); return(Ok(response)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
/// <summary> /// Add New Employee and Dependents /// </summary> /// <param name="employeeSubmit"></param> /// <returns></returns> public async Task <EmployeeViewModel> AddNewEmployeeAsync(EmployeeSubmitViewModel employeeSubmit) { var addRequest = new AddNewEmployeeRequest { FirstName = employeeSubmit.FirstName, LastName = employeeSubmit.LastName, MiddleName = employeeSubmit.MiddleName, DateOfBirth = employeeSubmit.DateOfBirth, Dependents = employeeSubmit.Dependents }; var client = new RestClient("https://localhost:44361"); var request = new RestRequest($"employee", Method.POST) .AddJsonBody(addRequest); var employee = client.Execute(request); var responseContent = JsonConvert.DeserializeObject <AddNewEmployeeResponse>(employee.Content); var employeeProfile = await this.GetEmployeeProfileAsync(responseContent.EmployeeId); return(employeeProfile); }
/// <summary> /// Add New Employee /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task <AddNewEmployeeResponse> AddNewEmployeeAsync(AddNewEmployeeRequest request) { try { var empEntity = _mapper.Map <EmployeeEntity>(request); var dbResult = await _humanResourceDbContext.AddAsync(empEntity); await _humanResourceDbContext.SaveChangesAsync(); return(new AddNewEmployeeResponse { EmployeeId = empEntity.EmployeeId, FirstName = empEntity.FirstName, LastName = empEntity.LastName, MiddleName = empEntity.MiddleName, DateOfBirth = empEntity.DateOfBirth }); } catch (Exception ex) { return(new AddNewEmployeeResponse()); } }