public async Task <int> GetDepartmentDesignationId(int departmentId, int designationId) { var departmentDesignation = await _departmentDesignationRepository.GetDepartmentDesignationAsync(departmentId, designationId); return(departmentDesignation.Id); }
/// <summary> /// this method is used to add new employee's official details in the system /// </summary> /// <param name="newEmployeeOfficialDetails">New Employee Official Details</param> public async Task <Guid> AddNewEmployeeOfficialInformationAsync(AddEmployeeOfficialInformationDto newEmployeeOfficialDetails) { var employeeId = Guid.NewGuid(); //check if same employee id and employee email already exists var sameEmployeeDetails = await _employeeRepository.GetEmployeeByCompanyIdAsync(newEmployeeOfficialDetails.CompanyId); if (sameEmployeeDetails != null) { throw new Exception("Employee already exist"); } //get department designation mapping id from departmentdesignation table var departmentDesignation = await _departmentDesignationRepository.GetDepartmentDesignationAsync(newEmployeeOfficialDetails.DepartmentId, newEmployeeOfficialDetails.DesignationId); if (departmentDesignation == null) { throw new Exception("Department designation Not Mapped"); } var employee = _mapper.Map <Employee>(newEmployeeOfficialDetails); employee.Id = employeeId; employee.DepartmentDesignationId = departmentDesignation.Id; employee.IsDeleted = false; employee.CreatedAt = DateTime.UtcNow; employee.ModifiedAt = DateTime.UtcNow; employee.Languages = JsonConvert.SerializeObject(newEmployeeOfficialDetails.Languages); employee.Gender = employee.Gender.ToLower(); var employeeSkill = new EmployeeSkill { EmployeeId = employee.Id, PrimarySkills = JsonConvert.SerializeObject(newEmployeeOfficialDetails.PrimarySkill), SecondarySkills = JsonConvert.SerializeObject(newEmployeeOfficialDetails.SecondarySkill), IsDeleted = false, }; var reportingManager = new ReportingManager { EmployeeId = employeeId, ReportingManagerId = newEmployeeOfficialDetails.ReportingManager }; using (var ts = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { _employeeRepository.AddNewEmployee(employee); await _employeeRepository.SaveChangesAsync(); if (newEmployeeOfficialDetails.ReportingManager != null) { _reportingManagerRepository.AddReportingManager(reportingManager); await _reportingManagerRepository.SaveChangesAsync(); } _employeeSkillRepository.AddEmployeeSkill(employeeSkill); await _employeeSkillRepository.SaveChangesAsync(); ts.Complete(); } //var elasticEmployeeDetailsDto = _mapper.Map<ElasticEmployeeDetailsDto>(newEmployeeOfficialDetails); //elasticEmployeeDetailsDto.Id = employeeId; //await AddEmployeeToElasticSearch(elasticEmployeeDetailsDto); return(employee.Id); }