Пример #1
0
        public IHttpActionResult PostTransaction(Transaction transaction)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var validpassword   = db.Account_Holder.Where(a => a.trans_pass == transaction.trans_pass && a.account_no == transaction.account_no).FirstOrDefault();
            var insufficientamt = db.Account_Holder.Where(a => a.balance >= transaction.amount && a.account_no == transaction.account_no).FirstOrDefault();

            if (validpassword != null && insufficientamt != null)
            {
                //transaction.ref_id = "RefNEFT" + "@" + random.Next(10000, 99999).ToString();
                transaction.mode = "neft";
                DateTime myDateTime = DateTime.Now;
                transaction.trans_date = myDateTime;
                db.debit_account(transaction.account_no, transaction.amount);
                db.credit_account(transaction.recipient_acct, transaction.amount);
                transaction.sender_updated_debit     = db.updated_balance(transaction.account_no).FirstOrDefault();
                transaction.recipient_updated_credit = db.updated_balance(transaction.recipient_acct).FirstOrDefault();
                db.Transactions.Add(transaction);

                try
                {
                    db.SaveChanges();
                }

                catch (DbUpdateException)
                {
                    if (TransactionExists(transaction.ref_id))
                    {
                        return(Conflict());
                    }
                    else
                    {
                        throw;
                    }
                }
                Sendneftsuccessdebited(db.fetchemail(transaction.account_no).FirstOrDefault(), transaction.ref_id, transaction.amount, transaction.mode, transaction.recipient_acct, transaction.trans_date, transaction.remarks);
                Sendneftsuccesscredited(db.fetchemail(transaction.recipient_acct).FirstOrDefault(), transaction.ref_id, transaction.amount, transaction.mode, transaction.account_no, transaction.trans_date, transaction.remarks);

                return(Ok("success"));
            }

            if (validpassword == null)
            {
                return(Ok("invalidpass"));
            }
            if (insufficientamt == null)
            {
                return(Ok("notenoughbalance"));
            }

            return(CreatedAtRoute("DefaultApi", new { id = transaction.ref_id }, transaction));
        }