public async Task <string> CreateSchedulingGroupAsync(string teamId, string groupName, List <string> userIds)
        {
            var client = _clientFactory.CreateClient(_options, teamId);

            // ensure that all users are actually in the Team and remove any that aren't
            var teamMembers = await GetMemberIdsAsync(client, teamId);

            RemoveInvalidUsers(userIds, teamMembers);
            if (userIds.Count == 0)
            {
                return(null);
            }

            // because we are caching the scheduling groups we cannot be certain that a group has not been
            // created by another instance of the service, so we should double-check prior to creating the
            // group
            var groupId = await GetSchedulingGroupIdByNameAsync(client, teamId, groupName);

            if (string.IsNullOrEmpty(groupId))
            {
                var request = new SchedulingGroupRequest
                {
                    DisplayName = groupName,
                    IsActive    = true,
                    UserIds     = userIds
                };

                var response = await client.CreateSchedulingGroupAsync(request, teamId);

                response.ThrowIfError();

                groupId = ((SchedulingGroupResponse)response).Id;

                // update the cache of scheduling groups
                var groups = await GetSchedulingGroupsAsync(client, teamId);

                groups[groupName] = groupId;
            }

            return(groupId);
        }
Ejemplo n.º 2
0
        public async Task <string> CreateSchedulingGroupAsync(string teamId, string groupName, List <string> userIds)
        {
            var client = _clientFactory.CreateClient(_options, teamId);

            // ensure that all users are actually in the Team and remove any that aren't
            var teamMembers = await _cacheService.GetKeyAsync <List <string> >(ApplicationConstants.TableNameEmployeeLists, teamId).ConfigureAwait(false);

            RemoveInvalidUsers(userIds, teamMembers);

            // because we are caching the scheduling groups we cannot be certain that a group has
            // not been created by another instance of the service, so try and get the group from
            // the refreshed cache, and only if it is still not found, create it
            var groupId = await GetSchedulingGroupIdByNameAsync(client, teamId, groupName).ConfigureAwait(false);

            if (string.IsNullOrEmpty(groupId))
            {
                var request = new SchedulingGroupRequest
                {
                    DisplayName = groupName,
                    IsActive    = true
                };

                if (userIds.Count > 0)
                {
                    request.UserIds = userIds;
                }

                var response = await client.CreateSchedulingGroupAsync(request, teamId).ConfigureAwait(false);

                response.ThrowIfError();

                groupId = ((SchedulingGroupResponse)response).Id;

                // update the cache of scheduling groups
                await RefreshCachedSchedulingGroupsAsync(client, teamId).ConfigureAwait(false);
            }

            return(groupId);
        }