public async Task <int> Create(TransactionServiceModel model)
        {
            var entity = new Transaction
            {
                Price          = model.Price,
                Description    = model.Description,
                SentDate       = DateTime.Now,
                CreateByUserId = model.CreateByUser.Id,
                SendToUserId   = model.SendToUser.Id
            };
            await _context.Transactions.AddAsync(entity);

            int addedRows = await _context.SaveChangesAsync();

            if (addedRows > 0)
            {
                var donator = await _userManager.Users.Where(x => x.Id == entity.CreateByUserId).FirstOrDefaultAsync();

                donator.TotalAmount -= entity.Price;
                var resivedUser = await _userManager.Users.Where(x => x.Id == entity.SendToUserId).FirstOrDefaultAsync();

                resivedUser.TotalAmount += entity.Price;
                await _userManager.UpdateAsync(donator);

                await _userManager.UpdateAsync(resivedUser);
            }

            return(addedRows);
        }
        public IEnumerable <TransactionServiceModel> GetAllTransactionsByUserId(int userId, string direction)
        {
            string query = string.Empty;

            if (direction == "notfinished")
            {
                query = QueryConstants.GetAllTransactionByUserIdOrderedByNotFinished;
            }
            else
            {
                query = QueryConstants.GetAllTransactionsByUserId;
            }

            var reader = this.ExecuteReader(query, new Dictionary <string, object> {
                { "userId", userId }
            });

            var transactions = new List <TransactionServiceModel>();

            while (reader.Read())
            {
                var transferId   = (int)reader[0];
                var senderIban   = (string)reader[1];
                var receiverIban = (string)reader[2];
                var amount       = (decimal)reader[3];
                var description  = (string)reader[4];
                var isFinished   = (bool)reader[5];

                var transaction = new TransactionServiceModel(transferId, senderIban, receiverIban, amount, description, isFinished);

                transactions.Add(transaction);
            }

            return(transactions);
        }
Exemplo n.º 3
0
 public SearchController(IBlockInfoRepository blockInfoRepository,
                         TransactionServiceModel transactionServiceModel, AccountServiceModel accountServiceModel)
 {
     _blockInfoRepository     = blockInfoRepository;
     _transactionServiceModel = transactionServiceModel;
     _accountServiceModel     = accountServiceModel;
 }
Exemplo n.º 4
0
        public Result <TransactionServiceModel> Add(TransactionServiceModel transaction, CurrentUser currentUser, CurrentGroup currentGroup)
        {
            var result = new Result <TransactionServiceModel>();

            try
            {
                var transactionEntity = new Transaction()
                {
                    Amount     = transaction.Amount,
                    ReceiverId = transaction.ReceiverId,
                    SenderId   = transaction.SenderId,
                    IsComplete = false,
                    IsActive   = true,
                    UserId     = transaction.UserId,
                    GroupId    = transaction.GroupId,
                    CreatedOn  = Application.CurrentDate,
                    CreatedBy  = currentUser.Id
                };
                _unitOfWork.TransactionRepository.Add(transactionEntity);
                _unitOfWork.Save();

                var transactionServiceModel = _mapper.Map <TransactionServiceModel>(transactionEntity);
                result.IsSuccess = true;
                result.Data      = transactionServiceModel;

                return(result);
            }
            catch (Exception ex)
            {
                _logger.LogCritical(ex.InnerException.Message);
                result.IsSuccess    = false;
                result.ErrorMessage = ErrorMessage.Add;
                return(result);
            }
        }
Exemplo n.º 5
0
        public void UpdateData(TransactionServiceModel model)
        {
            DateLabel.Text         = model.DisplayDate;
            MerchantNameLabel.Text = model.Merchant;
            SummaryLabel.Text      = model.Summary;
            AmountLabel.Text       = model.DisplayAmount;

            InvokeOnMainThread(() =>
            {
                SetMerchantImage(model.MerchantImageUrl);
            });
        }
        public async Task FetchTransactionDetailCommand(int transactionId, bool showLoadingIndicator = true)
        {
            try
            {
                ShowLoadingIndicator("Loading Transaction", showLoadingIndicator);

                var transactionDetail = await TransactionService.GetTransactionDetail(transactionId);

                Transaction = transactionDetail;

                HideLoadingIndicator(showLoadingIndicator);
            }
            catch (Exception ex)
            {
                LogExceptionAndShowMessage(ex, "Something went wrong with getting transactions, please contact support");
            }
        }
