コード例 #1
0
        public async Task <List <AmountResume> > AmountResumes()
        {
            List <AmountResume> amountResumes = new List <AmountResume>();

            List <TransactionOutlay> transactions = await _contextDB.TransactionOutlay.Include(x => x.TypeTransaction)
                                                    .AsNoTracking()
                                                    .ToListAsync();

            var transactionsGroup = transactions.GroupBy(key =>
            {
                TransactionDTO transactionAux = key.ToTransactionDTO();
                TransactionKey trKey          = new TransactionKey(transactionAux.Date.Year,
                                                                   transactionAux.Date.Month);

                return(trKey);
            });

            double currentTotalAmount = 0.0d;

            foreach (var transactionGroupAux in transactionsGroup)
            {
                foreach (var transactionsAux in transactionGroupAux)
                {
                    switch (transactionsAux.TypeTransaction.Type)
                    {
                    case "SPENDING":
                        currentTotalAmount -= transactionsAux.Amount;
                        break;

                    default:
                        currentTotalAmount += transactionsAux.Amount;
                        break;
                    }
                }

                TransactionKey key = transactionGroupAux.Key;

                amountResumes.Add(new AmountResume()
                {
                    Year   = key.Year,
                    Month  = key.Month,
                    Amount = currentTotalAmount
                });
            }

            return(amountResumes);
        }
コード例 #2
0
        public string CreateManifest()
        {
            var dateFormatString = DateTime.Now.ToString("MMddyyyy");

            var plainText = StringUtils.PadRight(MerchantId, 20, ' ') +
                            StringUtils.PadRight(DeviceId, 24, ' ') +
                            "000000000000" +
                            StringUtils.PadRight(dateFormatString, 8, ' ');

            var tempTransactionKey = TransactionKey.Substring(0, 16);

            var byteArray = Encoding.UTF8.GetBytes(tempTransactionKey);
            var encrypted = new byte[0];

            using (Aes aesAlg = Aes.Create())
            {
                aesAlg.Padding   = PaddingMode.None;
                aesAlg.Mode      = CipherMode.CBC;
                aesAlg.BlockSize = 128;
                aesAlg.KeySize   = 128;
                aesAlg.Key       = byteArray;
                aesAlg.IV        = byteArray;
                ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);

                using (MemoryStream msEncrypt = new MemoryStream())
                {
                    using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
                    {
                        using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
                        {
                            swEncrypt.Write(plainText);
                        }
                        encrypted = msEncrypt.ToArray();
                    }
                }
            }
            var encryptedData = BitConverter.ToString(encrypted).ToLower().Replace("-", string.Empty);

            var hashKey = HashHmac(TransactionKey, TransactionKey);

            return(hashKey.Substring(0, 4) + encryptedData + hashKey.Substring(hashKey.Length - 4, 4));;
        }