public IHttpActionResult Post(WithdrawModel withdraw) { Withdrawal withdrawTemp = new Withdrawal(); var balance = Uow.Repository <Balance>().FirstOrDefault(a => a.UserId == withdraw.UserId); if (withdraw.Amount <= balance.BalanceAmount) { var account = Uow.Repository <AccountDetail>().FirstOrDefault(a => a.AccountNumber == withdraw.AccountNumber); var branch = Uow.Repository <BankBranch>().FirstOrDefault(a => (a.IFSC_Code == withdraw.IFSC) && (a.Bank.BankId == withdraw.BankId)); if (account != null && branch != null) { if (account.BankBranchId == branch.BankBranchId) { withdrawTemp.AccountId = account.AccountId; withdrawTemp.WithdrawalAmount = withdraw.Amount; withdrawTemp.UserId = withdraw.UserId; withdrawTemp.BankId = withdraw.BankId; var date = DateTime.Now; withdrawTemp.WithdrawDate = date; withdrawTemp.WithdrawStatus = true; withdrawTemp.BalanceId = balance.BalanceId; withdrawTemp.Comment = withdraw.Comment; var withdrawMessage = WithdrawDomain.Post(withdrawTemp); if (withdrawMessage == "Withdrawal Successfull!!") { var tempBalance = BalanceDomain.GetBy(withdraw.UserId); tempBalance.BalanceAmount = tempBalance.BalanceAmount - withdraw.Amount; var accountDetail = AccountDetailsDomain.Getby(account.AccountId); accountDetail.AccountBalance = accountDetail.AccountBalance + withdraw.Amount; BalanceDomain.Put(tempBalance); AccountDetailsDomain.Put(accountDetail); return(Ok("successfull")); } return(Ok("not successfull")); } else { return(Ok("error")); } } else { return(Ok("error")); } } else { return(Ok("error")); } }
public IHttpActionResult Post(DepositModel deposit) { //while (true) //{ // Card card = new Card(); // card.CardTypeId = 7; // card.CardCompanyId = 9; // card.CardHolderName = "shail"; // card.CardNumber = Encrypt("1212121212121212", true); // card.Cvv = 200; // card.ExpiryMonth = 12; // card.ExpiryYear = 24; // card.AccountId = 10; //} if ((deposit.DepositTypeId == 6) || (deposit.DepositTypeId == 7)) { Card cartObj = new Card(); var encrypt = Encrypt((deposit.CardNumber).ToString(), true); var card = Uow.Repository <Card>().FirstOrDefault(c => (c.CardNumber == encrypt) && (c.Cvv == deposit.CVV)); var balance = BalanceDomain.GetBy(19); if (card != null) { if (card.Amount >= deposit.DepositAmount) { Deposit depositObj = new Deposit(); depositObj.UserId = 19; depositObj.DepositStatus = true; if (deposit.DepositTypeId == 6) { depositObj.DepositTypeId = 3; } else { depositObj.DepositTypeId = 4; } var date = DateTime.Now; depositObj.DepositDate = date; depositObj.AccountId = card.AccountId; depositObj.BalanceId = balance.BalanceId; depositObj.DepositAmount = deposit.DepositAmount; var depositMessage = DepositDomain.Post(depositObj); if (depositMessage == "Deposit Successful!") { balance.BalanceAmount = balance.BalanceAmount + deposit.DepositAmount; card.Amount = card.Amount - deposit.DepositAmount; BalanceDomain.Put(balance); CardDomain.Put(card); return(Ok("successfull")); } else { return(Ok("error")); } } else { return(Ok("error")); } } else { return(Ok("error")); } } else if (deposit.DepositTypeId == 5) { var branch = Uow.Repository <BankBranch>().FirstOrDefault(b => b.IFSC_Code == deposit.IFSC); var account = Uow.Repository <AccountDetail>().FirstOrDefault(a => (a.AccountNumber == deposit.AccountNumber) && (a.BankBranchId == branch.BankBranchId)); if (account != null) { if (account.AccountBalance >= deposit.DepositAmount) { Deposit depositObj = new Deposit(); var date = DateTime.Now; depositObj.DepositDate = date; depositObj.UserId = deposit.UserId; depositObj.DepositStatus = true; depositObj.DepositTypeId = deposit.DepositTypeId; depositObj.AccountId = account.AccountId; var balance = BalanceDomain.GetBy(deposit.UserId); depositObj.BalanceId = balance.BalanceId; depositObj.DepositAmount = deposit.DepositAmount; var depositMessage = DepositDomain.Post(depositObj); if (depositMessage == "Deposit Successful!") { account.AccountBalance = account.AccountBalance - deposit.DepositAmount; AccountDetailsDomain.Put(account); balance.BalanceAmount = balance.BalanceAmount + deposit.DepositAmount; BalanceDomain.Put(balance); return(Ok("successfull")); } else { return(Ok("error")); } } else { return(Ok("error")); } } else { return(Ok("error")); } } else { return(Ok("error")); } }
public IHttpActionResult Post(OrderDetailsModel orderDetail) { if (orderDetail.PaymentTypeId == 33) { var encryption = Encrypt((orderDetail.CardNumber).ToString(), true); var card = Uow.Repository <Card>().FirstOrDefault(c => (c.CardNumber == encryption) && (c.Cvv == orderDetail.CVV)); if (card != null) { if (card.Amount >= orderDetail.Amount) { var cartList = Uow.Repository <Cart>().All(); if (cartList != null) { string message; int flag = 0; List <OrderDetail> orderDetailList = new List <OrderDetail>(); foreach (var item in cartList) { if (item.UserId == orderDetail.UserId) { OrderDetail detailTemp = new OrderDetail(); detailTemp.ProductId = item.ProductId; detailTemp.Quantity = item.Quantity; detailTemp.SubTotal = item.SubTotal; var product = Uow.Repository <Product>().FirstOrDefault(p => p.ProductId == item.ProductId); detailTemp.DiscountId = product.DiscountId; detailTemp.OrderId = orderDetail.OrderId; orderDetailList.Add(detailTemp); } } if (orderDetailList != null) { try { message = (OrderDetailDomain.Post(orderDetailList)); if (message != "Order Placed!!") { flag = 1; } } catch (Exception ex) { throw ex; } } if (flag != 1) { var Order = Uow.Repository <Order>().FirstOrDefault(o => o.OrderId == orderDetail.OrderId); Order.OrderStatus = "true"; Order.PaymentTypeId = orderDetail.PaymentTypeId; OrderDomain.Put(Order); card.Amount = card.Amount - orderDetail.Amount; CardDomain.Put(card); return(Ok("items ordered")); } else { return(Ok("Order Not Placed!")); } } else { return(Ok("cart is empty")); } } else { return(Ok("Insufficient amount in card")); } } else { return(Ok()); } } else if (orderDetail.PaymentTypeId == 34) { var balanceCheck = BalanceDomain.GetBy(orderDetail.UserId); if (balanceCheck.BalanceAmount >= orderDetail.Amount) { balanceCheck.BalanceAmount = balanceCheck.BalanceAmount - orderDetail.Amount; var message = BalanceDomain.Put(balanceCheck); if (message == "Item Updated.") { return(Ok("items ordered")); } else { return(Ok()); } } else { return(Ok("balance is not enough")); } } else { return(Ok("error")); } }