public AddBillPayResult AddBillPay(AddBillPayRequest model, long memberId) { var payeeId = _dbContext.Payees .Where(p => p.Guid == model.PayeeGuid) .Select(p => p.Id) .SingleOrDefault(); if (payeeId == 0) { return(new AddBillPayResult(AddBillPayResultType.PayeeNotFound, null)); } var billPay = new BillPay { Amount = model.Amount.GetValueOrDefault(), Frequency = model.Frequency, IsRecurring = model.IsRecurring, MemberId = memberId, NextPaymentDate = model.FirstPaymentDate, PayeeId = payeeId, }; _dbContext.Add(billPay); _dbContext.SaveChanges(); return(new AddBillPayResult(AddBillPayResultType.Successful, billPay)); }
public async Task <IActionResult> Edit(int id, [Bind("BillPayID,Period,AccountNumber1,PayeeID,Amount,ScheduleDate,BillPayTimeUtc")] BillPay billPay) { if (id != billPay.BillPayID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(billPay); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BillPayExists(billPay.BillPayID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(billPay)); }
public IActionResult EditBillPay(int id, BillPay billpay) { if (id != billpay.BillPayID) { return(NotFound()); } if (ModelState.IsValid) { var content = new StringContent(JsonConvert.SerializeObject(billpay), Encoding.UTF8, "application/json"); var response = BankAPI.InitializeClient().PutAsync("api/BillPays", content).Result; // These are to get customerID so it can be passed to ViewBillPays and get back into that page var response2 = BankAPI.InitializeClient().GetAsync($"api/Customers/getCustomerFromBillPay/{id}"); int customerID = int.Parse(response2.Result.Content.ReadAsStringAsync().Result); if (response.IsSuccessStatusCode) { return(RedirectToAction("ViewBillPays", new { id = customerID })); } } ViewData["Status"] = new BillPayViewModel().Status; return(View(billpay)); }
public async Task <IActionResult> Edit(int id, [Bind("BillPayID,AccountNumber,PayeeID,Amount,ScheduleDate,Period,ModifyDate")] BillPay billPay) { if (id != billPay.BillPayID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(billPay); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BillPayExists(billPay.BillPayID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["PayeeID"] = new SelectList(_context.Set <Payee>(), "PayeeID", "PayeeName", billPay.PayeeID); return(View(billPay)); }
public ActionResult Create([Bind(Include = "BillPayID,Account_No,PayeeID,Amount,ScheduleDate,Period,ModifyDate")] BillPay billPay) { if (Session["Email"] != null) { if (ModelState.IsValid) { string email = Session["Email"].ToString(); var res = db.Account_Master_174797_Project.Where(a => a.Email.Equals(email)).First(); if (res.Balance > Convert.ToDouble(billPay.Amount)) { res.Balance = res.Balance - Convert.ToDouble(billPay.Amount); db.BillPays.Add(billPay); db.SaveChanges(); return(RedirectToAction("Index")); } else { ViewBag.Message("", "InSufficient Balance"); } } else { ViewBag.Message("", "Payment not done, please check gain"); } ViewBag.Account_No = new SelectList(db.Account_Master_174797_Project, "Account_No", "Account_Type", billPay.Account_No); ViewBag.PayeeID = new SelectList(db.Payees, "PayeeID", "PayeeName", billPay.PayeeID); return(View(billPay)); } else { return(RedirectToAction("LogIn", "Registration")); } }
public async Task <IActionResult> Create([Bind("BillPayID,AccountNumber,PayeeID,Amount,ScheduleDate,Period,ModifyDate")] BillPay billPay) { // input fixed values billPay.ModifyDate = DateTime.UtcNow; billPay.Status = BillStatus.Normal; billPay.ScheduleDate = DateTime.SpecifyKind(billPay.ScheduleDate, DateTimeKind.Local).ToUniversalTime(); // input validation if (billPay.ScheduleDate <= DateTime.UtcNow) { ModelState.AddModelError(nameof(billPay.ScheduleDate), "Schedule time must be after this time"); } if (ModelState.IsValid) { _context.Add(billPay); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } // operation when error occurs var customerAccounts = _context.Customers.FirstOrDefault(c => c.CustomerID == CustomerID).Accounts; ViewData["AccountNumber"] = new SelectList(customerAccounts, "AccountNumber", "AccountNumber"); ViewData["PayeeID"] = new SelectList(_context.Payees, "PayeeID", "PayeeName"); ViewData["Period"] = new SelectList(Enum.GetValues(typeof(BillPeriod))); return(View(billPay)); }
public async Task CreateBillPay(NwbaContext nwbaContext) { var billPay = new BillPay { AccountNumber = Account, PayeeID = Payee, Amount = Amount, ScheduleDate = ScheduledDate.ToUniversalTime(), ModifyDate = DateTime.UtcNow }; if (Period.Equals("S")) { billPay.Period = Models.Period.S; } if (Period.Equals("M")) { billPay.Period = Models.Period.M; } if (Period.Equals("Q")) { billPay.Period = Models.Period.Q; } if (Period.Equals("Y")) { billPay.Period = Models.Period.Y; } nwbaContext.BillPays.Add(billPay); await nwbaContext.SaveChangesAsync(); }
public async Task UpdateAsync(BillPay billPay, int billPayId) { billPay.BillPayID = billPayId; billPay.ModifyDate = DateTime.UtcNow; _set.Update(billPay); await _context.SaveChangesAsync(); }
public int UpdateBillPay(int id, BillPay billPay) { _context.Update(billPay); _context.SaveChanges(); return(id); }
public async Task <IActionResult> Create(BillPay billPay) { if (ModelState.IsValid) { if (_context.Account.Where(x => x.AccountNumber == billPay.AccountNumber).FirstOrDefault().Balance > billPay.Amount && billPay.Amount > 0) { if (billPay.ScheduleDate < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"))) { ModelState.AddModelError(nameof(billPay.ScheduleDate), "Invaild data time."); } else { ViewData["ErrorMessage"] = ""; billPay.ModifyDate = DateTime.UtcNow; billPay.Status = BillPayStatus.Available; _context.Add(billPay); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } else { ModelState.AddModelError(nameof(billPay.Amount), "Not enough money or invaild amount."); } } ViewData["AccountNumber"] = new SelectList(_context.Account.Where(a => a.CustomerID == CustomerID), "AccountNumber", "AccountNumber"); ViewData["PayeeID"] = new SelectList(_context.Payee.Where(x => x.PayeeID > 0), "PayeeID", "PayeeID"); return(View(billPay)); }
public void CreateBill(int?CustomerId, BillPay bill) { if (CustomerId == bill.Account.CustomerId) { _context.BillPay.AddAsync(bill); } SaveChangesAsync(); }
// Logic for modifying billpays public void ModifyBillPay(BillPay billPay, int accountNumber, int payeeID, decimal amount, DateTime scheduleDate, string period) { billPay.AccountNumber = accountNumber; billPay.PayeeID = payeeID; billPay.Amount = amount; billPay.ScheduleDate = scheduleDate; billPay.Period = period; }
// adding rating public async Task <IActionResult> Create(IFormCollection form) { var billPay = new BillPay { }; //int.TryParse(form["AccountNumber"].ToString(), out int acNum); SessionAccountNumber = (int)HttpContext.Session.GetInt32(nameof(SessionAccountNumber)); int id = SessionAccountNumber; billPay.AccountNumber = SessionAccountNumber; billPay.Amount = double.Parse(form["Amount"]); billPay.CustomerID = CustomerID; billPay.PayeeID = int.Parse(form["PayeeID"]); billPay.Period = (PeriodType)Enum.Parse(typeof(PeriodType), form["Period"]); billPay.ScheduleDate = DateTime.Parse(form["ScheduleDate"]); billPay.ModifyDate = DateTime.UtcNow; billPay.Count = 0; billPay.Blocked = false; if (ModelState.IsValid) { try { var payee = await _context.Payees.FindAsync(billPay.PayeeID); if (payee == null) { ModelState.AddModelError("PayeeID", "Selected payee doesn't exist. Chose from: [" + string.Join(", ", _context.Payees.Select(x => x.PayeeID).ToList()) + "]"); return(View(billPay)); } myAccount = null; await GetMyAccount(id); if (myAccount.Balance < billPay.Amount) { ModelState.AddModelError("Amount", "You do not have sufficient Balance for this Amount!"); return(View(billPay)); } _context.Update(billPay); await _context.SaveChangesAsync(); myAccount = null; //HttpContext.Session.Remove(nameof(SessionAccountNumber)); return(View("DisplayBP", await GetMyAccount(SessionAccountNumber))); } catch (DbUpdateConcurrencyException) { throw; } } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(IFormCollection form) { int SessionEditID; int.TryParse(form["editID"], out int id); if (id != 0) { System.Diagnostics.Debug.WriteLine(" BP ID : " + id); SessionEditID = id; HttpContext.Session.SetInt32(nameof(SessionEditID), SessionEditID); return(View(await _context.BillPays.FindAsync(id))); } else { SessionEditID = (int)HttpContext.Session.GetInt32(nameof(SessionEditID)); SessionAccountNumber = (int)HttpContext.Session.GetInt32(nameof(SessionAccountNumber)); var billPay = new BillPay { }; billPay.BillPayID = SessionEditID; billPay.AccountNumber = SessionAccountNumber; billPay.Amount = double.Parse(form["Amount"]); billPay.CustomerID = CustomerID; billPay.PayeeID = int.Parse(form["PayeeID"]); billPay.Period = (PeriodType)Enum.Parse(typeof(PeriodType), form["Period"]); billPay.ScheduleDate = DateTime.Parse(form["ScheduleDate"]); billPay.ModifyDate = DateTime.UtcNow; billPay.Count = 0; billPay.Blocked = bool.Parse(form["Blocked"]); if (ModelState.IsValid) { try { _context.Update(billPay); await _context.SaveChangesAsync(); myAccount = null; //acc.BillPays.Remove(acc.BillPays.Find(x => x.BillPayID == SessionEditID)); //acc.BillPays.Add(billPay); //HttpContext.Session.Remove(nameof(SessionAccountNumber)); HttpContext.Session.Remove(nameof(SessionEditID)); //ActionResult action = new BillPayController(_context).DisplayBP(acc)); return(View("DisplayBP", await GetMyAccount(SessionAccountNumber))); } catch (DbUpdateConcurrencyException) { throw; } } return(RedirectToAction(nameof(Index))); } }
public async Task ProcessInScope(IServiceProvider serviceProvider) { Console.WriteLine("Current Time: " + DateTime.Now); var bpayRepo = serviceProvider.GetService <BillpayManager>(); var accRepo = serviceProvider.GetService <AccountManager>(); var loginRepo = serviceProvider.GetService <LoginManager>(); BillPay billPay = await bpayRepo.GetEarliestBillPay(); if (billPay != null) { //Debugging Code - Ignore writelines Console.WriteLine("------\nDate looking for " + billPay.ScheduleDate.ToLocalTime() + "\nTime Difference: " + (billPay.ScheduleDate.ToLocalTime() - DateTime.Now) + "\nTime Equal: " + AreEqual(DateTime.Now, billPay.ScheduleDate.ToLocalTime()) + "\n------"); if (AreEqual(DateTime.Now, billPay.ScheduleDate.ToLocalTime())) { Account account = await accRepo.Get(billPay.AccountNumber); if (CanProceed(account, billPay.Amount)) { NWBASystem.GetInstance().PayBill(account, billPay.Amount, billPay.Payee); UpdateNextScheduledDate(billPay); if (DeleteBillPayIfNeeded(billPay)) { bpayRepo.Delete(billPay); } else { bpayRepo.Update(billPay); } } else { bpayRepo.Delete(billPay); } Console.WriteLine("Scheduled payment has been made!"); } } ; Login login = await loginRepo.GetEarliestBlockedAccount(); if (login != null) { Console.WriteLine("Time to unlock: " + login.BlockTime.ToLocalTime().AddSeconds(60)); if (AreEqual(DateTime.Now, login.BlockTime.ToLocalTime().AddSeconds(60))) { login.LoginAttempts = 0; login.Status = "Active"; loginRepo.Update(login); Console.WriteLine("Account unblocked"); } } }
public object BlockBillPay(int billPayID) { BillPay billPay = _repo.Get(billPayID); billPay.Status = BillStatus.Blocked; billPay.StatusMessage = "blocked"; _context.SaveChanges(); return(new { success = true }); }
//Used to modify the job and time if a user modifys it //Used to update the db and schedule service public void ModifyJob(BillPay UpdatedBillPayObject) { Debug.WriteLine("Inside Modify Job Method"); //Remove old job from the schduler removeJob(UpdatedBillPayObject.BillPayID.ToString()); //Add new job to schduler createScheduledJobService(UpdatedBillPayObject.BillPayID, UpdatedBillPayObject.AccountNumber, UpdatedBillPayObject.PayeeID, UpdatedBillPayObject.Amount, UpdatedBillPayObject.Period[0], UpdatedBillPayObject.ScheduleDate); }
public object UnblockBillPay(int billPayID) { BillPay billPay = _repo.Get(billPayID); billPay.Status = BillStatus.Normal; billPay.StatusMessage = "recently unblocked"; _context.SaveChanges(); return(new { success = true }); }
/*PayBillUpdatePost * This method actually triggered when the user submit the changes they have made to the schdulked job * Method will modify the database and also modify the active billpay job in the schduler */ public ATMPayBillsSchedule_ViewModel billUpdatePost(int sessionID, ATMPayBillsSchedule_ViewModel models, string id) { int billID = 0; if (id != null) { billID = int.Parse(id); } //Create a billPayObject instance with newly updated properties //and send it to repositry to handle the update to DB. BillPay UpdatedBillPayObject = new BillPay(); DateTime ScheduleDateFormat = DateTime.ParseExact(models.ScheduleDate, "dd/MM/yyyy", CultureInfo.InvariantCulture); UpdatedBillPayObject.BillPayID = billID; UpdatedBillPayObject.AccountNumber = models.AccountNumber; UpdatedBillPayObject.PayeeID = models.PayeeID; UpdatedBillPayObject.Amount = models.Amount; UpdatedBillPayObject.ScheduleDate = ScheduleDateFormat; UpdatedBillPayObject.Period = models.Period; UpdatedBillPayObject.ModifyDate = System.DateTime.Now; Repo.UpdateExistingBillPayRecord(UpdatedBillPayObject); //Tell the schduler to remove the job //and now manually create a new job with the newly updated information Billpay BillPayBusinessObj = new Billpay(); BillPayBusinessObj.ModifyJob(UpdatedBillPayObject); //######### Repopulating the viewmodel Below #### var customerQuery = Repo.GetCustomerSingle(sessionID); var AccountListQuery = Repo.GetCustomerAccountQueryable(sessionID); var allPayeeQuery = Repo.GetAllPayeeQueryable(); IEnumerable <SelectListItem> accounts = AccountListQuery.OrderBy(a => a.AccountNumber).ToList().Select(a => new SelectListItem { Value = Convert.ToString(a.AccountNumber), Text = (a.AccountType.Equals("S")) ? "Savings - " + a.AccountNumber.ToString() + " - $" + a.Balance : "Checkings - " + a.AccountNumber.ToString() + " - $" + a.Balance }); IEnumerable <SelectListItem> allPayee = allPayeeQuery.OrderBy(p => p.PayeeID).ToList().Select(p => new SelectListItem { Value = Convert.ToString(p.PayeeID), Text = (p.PayeeID + " - " + p.PayeeName) }); models.CustomerName = customerQuery.CustomerName; models.accountList = accounts; models.AllPayeeList = allPayee; return(models); }
public async Task <bool> InsertPayment(int?id, int PayeeID, decimal Amount, DateTime ScheduleDate, Period Period) { Account account = await _context.Accounts.FindAsync(id); if (account.Balance < Amount) { controller.ModelState.AddModelError(nameof(Amount), "Your account balance is not enough."); } if (!await CheckNull(id)) {//check if the customer own this account controller.ModelState.AddModelError("AccountNotExsit", "Account not exsit in your name."); } if (CountDecimalPlaces(Amount) > 2) { controller.ModelState.AddModelError(nameof(Amount), "Amount cannot have more than 2 decimal places."); } if (Amount <= 0) { controller.ModelState.AddModelError(nameof(Amount), "Amount must be positive."); } if (!(CheckPayee(PayeeID))) {//check if the customer own this account controller.ModelState.AddModelError("AccountNotExsit", "Payee not exsit"); } if (ScheduleDate < DateTime.Today) { controller.ModelState.AddModelError("ScheduleDate", "Schedule Date cannot be ealier than today"); } if (!controller.ModelState.IsValid) { return(false); } BillPay billPay = new BillPay { AccountNumber = (int)id, PayeeID = PayeeID, Amount = Amount, ModifyDate = DateTime.UtcNow, //default modfied today ScheduleDate = ScheduleDate.ToUniversalTime(), Period = Period }; _context.BillPays.Add(billPay); _context.SaveChanges(); return(true); }
private Boolean DeleteBillPayIfNeeded(BillPay billPay) { if (billPay.Period == "S") { return(true); } else { return(false); } }
public async Task <IActionResult> Create([Bind("BillPayID,Period,AccountNumber1,PayeeID,Amount,ScheduleDate,BillPayTimeUtc")] BillPay billPay) { if (ModelState.IsValid) { _context.Add(billPay); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(billPay)); }
public async Task <IActionResult> Delete(int?id) { BillPay billPay = await _bpayRepo.GetBpayWithPayee(id); if (billPay == null) { return(NotFound()); } return(View(billPay)); }
public async Task <IActionResult> Delete(BillPay billPay) { BillPay billPayToDelete = await _bpayRepo.GetBpay(billPay.BillPayID); if (billPayToDelete == null) { return(NotFound()); } _bpayRepo.Delete(billPayToDelete); return(RedirectToAction(nameof(SuccessfulEdit))); }
public async Task <IActionResult> Create([Bind("BillPayID,AccountNumber,PayeeID,Amount,ScheduleDate,Period,ModifyDate")] BillPay billPay) { if (ModelState.IsValid) { _context.Add(billPay); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["PayeeID"] = new SelectList(_context.Set <Payee>(), "PayeeID", "PayeeName", billPay.PayeeID); return(View(billPay)); }
public async Task <IActionResult> Create(BillPay billPay) { if (ModelState.IsValid) { billPay.ModifyDate = DateTime.UtcNow; _context.Add(billPay); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["AccountNumber"] = new SelectList(_context.Account.Where(a => a.CustomerID == CustomerID), "AccountNumber", "AccountNumber"); ViewData["PayeeID"] = new SelectList(_context.Payee.Where(x => x.PayeeID > 0), "PayeeID", "PayeeID"); return(View(billPay)); }
public ActionResult DeleteConfirmed(int id) { if (Session["Email"] != null) { BillPay billPay = db.BillPays.Find(id); db.BillPays.Remove(billPay); db.SaveChanges(); return(RedirectToAction("Index")); } else { return(RedirectToAction("LogIn", "Registration")); } }
public static Transaction BuildTransaction(BillPay bill) { Transaction transaction = new Transaction() { TransactionType = TransactionType.Transfer, AccountNumber = bill.AccountNumber, DestinationAccountNumber = bill.PayeeID, Amount = bill.Amount, TransactionTimeUtc = DateTime.UtcNow, Comment = "Transfer for Bill pay" }; return(transaction); }
public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BillPay billPay = db.BillPays.Find(id); if (billPay == null) { return(HttpNotFound()); } return(View(billPay)); }
private static BillPay TrimBillPay(BillPay b) { return(new BillPay { BillPayID = b.BillPayID, AccountNumber = b.AccountNumber, Payee = b.Payee, Amount = b.Amount, ScheduleDate = b.ScheduleDate, Period = b.Period, Comment = b.Comment, Status = b.Status, StatusModifyDate = b.StatusModifyDate }); }