[Route("api/hajjCoin/VerifyTransaction/{cardQR}/{Total}")]///{SupplierID}")] public IHttpActionResult VerifyTransaction(string cardQR, int Total) { var cQR = Guid.Parse(cardQR); //return class contains password or not found if there is no password Messages msg = new Messages(); using (db = new HajjCoinsModel()) { configCards configCards = new configCards(); var card = db.configCards.Where(a => a.CardID == cQR).ToList(); if (card.Count > 0) { var coin = db.configCards.Where(m => m.NoOfCoins >= Total).ToList(); //Check no of coins if (coin.Count > 0) { msg.message = "Amount of " + Total + " hajjCoins will be debited from your account."; msg.status = true; return(Ok(msg)); } else { msg.message = "Your hajjCoins balance is not enough"; msg.status = false; return(Ok(msg)); } } else { msg.message = "Your hajjCoins card Not Found"; msg.status = false; return(Ok(msg)); } } }
public IHttpActionResult PerformTransaction(string cardQR, int Total, int SupplierID, int password) { var cQR = Guid.Parse(cardQR); //return class contains password or not found if there is no password Messages msg = new Messages(); using (db = new HajjCoinsModel()) { configCards configCards = new configCards(); var CoinsCount = db.configCards.Where(a => a.CardID == cQR).Select(a => a.NoOfCoins).FirstOrDefault(); if (CoinsCount >= Total) { //var coinsList = db.Coins.Where(a => a.CardID == cQR).ToList(); //var validCoins = (from coinsList in db.Coins // join usedList in db.TransactionsCoinsSupplier // on coinsList.CoinID equals usedList.CoinsID // where db.TransactionsCoinsSupplier.Contains(usedList.CoinsID) // select new { coinsList.CoinID }).ToList(); var trans_coinList = db.TransactionsCoinsSupplier.Select(x => x.CoinsID).ToArray(); var validCoins = db.Coins.Where(p => !trans_coinList.Contains(p.CoinID)).ToList(); if (validCoins.Count > 0) { var cardCoin = db.configCards.Where(a => a.CardID == cQR).FirstOrDefault(); db.Entry(cardCoin).State = EntityState.Modified; cardCoin.NoOfCoins -= Total; db.SaveChanges(); Transaction tr = new Transaction(); tr.TotalCoinsUsed = Total; tr.TransactionDate = System.DateTime.Now; tr.SupplyerID = SupplierID; db.Transaction.Add(tr); db.SaveChanges(); for (int i = 0; i < Total; i++) { TransactionsCoinsSupplier coin = new TransactionsCoinsSupplier(); coin.CoinsID = validCoins[i].CoinID; coin.TransactionID = tr.TransactionID; db.TransactionsCoinsSupplier.Add(coin); } msg.message = Total + " hajjCoins successfully received"; msg.status = true; return(Ok(msg)); } else { msg.message = "Your hajjCoins balance is not enough"; msg.status = false; return(Ok(msg)); } } else { msg.message = "Your hajjCoins balance is not enough"; msg.status = false; return(Ok(msg)); } } }