Exemplo n.º 1
0
        public async Task <bool> DoesUserPaidForMatrixLevelAsync(int matrixLevel, Guid userMultiAccountId)
        {
            var userPayments = await _paymentHistoryRepository.GetPaymentsByUser(userMultiAccountId);

            return(userPayments.Any(
                       x => x.PaymentFor == PaymentForHelper.MatrixLevelPositionsDictionary[matrixLevel] &&
                       (x.Status == PaymentStatusHelper.Paid || x.Status == PaymentStatusHelper.Completed)
                       ));
        }
        public async Task <IEnumerable <PaymentHistoryModel> > Handle(GetPaymentHistoriesRequest request, CancellationToken cancellationToken)
        {
            var user = await _userAccountDataRepository.GetAsync(request.UserAccountId);

            if (user is null)
            {
                throw new AccountNotFoundException("User with given ID does not exist");
            }

            var allPayments = new List <PaymentHistoryModel>();

            var userPayments = await _paymentHistoryRepository.GetPaymentsByUser(user.Id);

            var userPaymentModels = _mapper.Map <List <PaymentHistoryModel> >(userPayments);

            foreach (var userPaymentModel in userPaymentModels)
            {
                userPaymentModel.AccountName = user.Login;
            }

            allPayments.AddRange(userPaymentModels);

            foreach (var userUserMultiAccount in user.UserMultiAccounts)
            {
                var payment = await _paymentHistoryRepository.GetPaymentsByUser(userUserMultiAccount.Id);

                var paymentModels = _mapper.Map <List <PaymentHistoryModel> >(payment);

                foreach (var paymentModel in paymentModels)
                {
                    paymentModel.AccountName = userUserMultiAccount.MultiAccountName;
                }

                allPayments.AddRange(paymentModels);
            }

            return(allPayments);
        }