Ejemplo n.º 1
0
        public async Task <ServiceResult <int> > UpdateAsync(ClaimsPrincipal user, int groupId, int transactionId, TransactionRequestModel transaction)
        {
            var group = groupsRepository.Get(groupId);

            if (group is null)
            {
                return(ServiceResult <int> .Error(404, "Group was not found"));
            }

            var authorizationResult = await authorizationService.AuthorizeAsync(user, group, GroupOperations.Write);

            if (!authorizationResult.Succeeded)
            {
                return(ServiceResult <int> .Error(401, "Unauthorized"));
            }

            var transactionEntity = transactionsRepository.Get(transactionId);

            if (transactionEntity is null || transactionEntity.GroupId != groupId)
            {
                return(ServiceResult <int> .Error(404, "Transaction was not found"));
            }

            transactionEntity.Amount      = transaction.Amount;
            transactionEntity.Description = transaction.Description;
            transactionEntity.CategoryId  = transaction.CategoryId;

            var result = await transactionsRepository.UpdateAsync(transactionEntity);

            if (result is null)
            {
                return(ServiceResult <int> .Error(500, "Could not update transaction"));
            }
            return(ServiceResult <int> .Success(TransactionViewModel.FromModel(result)));
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        /// <summary>
        /// Gets the transactions view model.
        /// </summary>
        /// <param name="umbracoContext">The umbraco context.</param>
        /// <returns></returns>
        public IEnumerable <BraintreeTransactionViewModel> GetTransactionsViewModel(UmbracoContext umbracoContext)
        {
            loggingService.Info(GetType());

            List <BraintreeTransactionViewModel> viewModels = new List <BraintreeTransactionViewModel>();

            PaymentSettingsModel model = paymentProvider.GetPaymentSettingsModel(umbracoContext);

            if (model.PaymentsEnabled)
            {
                transactionsRepository.SetKey(umbracoContext);

                bool exists = transactionsRepository.Exists();

                if (exists)
                {
                    return(transactionsRepository.Get <IEnumerable <BraintreeTransactionViewModel> >());
                }

                ResourceCollection <Transaction> transactions = paymentProvider.GetBraintreeTransactions(model);

                viewModels = (from Transaction transaction
                              in transactions
                              select transactionTranslator.Translate(transaction))
                             .ToList();

                transactionsRepository.Add(viewModels);
            }

            return(viewModels);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var transaction = await _transactionsRepository.Get(id);

            if (transaction == null)
            {
                return(NotFound());
            }

            return(View(transaction));
        }
Ejemplo n.º 4
0
        public Transactions GetAccount(int id) //for specific ID with /id
        {
            Transactions item = trepository.Get(id);

            if (item == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            return(item);
        }
        public async Task UpdateTransaction(string userId, TransactionModel transaction)
        {
            try
            {
                UserModel user = await _userRepository.Get(userId);

                TransactionModel oldTransaction = await _transactionRepository.Get(transaction._id);

                if (transaction.Amount != oldTransaction.Amount)
                {
                    user.Wallets.Add(await UpdateWalletForUpdatedTransaction(user, transaction, oldTransaction));
                }

                await _transactionRepository.Update(transaction._id, transaction);

                await _userRepository.Update(userId, user);
            } catch (Exception e)
            {
                throw new Exception();
            }
        }
 public Transaction Get([FromRoute] long id)
 {
     return(repository.Get(id));
 }