private void AddOrUpdateEmployee(EKontoUser eKontoUser, EKadryEmployee eKadryEmployee, Institute institute) { Promoter promoter = _context.Promoters.Where(p => p.Id == eKadryEmployee.id).FirstOrDefault(); if (promoter == null) { promoter = new Promoter { Id = eKadryEmployee.id, InstituteId = institute.Id, ExpectedNumberOfBachelorProposals = 0, ExpectedNumberOfMasterProposals = 0, UserId = eKontoUser.id }; _mapper.Map(eKontoUser, promoter); _mapper.Map(eKadryEmployee, promoter); _context.Promoters.Add(promoter); } else { _mapper.Map(eKontoUser, promoter); _mapper.Map(eKadryEmployee, promoter); promoter.InstituteId = institute.Id; _context.Promoters.Update(promoter); } _context.SaveChanges(); }
private EKadryDepartment getFacultyDepartment(EKadryEmployee employee, out EKadryDepartment instituteDepartment) { instituteDepartment = null; if (employee.employments == null) { return(null); } foreach (EKadryEmployment employment in employee.employments) { if (employment.isActive == false) { continue; } if (employment.position == null) { continue; } if (employment.position.isEducational == false) { continue; } EKadryDepartment department = employment.position.department; while (department != null) { if (department.typeName == InstituteTypeName) { instituteDepartment = department; } if (department.typeName == FacultyTypeName) { return(department); } department = department.parentDepartment; } } return(null); }
public void Synchronize() { EKontoUser[] didacticEKontoUsers = _eKontoClient.GetAllUsersByIds(_eKontoClient.GetGroupUsers(DidacticEmployeesEKontoGroupId)); foreach (EKontoUser didacticUser in didacticEKontoUsers) { EKadryEmployee employee = _eKadryClient.GetEmployeeDataById(int.Parse(didacticUser.internalId)); if (employee == null || employee.title == null) { continue; } EKadryDepartment facultyDepartment = getFacultyDepartment(employee, out EKadryDepartment instituteDepartment); if (facultyDepartment == null) { continue; } Institute institute = _context.Institutes.Where(i => i.Id == instituteDepartment.id).FirstOrDefault(); AddOrUpdatePromoterUser(didacticUser); AddOrUpdateEmployee(didacticUser, employee, institute); } }