Exemplo n.º 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));
        }
        public IHttpActionResult PostAccount_Holder(ForgotCustomerId forgotCustomerId)
        {
            if (forgotCustomerId.email_id == db.fetchemail(forgotCustomerId.account_no).FirstOrDefault())
            {
                int onetimepassword = random.Next(10000, 99999);
                db.insertotp(onetimepassword);
                SendOtp(forgotCustomerId.email_id, onetimepassword);
                return(Ok("otp sent"));
            }
            else
            {
                return(Ok("not matched"));
            }
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}

            //db.Account_Holder.Add(account_Holder);

            //try
            //{
            //    db.SaveChanges();
            //}
            //catch (DbUpdateException)
            //{
            //    if (Account_HolderExists(account_Holder.account_no))
            //    {
            //        return Conflict();
            //    }
            //    else
            //    {
            //        throw;
            //    }
            //}

            //return CreatedAtRoute("DefaultApi", new { id = account_Holder.account_no }, account_Holder);
        }