Beispiel #1
0
        public async Task <ChargeStorageStatus> StoreChargeAsync(ChangeOfChargesTransaction transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            var chargeType = await GetChargeTypeAsync(transaction).ConfigureAwait(false);

            if (chargeType == null)
            {
                return(ChargeStorageStatus.CreateFailure($"No charge type for {transaction.Type}"));
            }

            var resolutionType = await GetResolutionTypeAsync(transaction).ConfigureAwait(false);

            if (resolutionType == null)
            {
                return(ChargeStorageStatus.CreateFailure($"No resolution type for {transaction.Period?.Resolution}"));
            }

            var vatPayerType = await GetVatPayerTypeAsync(transaction).ConfigureAwait(false);

            if (vatPayerType == null)
            {
                return(ChargeStorageStatus.CreateFailure($"No VAT payer type for {transaction.MktActivityRecord?.ChargeType?.VatPayer}"));
            }

            var chargeTypeOwnerMRid = await GetChargeTypeOwnerMRidAsync(transaction).ConfigureAwait(false);

            if (chargeTypeOwnerMRid == null)
            {
                return(ChargeStorageStatus.CreateFailure($"No market participant for {transaction.ChargeTypeOwnerMRid}"));
            }

            var charge = ChangeOfChargesMapper.MapChangeOfChargesTransactionToCharge(transaction, chargeType, chargeTypeOwnerMRid, resolutionType, vatPayerType);

            await _chargesDatabaseContext.Charge.AddAsync(charge).ConfigureAwait(false);

            await _chargesDatabaseContext.SaveChangesAsync().ConfigureAwait(false);

            return(ChargeStorageStatus.CreateSuccess());
        }
        public async Task <ChargeStorageStatus> StoreChargeAsync(ChangeOfChargesMessage chargeMessage)
        {
            var chargeType = await GetChargeTypeAsync(chargeMessage).ConfigureAwait(false);

            if (chargeType == null)
            {
                return(ChargeStorageStatus.CreateFailure($"No charge type for {chargeMessage.Type}"));
            }

            var resolutionType = await GetResolutionTypeAsync(chargeMessage).ConfigureAwait(false);

            if (resolutionType == null)
            {
                return(ChargeStorageStatus.CreateFailure($"No resolution type for {chargeMessage.Period?.Resolution}"));
            }

            var vatPayerType = await GetVatPayerTypeAsync(chargeMessage).ConfigureAwait(false);

            if (vatPayerType == null)
            {
                return(ChargeStorageStatus.CreateFailure($"No VAT payer type for {chargeMessage.MktActivityRecord?.ChargeType?.VATPayer}"));
            }

            var chargeTypeOwnerMRid = await GetChargeTypeOwnerMRidAsync(chargeMessage) !.ConfigureAwait(false);

            if (chargeTypeOwnerMRid == null)
            {
                return(ChargeStorageStatus.CreateFailure($"No market participant for {chargeMessage.ChargeTypeOwnerMRid}"));
            }

            var charge = ChangeOfChargesMapper.MapChangeOfChargesMessageToCharge(chargeMessage, chargeType, chargeTypeOwnerMRid, resolutionType, vatPayerType);

            await _chargesDatabaseContext.Charge.AddAsync(charge);

            await _chargesDatabaseContext.SaveChangesAsync().ConfigureAwait(false);

            return(ChargeStorageStatus.CreateSuccess());
        }