Пример #1
0
        /// <summary>
        /// Delete Historic Records for Specified Airline, Reporting Period, ReportType (GCP SchemaId) and Year
        /// </summary>
        /// <param name="iaocCode">Airline Code</param>
        /// <param name="reportPeriod">Report Period - Annual, Q1, Q2</param>
        /// <param name="schemaId">GCP SchemaId e.g. raw-income-statement</param>
        /// <param name="year">Report Year</param>
        /// <returns>Command Response</returns>
        public async Task <CommandResponse> DeleteHistoricRecordsAsync(string iaocCode, ReportPeriod reportPeriod, string schemaId, int year)
        {
            CommandResponse response = new CommandResponse
            {
                Information = $"Deleting Historic Reports for:{iaocCode} period:{reportPeriod} type:{schemaId} year:{year}",
                Success     = true
            };

            try
            {
                var deleteList = _reportDataService.GetReportDocumentsForDeletions(iaocCode, reportPeriod, schemaId, year);
                if (deleteList != null)
                {
                    var token = _clientTokenHandler.GetValidToken();
                    foreach (Guid documentId in deleteList)
                    {
                        // DELETE Document from GCP
                        var gcpDeletionResponse = await _documentDeletionProcessor.DeleteDocumentAsync(schemaId, documentId.ToString(), token, CancellationToken.None);

                        if (gcpDeletionResponse == true)
                        {
                            // Delete Report in Document Service Database
                            var documentAPIResponse = _reportDataService.DeleteReport(documentId.ToString());
                            if (documentAPIResponse != null && !documentAPIResponse.Success)
                            {
                                response.Success = false;
                            }
                        }
                        else
                        {
                            response.Success = false;
                            _logger.LogWarning($"FAILED to DELETE Document from GCP for:{iaocCode} period:{reportPeriod} type:{schemaId} year:{year}");
                        }
                    }

                    if (!response.Success)
                    {
                        _logger.LogWarning($"FAILED to DELETE ALL Historic Documents for :{iaocCode} period:{reportPeriod} type:{schemaId} year:{year}");
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                response.FaultMessage = ex.Message;
                response.Success      = false;
            }

            return(response);
        }