Exemplo n.º 1
0
        public ResultOfOperation ReplaceCard(PaidByUsTransactionDTO transaction, ClassUsers user, int cause)
        {
            var      creditcard        = new CreditCard();
            var      transactionLog    = new PaidByUsCreditCardTransactionLog();
            var      resultOfOperation = new ResultOfOperation();
            Entities dblog             = new Entities();

            var activeLog = dblog.PaidByUsCreditCardTransactionLog.FirstOrDefault(x => x.PaidByUsTransactionId == transaction.Id && x.Active.Value == true);

            if (activeLog == null)
            {
                resultOfOperation.Message = "Active Log Not found";
            }
            else
            {
                activeLog.ReplacementCause = cause;
                dblog.SaveChanges();
                try
                {
                    using (Entities db = new Entities())
                    {
                        var lasttransactionLog = db.PaidByUsCreditCardTransactionLog.FirstOrDefault(x => x.id == activeLog.id);
                        if (lasttransactionLog == null)
                        {
                            resultOfOperation.Message = "Active Log Not found in DB: " + activeLog.id;
                        }
                        else
                        {
                            lasttransactionLog.Active           = false;
                            lasttransactionLog.ReplacementCause = cause;
                            creditcard = ApllyGetCardAlgorithm(user.WorkerClockId, transaction);
                            //transactionLog.ImageName = creditcard.ComputeHashForImage();
                            transactionLog.Active = true;
                            transactionLog.PaidByUsTransactionId = transaction.Id;
                            transactionLog.CreditCardRecId       = creditcard.RecId;
                            //DB Operations
                            db.PaidByUsCreditCardTransactionLog.Add(transactionLog);
                            db.SaveChanges();
                            transaction.UpdateInDataBase(user);
                            resultOfOperation.Additional = transaction.Id.ToString();
                            resultOfOperation.Success    = true;
                        }
                    }
                }
                catch (Exception e)
                {
                    resultOfOperation.Success = false;
                    resultOfOperation.Message = e.Message;
                }
            }
            return(resultOfOperation);
        }
Exemplo n.º 2
0
        public ResultOfOperation CreateNewTransaction(PaidByUsTransactionDTO transaction, ClassUsers user)
        {
            var creditcard        = new CreditCard();
            var resultOfOperation = new ResultOfOperation();

            try
            {
                transaction.Status = (int)Amsalem.Types.Status.Pending;
                //Credit Card Operations
                creditcard = ApllyGetCardAlgorithm(user.WorkerClockId, transaction);

                //TransactionLog Initial
                var transactionLog = new PaidByUsCreditCardTransactionLog();
                transactionLog.Active = true;
                //transactionLog.PaidByUsTransactionId = transaction.Id;
                transactionLog.CreditCardRecId = creditcard.RecId;

                transaction.PaidByUsCreditCardTransactionLog = new List <PaidByUsCreditCardTransactionLog>();

                transaction.PaidByUsCreditCardTransactionLog.Add(transactionLog);

                //DB Operations
                transaction.UpdateInDataBase(user);

                resultOfOperation.Additional = transaction.Id.ToString();
                resultOfOperation.Success    = true;
            }

            catch (Exception e)
            {
                resultOfOperation.Success     = false;
                resultOfOperation.Additional4 = e.Message;
            }

            return(resultOfOperation);
        }