Exemple #1
0
        /// <summary>
        /// Get all teams from KMS by KMS API
        /// API: https://hr.kms-technology.com/api/projects/ReturnListProjectClient
        /// </summary>
        /// <returns>A collection of all KMS team DTOs</returns>
        private async Task <IEnumerable <KmsTeamDto> > GetTeamsFromKmsAsync()
        {
            var kmsTeamDTOs = new List <KmsTeamDto>();

            // Initialize httpclient with token from login service to send request to KMS HRM
            var bearerToken = await _authenticateService.AuthenticateUsingConfiguration();

            var client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", bearerToken);
            var response = await client.GetAsync(Configuration.GetValue <string>("KmsInfo:KmsTeamRequestUrl"));

            if (response.StatusCode == HttpStatusCode.OK)
            {
                // Convert response JSON to object
                var contentString = await response.Content.ReadAsStringAsync();

                var jsonKmsTeamDTOs = JsonConvert.DeserializeObject <IEnumerable <KmsTeamDto> >(contentString);

                // Add KMS team DTOs to list
                kmsTeamDTOs.AddRange(jsonKmsTeamDTOs);
            }

            return(kmsTeamDTOs);
        }
Exemple #2
0
        /// <summary>
        /// Get all teams from KMS by KMS API
        /// API: https://hr.kms-technology.com/api/contact/ReturnContactList/{pageIndex}/{pageSize}
        ///     Default page index: 1
        ///     Default page size: 10
        /// </summary>
        /// <returns>A collection of all KMS employee DTOs</returns>
        private async Task <IEnumerable <KmsEmployeeDto> > GetEmployeesFromKmsAsync()
        {
            var KmsEmployeeDTOs = new List <KmsEmployeeDto>();
            // Initialize query string for request to KMS HRM API
            var pageIndex  = 1;
            var pageSize   = 100;
            var totalCount = 0;
            // Initialize httpclient with token to send request to KMS HRM
            var bearerToken = await _authenticateService.AuthenticateUsingConfiguration();

            var client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", bearerToken);

            do
            {
                var response = await client
                               .GetAsync($"{Configuration.GetValue<string>("KmsInfo:KmsEmployeeRequestUrl")}/{pageIndex}/{pageSize}");

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    // Convert response JSON to object and get total count
                    var contentString = await response.Content.ReadAsStringAsync();

                    var kmsEmployeeResponse = JsonConvert.DeserializeObject <KmsEmployeeResponseDto>(contentString);
                    totalCount = kmsEmployeeResponse.TotalCount;
                    // Add KMS employee DTOs to list
                    KmsEmployeeDTOs.AddRange(kmsEmployeeResponse.KmsEmployees);
                }
                // Prepare next request
                pageIndex += 1;
            } while (totalCount >= (pageSize * (pageIndex - 1)));

            return(KmsEmployeeDTOs);
        }