예제 #1
0
        private async Task UpdateCachedEmployeesAsync(IList <EmployeeModel> sourceEmployees, Dictionary <string, EmployeeModel> teamEmployeesDict, string teamId)
        {
            foreach (var sourceEmployee in sourceEmployees)
            {
                var teamEmployee = _userPrincipalMap.MapEmployee(sourceEmployee.WfmLoginName, teamEmployeesDict);
                if (teamEmployee != null)
                {
                    sourceEmployee.TeamsEmployeeId = teamEmployee.TeamsEmployeeId;
                    sourceEmployee.TeamsLoginName  = teamEmployee.TeamsLoginName;

                    // save the employee to cache keyed by both the source and destination ids as we
                    // need to do the lookups from both directions e.g. in weekactivity, the lookup
                    // is from source -> destination e.g. in shift swap, the lookup is from
                    // destination -> source

                    var existing = await _cacheService.GetKeyAsync <EmployeeModel>(ApplicationConstants.TableNameEmployees, sourceEmployee.TeamsEmployeeId).ConfigureAwait(false);

                    if (existing != null)
                    {
                        sourceEmployee.TeamIds = existing.TeamIds;
                    }

                    if (!sourceEmployee.TeamIds.Contains(teamId))
                    {
                        sourceEmployee.TeamIds.Add(teamId);
                    }
                    await _cacheService.SetKeyAsync(ApplicationConstants.TableNameEmployees, sourceEmployee.TeamsEmployeeId, sourceEmployee).ConfigureAwait(false);

                    await _cacheService.SetKeyAsync(ApplicationConstants.TableNameEmployees, sourceEmployee.WfmEmployeeId, sourceEmployee).ConfigureAwait(false);
                }
            }
        }
        public async Task <EmployeeModel> GetEmployeeAsync(string teamId, string login)
        {
            var client = _clientFactory.CreateClient(_options, teamId);

            await LoadMembersAsync(client, teamId);

            return(_userPrincipalMap.MapEmployee(login, _teamMembers[teamId]));
        }