public bool ModifyHistory(int voucherID, int consumerVoucherID) { List <voucher> voucherlist = (from c in db.vouchers where c.VoucherType_ID == 1 && c.Voucher_ID > voucherID select c).ToList(); //consumer [] consumerList = (from c in db.consumers select c).ToArray(); voucher[] consumerVouchers = (from c in db.vouchers where c.VoucherType_ID == 2 && c.Voucher_ID > consumerVoucherID select c).ToArray(); int counter = 1; foreach (voucher temp in voucherlist) { int value = (int)temp.voucherValue; decimal amount = (Decimal)(value * 0.2); voucher cons = consumerVouchers[counter]; for (int i = 0; i < 5; i++) { //counter++; consumerVouchers[counter].voucherValue = amount; addVoucherTransaction(consumerVouchers[counter].Voucher_ID, temp.Voucher_ID, cons.User_ID, temp.User_ID, amount, 2, (DateTime)consumerVouchers[counter].voucherCreationDate); db.SaveChanges(); } temp.voucherValue = 0; db.SaveChanges(); } return(true); }
//POST...add a voucher: use cases involved: //-reseller buys voucher online= reseller gets a brand new bulk voucher added //-= consumer gets a brand new normal voucher added //PUT...update a voucher: use cases involved: //-reseller sends voucher= update reseller's voucher amount public IHttpActionResult SendVoucher(int senderID, int receiverID, decimal amountToSend, int transactionType_ID, int voucherTypeID) { if (getVoucherAccountBalance(senderID) < amountToSend) { return(BadRequest("invalid funds")); // or custom responce for invalid funds } Decimal toDeduct = amountToSend; List <voucher> senderVouchers = (from c in db.vouchers where c.User_ID == senderID && c.voucherValue > 0 orderby c.voucherValue ascending select c).ToList(); voucher newVoucher = new voucher(); newVoucher.User_ID = receiverID; newVoucher.voucherValue = amountToSend; newVoucher.VoucherType_ID = voucherTypeID; DateTime now = DateTime.Now; now.ToString("yyyy-MM-dd H:mm:ss"); newVoucher.voucherCreationDate = now; db.vouchers.Add(newVoucher); db.SaveChanges(); for (int i = 0; i < senderVouchers.Count && toDeduct > 0; i++) { voucher temp = senderVouchers.ElementAt(i); if (toDeduct >= temp.voucherValue) { toDeduct -= temp.voucherValue; addVoucherTransaction(newVoucher.Voucher_ID, temp.Voucher_ID, receiverID, senderID, temp.voucherValue, transactionType_ID); temp.voucherValue = 0; } else { temp.voucherValue -= toDeduct; addVoucherTransaction(newVoucher.Voucher_ID, temp.Voucher_ID, receiverID, senderID, toDeduct, transactionType_ID); toDeduct = 0; } } return(Ok()); }
public IHttpActionResult Postproduct(DTOproduct productT) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } product p = EntityMapper.updateEntity(null, productT); db.products.Add(p); db.SaveChanges(); productT.Product_ID = p.Product_ID; return(CreatedAtRoute("DefaultApi", new { id = productT.Product_ID }, productT)); }
public int DeactivteProducts() { int toreturn = 0; var date = new DateTime(2016, 09, 01); List <activeproductitem> prod = (from c in db.activeproductitems where c.activeProductItemStartDate < date select c).ToList(); foreach (var temp in prod) { temp.activeProductItemPolicyNum = "PP-IM-" + toreturn; db.SaveChanges(); toreturn++; } return(toreturn); }
public Boolean setResellerLocations(List <String> address) { Random b = new Random(); List <reseller> list = (from c in db.resellers select c).ToList(); int i = 0; foreach (reseller r in list) { r.street = address[i]; i++; db.SaveChanges(); } return(true); }
//returns users associated address. if user has no address -> give user address -> return new address. permission params - assign permissions if new address is created. // public static async Task<string> getAddress(MultiChainClient client, int userID, params BlockchainPermissions[] paramPermissions) public static async Task <string> getAddress(MultiChainClient client, int userID) { user tmp = new user(); tmp.User_ID = -1; tmp = await db.users.SingleAsync(l => l.User_ID == userID); if (tmp.User_ID != -1) { if (tmp.blockchainAddress == null) { //get new address, get user for which address does not exist, add address to user record. var newAddress = await client.GetNewAddressAsync(); newAddress.AssertOk(); string newAddr = newAddress.Result; //give permissions // var grant1 = client.GrantAsync(new List<string>() { newAddr }, BlockchainPermissions.Send); //var grant2 = client.GrantAsync(new List<string>() { newAddr }, BlockchainPermissions.Receive); tmp.blockchainAddress = newAddress.Result; db.Entry(tmp).State = EntityState.Modified; db.SaveChanges(); //if(paramPermissions.Length > 0) //{ // MUserController tmpUser = new MUserController(userID); // tmpUser = await tmpUser.init(); // await tmpUser.grantPermissions(paramPermissions); //} return(newAddress.Result); } else { return(tmp.blockchainAddress); } } else { throw new KeyNotFoundException(); } }
public IHttpActionResult sendUserOTPAndSaveOTP(int UserID, bool isResend) { string userPhoneNum = getPhoneNumFromUserID(UserID); string correctPhoneNum = getCorrectPhoneNumFormat(userPhoneNum); string newOTP = generateOTP(); otpview toUpdate = (from c in db.otpviews where c.User_ID == UserID select c).SingleOrDefault(); DTOotpview dtoOtpView = new DTOotpview(toUpdate); if (isResend) { dtoOtpView.otpRetryCount += 1; //increment the retrycount if (dtoOtpView.otpRetryCount < 3) //still a valid attempt { sendEmailViaWebApi(correctPhoneNum, "Hello from Nanofin! Your OTP for your transaction is: " + newOTP); dtoOtpView.otpCode = newOTP; //dtoOtpView.otpRetryCount has been set above dtoOtpView.otpExpirationTime = DateTime.Now.AddMinutes(3); dtoOtpView.otpNextAllowedTime = null; //remains null as long as the user isn't blocked dtoOtpView.otpRecordCreated = DateTime.Now; toUpdate = EntityMapper.updateEntity(toUpdate, dtoOtpView); db.Entry(toUpdate).State = EntityState.Modified; db.SaveChanges(); return(Content(HttpStatusCode.OK, "OTP Resent Successfully")); } if (dtoOtpView.otpRetryCount == 3)//too many attempts: user can request new OTP after a defined time=>blocked { dtoOtpView.otpCode = null; dtoOtpView.otpRetryCount = 3; dtoOtpView.otpExpirationTime = null; dtoOtpView.otpNextAllowedTime = DateTime.Now.AddMinutes(2);//block time dtoOtpView.otpRecordCreated = DateTime.Now; toUpdate = EntityMapper.updateEntity(toUpdate, dtoOtpView); db.Entry(toUpdate).State = EntityState.Modified; db.SaveChanges(); return(Content(HttpStatusCode.OK, "User blocked, OTP not Resent")); } return(StatusCode(HttpStatusCode.NoContent)); } else //not a resend: first time being sent { Nullable <DateTime> nowTime = DateTime.Now; //check if user is blocked: User is not blocked timeNow>next allowed time if (dtoOtpView.otpNextAllowedTime == null || (Nullable.Compare(nowTime, dtoOtpView.otpNextAllowedTime) > 0)) { sendEmailViaWebApi(correctPhoneNum, "Hello from Nanofin! Your OTP for your transaction is: " + newOTP); dtoOtpView.otpCode = newOTP; dtoOtpView.otpRetryCount = 0; dtoOtpView.otpExpirationTime = DateTime.Now.AddMinutes(1); //expiry time dtoOtpView.otpNextAllowedTime = null; //remains null as long as the user isn't blocked dtoOtpView.otpRecordCreated = DateTime.Now; toUpdate = EntityMapper.updateEntity(toUpdate, dtoOtpView); db.Entry(toUpdate).State = EntityState.Modified; db.SaveChanges(); return(Content(HttpStatusCode.OK, "OTP Sent sucessfully first time")); } else //user is still blocked { return(Content(HttpStatusCode.OK, "User is still blocked")); } } }