public async Task <IHttpActionResult> buyBulkVoucher(int userID, decimal BulkVoucherAmount) { if (isUserReseller(userID)) { //need to check if reseller has the available funds in bank account - else return bad request or err page //transfer money from reseller bank account to nanoFin account voucher newVoucher = new voucher(); newVoucher.User_ID = userID; newVoucher.voucherValue = BulkVoucherAmount; newVoucher.VoucherType_ID = 1; newVoucher.voucherCreationDate = DateTime.Now; db.vouchers.Add(newVoucher); db.SaveChanges(); addVoucherTransaction(newVoucher.Voucher_ID, newVoucher.Voucher_ID, userID, 1, BulkVoucherAmount, 1); //buy bulk transaction on blockchain MResellerController resellerCtrl = new MResellerController(userID); resellerCtrl = await resellerCtrl.init(); await resellerCtrl.buyBulk(Decimal.ToInt32(BulkVoucherAmount)); return(Ok()); } else { return(BadRequest("User not a valid reseller")); } }
//Send bulk voucher recipient details known public async Task <IHttpActionResult> sendBulkVoucher(int resellerUserID, int recipientID, decimal transferAmount) { if (isUserReseller(resellerUserID)) { if (recipientID > 0) { if (getVoucherAccountBalance(resellerUserID) < transferAmount) { return(BadRequest("invalid funds")); // or custom responce for invalid funds } else { SendVoucher(resellerUserID, recipientID, transferAmount, 2, 2); MResellerController resellerCtrl = new MResellerController(resellerUserID); resellerCtrl = await resellerCtrl.init(); await resellerCtrl.sendBulk(recipientID, Decimal.ToInt32(transferAmount)); } } else { return(BadRequest("Recipient details not valid")); } return(Ok()); } else { return(BadRequest("User not a valid reseller")); } }
public async Task <bool> resellerBuyBulk(int userID, int amount) { MResellerController resellerCtrl = new MResellerController(userID); resellerCtrl = await resellerCtrl.init(); await resellerCtrl.buyBulk(Decimal.ToInt32(amount)); return(true); }