コード例 #1
0
        public async Task <IActionResult> SaveOnCallSupportDetailsAsync([FromBody] OnCallSupportDetail onCallSupportDetails)
        {
            try
            {
                if (onCallSupportDetails == null)
                {
                    return(this.BadRequest());
                }

                if (!this.IsUserAuthenticated())
                {
                    throw new UnauthorizedAccessException("Failed to get fromId from token.");
                }

                this.logger.LogInformation("Initiated call to on storage provider service.");
                var result = await this.onCallSupportDetailStorageProvider.UpsertOnCallSupportDetailsAsync(onCallSupportDetails);

                this.logger.LogInformation("POST call for saving on call support details in storage is successful.");
                return(this.Ok(result));
            }
            catch (UnauthorizedAccessException ex)
            {
                this.logger.LogError(ex, "Failed to get user token to make POST call to API.");
                return(this.GetErrorResponse(StatusCodes.Status401Unauthorized, ex.Message));
            }
            #pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
            #pragma warning restore CA1031 // Do not catch general exception types
            {
                this.logger.LogError(ex, "Error while saving on call support details.");
                throw;
            }
        }
        /// <summary>
        /// Save on call support details in Azure Table Storage.
        /// </summary>
        /// <param name="onCallSupportTeamDetails">On call support details to be stored in table storage.</param>
        /// <returns><see cref="Task"/> Returns OnCallSupportId when on call support data was saved successfully.</returns>
        public async Task <string> UpsertOnCallSupportDetailsAsync(OnCallSupportDetail onCallSupportTeamDetails)
        {
            await this.EnsureInitializedAsync();

            onCallSupportTeamDetails        = onCallSupportTeamDetails ?? throw new ArgumentNullException(nameof(onCallSupportTeamDetails));
            onCallSupportTeamDetails.RowKey = Guid.NewGuid().ToString();
            TableOperation addOperation = TableOperation.Insert(onCallSupportTeamDetails);
            var            result       = await this.CloudTable.ExecuteAsync(addOperation);

            if (result.Result != null)
            {
                var onCallSMEDetails = (OnCallSupportDetail)result.Result;
                return(onCallSMEDetails.OnCallSupportId);
            }

            return(string.Empty);
        }