Ejemplo n.º 1
0
        /// <summary>
        /// Create TimeOff Reasons in Shifts.
        /// </summary>
        /// <param name="accessToken">Cached AccessToken.</param>
        /// <param name="teamsId">MS Teams Id.</param>
        /// <param name="payCode">Kronos payCode.</param>
        /// <returns>None.</returns>
        private async Task <dynamic> CreateTimeOffReasonAsync(string accessToken, string teamsId, string payCode)
        {
            this.telemetryClient.TrackTrace($"{MethodBase.GetCurrentMethod().Name}");

            TimeOffReasonRequest.TimeOffReason timeOffReason = new TimeOffReasonRequest.TimeOffReason
            {
                DisplayName = payCode,
                IconType    = "plane",
                IsActive    = true,
            };
            var requestString = JsonConvert.SerializeObject(timeOffReason);

            var httpClient = this.httpClientFactory.CreateClient("ShiftsAPI");

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
            using (var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "teams/" + teamsId + "/schedule/timeOffReasons")
            {
                Content = new StringContent(requestString, Encoding.UTF8, "application/json"),
            })
            {
                var response = await httpClient.SendAsync(httpRequestMessage).ConfigureAwait(true);

                if (response.IsSuccessStatusCode)
                {
                    var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(true);

                    return(responseContent);
                }
                else
                {
                    var failedCreateTimeOffReasonsProps = new Dictionary <string, string>()
                    {
                        { "TeamId", teamsId },
                        { "PayCode", payCode },
                    };

                    this.telemetryClient.TrackTrace($"{MethodBase.GetCurrentMethod().Name}", failedCreateTimeOffReasonsProps);
                    return(string.Empty);
                }
            }
        }
        /// <summary>
        /// Create TimeOff Reasons in Shifts.
        /// </summary>
        /// <param name="allRequiredConfigurations">Object containing the AccessToken.</param>
        /// <param name="teamsId">MS Teams Id.</param>
        /// <param name="payCode">Kronos payCode.</param>
        /// <returns>None.</returns>
        private async Task <(bool, TimeOffReasonResponse.TimeOffReason)> CreateTimeOffReasonAsync(SetupDetails allRequiredConfigurations, string teamsId, string payCode)
        {
            this.telemetryClient.TrackTrace($"Adding {payCode} for {teamsId}");

            TimeOffReasonRequest.TimeOffReason timeOffReason = new TimeOffReasonRequest.TimeOffReason
            {
                DisplayName = payCode,
                IconType    = "plane",
                IsActive    = true,
            };

            var httpClient = this.httpClientFactory.CreateClient("ShiftsAPI");

            var requestUrl    = $"teams/{teamsId}/schedule/timeOffReasons";
            var requestString = JsonConvert.SerializeObject(timeOffReason);

            var response = await this.graphUtility.SendHttpRequest(allRequiredConfigurations.GraphConfigurationDetails, httpClient, HttpMethod.Post, requestUrl, requestString).ConfigureAwait(false);

            if (response.IsSuccessStatusCode)
            {
                var createdTimeOffReason = JsonConvert.DeserializeObject <TimeOffReasonResponse.TimeOffReason>(
                    await response.Content.ReadAsStringAsync().ConfigureAwait(true));
                return(true, createdTimeOffReason);
            }
            else
            {
                var failedCreateTimeOffReasonsProps = new Dictionary <string, string>()
                {
                    { "TeamId", teamsId },
                    { "PayCode", payCode },
                };

                this.telemetryClient.TrackTrace($"Failed to add {payCode} for {teamsId}", failedCreateTimeOffReasonsProps);
                return(false, null);
            }
        }