Пример #1
0
        public void SetIbisFileData(IbisFileData ibisFileData)
        {
            Guard.ArgumentNotNull(() => ibisFileData, ibisFileData);

            if (CompetentAuthority.Name != "Environment Agency")
            {
                string errorMessage = "1B1S files can only be provided for the Environment Agency. Devolved agencies do not use 1B1S.";
                throw new InvalidOperationException(errorMessage);
            }

            if (IbisFileData != null)
            {
                string errorMessage = "Once 1B1S files have been provided for an invoice run, they cannot be replaced.";
                throw new InvalidOperationException(errorMessage);
            }

            IbisFileData = ibisFileData;
        }
Пример #2
0
        public void SetIbisFileData(IbisFileData ibisFileData)
        {
            Guard.ArgumentNotNull(() => ibisFileData, ibisFileData);

            if (CompetentAuthority.Name != "Environment Agency")
            {
                string errorMessage = "1B1S files can only be provided for the Environment Agency. Devolved agencies do not use 1B1S.";
                throw new InvalidOperationException(errorMessage);
            }

            if (IbisFileData != null)
            {
                string errorMessage = "Once 1B1S files have been provided for an invoice run, they cannot be replaced.";
                throw new InvalidOperationException(errorMessage);
            }

            IbisFileData = ibisFileData;
        }
        /// <summary>
        /// Creates the data representing 1B1S customer and transaction files for the specified list
        /// of member uploads.
        /// </summary>
        /// <param name="fileID">The ID that the 1B1S files will use. This must be unique for every pair of 1B1S files
        /// and must be in the range of 0 to 99999. To avoid clashes with IDs used by the incumbent system, a seed
        /// value may need to be used.</param>
        /// <param name="invoiceRun">The invoice run specifying the list of member uploads to be included.</param>
        /// <returns>Returns an <see cref="IbisFileDataGeneratorResult"/> which provides the data and file names of the
        /// generated 1B1S customer and transaction files or a list of error which occurred during the process.</returns>
        public async Task<IbisFileDataGeneratorResult> CreateFileDataAsync(ulong fileID, InvoiceRun invoiceRun)
        {
            var customerFileGeneratorResult = await ibisCustomerFileGenerator.CreateAsync(fileID, invoiceRun);
            var ibisTransactionFileGeneratorResult = await ibisTransactionFileGenerator.CreateAsync(fileID, invoiceRun);

            IbisFileData ibisFileData = null;
            var errors = new List<string>();

            if (customerFileGeneratorResult.Errors.Count == 0 &&
                ibisTransactionFileGeneratorResult.Errors.Count == 0)
            {
                CustomerFile customerFile = customerFileGeneratorResult.IbisFile;
                TransactionFile transactionFile = ibisTransactionFileGeneratorResult.IbisFile;

                string customerFileName = string.Format("WEEHC{0:D5}.dat", fileID);
                string transactionFileName = string.Format("WEEHI{0:D5}.dat", fileID);

                string customerFileData = customerFile.Write();
                string transactionFileData = transactionFile.Write();

                ibisFileData = new IbisFileData(
                    fileID,
                    customerFileName,
                    customerFileData,
                    transactionFileName,
                    transactionFileData);
            }
            else
            {
                errors = ibisFileDataErrorTranslator
                    .MakeFriendlyErrorMessages(customerFileGeneratorResult
                                               .Errors
                                               .Union(ibisTransactionFileGeneratorResult.Errors)
                                               .ToList());
            }

            return new IbisFileDataGeneratorResult(ibisFileData, errors);
        }