Ejemplo n.º 1
0
        public TransactionModel AddTransaction(TransactionModel transactionModel)
        {
            Log.Information("File Name: " + _stackFrame.GetMethod().DeclaringType.Name + ".cs " + "NameSpace: " + _stackFrame.GetMethod().DeclaringType.Namespace + " Method Name: AddTransaction()");
            TransactionModel transactionResultModel = new TransactionModel();

            if (transactionModel?.ScratchCardGUID > 0 && transactionModel.UserId > 0)
            {
                int  scratchCardBalanceAmount = _transactionRespository.GetScratchCardBalanceAmount(transactionModel.ScratchCardGUID);
                bool isValidScratchCard       = _scratchCardRepository.IsUnusedAndValidScratchCardId(transactionModel.ScratchCardGUID);
                bool IsValidUser = _userRespository.IsValidUser(transactionModel.UserId);
                if (transactionModel.Amount <= scratchCardBalanceAmount && isValidScratchCard && IsValidUser)
                {
                    try
                    {
                        transactionModel.DateofTransaction = DateTime.Now.Date;
                        var     config      = _mapperProfile.MapperTransactionEntity();
                        IMapper iMapper     = config.CreateMapper();
                        var     transaction = iMapper.Map <TransactionModel, Transaction>(transactionModel);

                        var transactionsResult = _transactionRespository.AddTransaction(transaction);
                        transactionResultModel = iMapper.Map <Transaction, TransactionModel>(transactionsResult);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Error Message: " + ex.Message + " " + ex.StackTrace + System.Environment.NewLine);
                        throw;
                    }
                }
            }
            Log.Information("File Name: " + _stackFrame.GetMethod().DeclaringType.Name + ".cs " + "AddTransaction() Method Executed Successfully");
            return(transactionResultModel);
        }