Exemplo n.º 7
0
        public Result <TransactionServiceModel> Update(TransactionServiceModel group, CurrentUser currentUser, CurrentGroup currentGroup)
        {
            var result = new Result <TransactionServiceModel>();

            try
            {
                var transactionEntity = _unitOfWork.TransactionRepository.GetSingle(x => x.IsActive && x.Id == group.Id && x.UserId == currentUser.Id && x.GroupId == currentGroup.Id);
                if (transactionEntity != null)
                {
                    transactionEntity.Amount     = group.Amount;
                    transactionEntity.ReceiverId = group.ReceiverId;
                    transactionEntity.SenderId   = group.SenderId;
                    transactionEntity.IsComplete = group.IsComplete;
                    transactionEntity.UpdatedOn  = Application.CurrentDate;
                    transactionEntity.UpdatedBy  = currentUser.Id;
                    _unitOfWork.Save();

                    var transactionEntityService = _mapper.Map <TransactionServiceModel>(transactionEntity);
                    result.IsSuccess = false;
                    result.Data      = transactionEntityService;
                    return(result);
                }
                else
                {
                    result.IsSuccess    = false;
                    result.ErrorMessage = ErrorMessage.UpdateUnAuth;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                _logger.LogCritical(ex.InnerException.Message);
                result.IsSuccess    = true;
                result.ErrorMessage = ErrorMessage.Update;
                return(result);
            }
        }
        public IEnumerable <TransactionServiceModel> GetLatestSixTransationsById(int id)
        {
            var reader = this.ExecuteReader(QueryConstants.GetAllTransfersByUserId, new Dictionary <string, object> {
                { "userId", id }
            });

            var transactions = new List <TransactionServiceModel>();

            while (reader.Read())
            {
                var transferId   = (int)reader[0];
                var senderIban   = (string)reader[1];
                var receiverIban = (string)reader[2];
                var amount       = (decimal)reader[3];
                var description  = (string)reader[4];
                var isFinished   = (bool)reader[5];

                var transaction = new TransactionServiceModel(transferId, senderIban, receiverIban, amount, description, isFinished);

                transactions.Add(transaction);
            }

            return(transactions);
        }
Exemplo n.º 9
0
 public TransactionController(TransactionServiceModel transactionServiceModel)
 {
     _transactionServiceModel = transactionServiceModel;
 }
Exemplo n.º 10
0
 public void MakePayment(TransactionServiceModel data, Action <string> success, Action <string> failure)
 {
     data.type = TransactionType.Sale.ToDescription();
     ExecuteAction(data, success, failure);
 }
Exemplo n.º 11
0
        public bool FinishTransactionById(int id, int currentUserId)
        {
            var reader = this.ExecuteReader(QueryConstants.CheckIfTransferIsCorrectWithIdAndUserId, new Dictionary <string, object>
            {
                { "@userId", currentUserId },
                { "@transactionId", id }
            });

            if (!reader.HasRows)
            {
                return(false);
            }

            reader.Close();

            var transactionReader = this.ExecuteReader(QueryConstants.GetTransactionById, new Dictionary <string, object> {
                { "@transactionId", id }
            });

            if (!transactionReader.HasRows)
            {
                return(false);
            }

            TransactionServiceModel transaction = null;

            while (transactionReader.Read())
            {
                var transactionId = (int)transactionReader[0];
                var senderIban    = (string)transactionReader[1];
                var receiverIban  = (string)transactionReader[2];
                var amount        = (decimal)transactionReader[3];
                var description   = (string)transactionReader[4];
                var isFinished    = (bool)transactionReader[5];

                transaction = new TransactionServiceModel(transactionId, senderIban, receiverIban, amount, description, isFinished);
            }

            transactionReader.Close();

            var senderIbanReader = this.ExecuteReader(QueryConstants.GetBillByIBAN, new Dictionary <string, object> {
                { "@iban", transaction.SenderIban }
            });

            if (!senderIbanReader.HasRows)
            {
                return(false);
            }

            BillServiceModel senderBill = null;

            while (senderIbanReader.Read())
            {
                var iban         = (string)senderIbanReader[0];
                var senderAmount = (decimal)senderIbanReader[1];

                senderBill = new BillServiceModel(iban, senderAmount);
            }

            senderIbanReader.Close();

            var receiverIbanReader = this.ExecuteReader(QueryConstants.GetBillByIBAN, new Dictionary <string, object> {
                { "@iban", transaction.ReceiverIban }
            });

            if (!receiverIbanReader.HasRows)
            {
                return(false);
            }

            BillServiceModel receiverBill = null;

            while (receiverIbanReader.Read())
            {
                var iban         = (string)receiverIbanReader[0];
                var senderAmount = (decimal)receiverIbanReader[1];

                receiverBill = new BillServiceModel(iban, senderAmount);
            }

            receiverIbanReader.Close();

            if (senderBill.Amount < transaction.Amount)
            {
                return(false);
            }

            var senderLeftMoney   = senderBill.Amount -= transaction.Amount;
            var receiverLeftMoney = receiverBill.Amount += transaction.Amount;

            var updateSenderAmount = this.ExecuteNonQuery(QueryConstants.UpdateBill, new Dictionary <string, object>
            {
                { "@amount", senderLeftMoney },
                { "@iban", senderBill.IBAN }
            });

            if (updateSenderAmount != 1)
            {
                return(false);
            }

            var updateReceiverAmount = this.ExecuteNonQuery(QueryConstants.UpdateBill, new Dictionary <string, object>
            {
                { "@amount", receiverLeftMoney },
                { "@iban", receiverBill.IBAN }
            });

            if (updateReceiverAmount != 1)
            {
                return(false);
            }

            var updateTransferToFinish = this.ExecuteNonQuery(QueryConstants.UpdateTransferToFinished, new Dictionary <string, object> {
                { "@transactionId", id }
            });

            return(updateTransferToFinish == 1);
        }