public JsonResult Deactivate(string Id) { BankAccountDetails bd = null; using (var db = new ApplicationDbContext()) { var acct = (from a in db.BankAccounts where a.Id == Id select a).FirstOrDefault(); if (acct != null && acct.IsReceiver == true) { acct.IsReceiver = false; //remove any existing waiting tickets from the waiting ticket repository WaitingTicket tckt = (from t in db.WaitingList where t.TicketHolderId == acct.Id && t.IsValid == true select t).FirstOrDefault(); if (tckt != null) { if (tckt.Donations != null) { foreach (Donation d in tckt.Donations) { db.Donations.Remove(d); } db.WaitingList.Remove(tckt); } } db.SaveChanges(); bd = CreateBankAccountDetails(acct); } } return(Json("Done")); }
public ActionResult Delete(string Id) { using (var db = new ApplicationDbContext()) { BankAccount ac = (from a in db.BankAccounts where a.Id == Id select a).FirstOrDefault(); if (ac != null) { //retrieve any waiting ticket on and pending donation matches for the account and delete them WaitingTicket tkt = (from t in db.WaitingList where t.TicketHolderId == ac.Id && t.IsValid == true select t).FirstOrDefault(); if (tkt.Donations.Count() > 0) { foreach (Donation d in tkt.Donations) { // delete the unserviced donations for the account's ticket db.Donations.Remove(d); } // delete the account's ticket db.WaitingList.Remove(tkt); } //delete the account db.BankAccounts.Remove(ac); db.SaveChanges(); } return(Json("done")); } }
public ActionResult PaymentConfirmed(string Id) { if (Id != null) { using (var db = new ApplicationDbContext()) { var pay = db.Payments.Find(Id); // get the payment object associated with the supplied id if (pay.Confirmed == false) // ensure that the payment hasnt been previously confirmed. { pay.Confirmed = true; // set its confirmation status to true pay.DonationPack.IsOpen = true; // open its donation package pay.DonationPack.Donor.IsReceiver = true; // set the donors receiver status to true var newticket = new WaitingTicket { TicketHolder = pay.DonationPack.Donor, TicketHolderId = pay.DonationPack.Donor.Id, EntryDate = DateTime.Now, }; // Create a ticket for the donor db.WaitingList.Add(newticket); // add the ticket to record db.SaveChanges(); // save current changes if (pay.DonationPack.Ticket.Donations.Count > 1 && pay.DonationPack.Ticket.Donations.Where(m => m.IsOpen == true).Count() == 2) { //If the donation ticket has up to 2 donations and both hav been opened, change the status of the recipient. pay.DonationPack.Ticket.TicketHolder.IsReceiver = false; pay.DonationPack.Ticket.IsValid = false; db.SaveChanges();// save current changes } } return(Json("Done")); } } return(HttpNotFound("Record could not be found")); }
public static bool IsNotNull(WaitingTicket ticket) { if (ticket != null) { return(true); } else { return(false); } }
public static void UpdateTicket(WaitingTicket UpdateTicket) { if (IsNotNull(UpdateTicket)) { if (ExistInRecord(UpdateTicket)) { DbAccessHandler.DbContext.Entry(UpdateTicket).State = EntityState.Modified; DbAccessHandler.DbContext.SaveChanges(); } } }
public static void RemoveTicket(WaitingTicket DeleteTicket) { if (IsNotNull(DeleteTicket)) { if (ExistInRecord(DeleteTicket)) { DbAccessHandler.DbContext.WaitingList.Remove(DeleteTicket); DbAccessHandler.DbContext.SaveChanges(); } } }
protected override void Seed(FundSharer.Models.ApplicationDbContext context) { // Reset the database //BankAccounts context.BankAccounts.RemoveRange(context.BankAccounts.ToList()); //Donations context.Donations.RemoveRange(context.Donations.ToList()); //Payments context.Payments.RemoveRange(context.Payments.ToList()); //PopImages context.POPImages.RemoveRange(context.POPImages.ToList()); //WaitingTickets context.WaitingList.RemoveRange(context.WaitingList.ToList()); //Populate database var Users = (from u in context.Users select u).ToList(); //Create Bank Accounts String[] Banks = { "GTB", "UBA", "Fidelity", "First Bank" }; int counter = 0; foreach (ApplicationUser User in Users) { if (User.FirstName != "Admin") { BankAccount b = new BankAccount { AccountTitle = User.FullName, AccountNumber = "112345", Bank = Banks[counter], BankAccountOwner = User, BankAccountOwnerId = User.Id }; context.BankAccounts.Add(b); if (counter == 0) // Create the first ticket { var firstticket = new WaitingTicket { EntryDate = DateTime.Now, TicketHolder = b, TicketHolderId = b.Id, IsValid = true }; context.WaitingList.Add(firstticket); b.IsReceiver = true; } counter++; } } }
public static WaitingTicket PopOutTopTicket() { WaitingTicket ticket = null; if (DbAccessHandler.DbContext.WaitingList.Count() > 0) // if there are tickets in the waiting list { // get a list tickest of with less than 2 donations List <WaitingTicket> NeedsDonorList = (from t in DbAccessHandler.DbContext.WaitingList where t.Donations.Count() < 2 select t).ToList(); // if there are tickets that fit the specified criteria, select the last ticket on the list.. //i.e the oldest ticket on the list if (NeedsDonorList.Count() > 0) { ticket = NeedsDonorList.Last(); } } return(ticket); }
public static void AddTicket(WaitingTicket NewTicket) { if (IsNotNull(NewTicket)) { if (!ExistInRecord(NewTicket))// ensure that no ticket in the database exists with the specified ticket id { //check the ticket has no pending donations... if not, add the ticket to the database and save the changes if (NewTicket.Donations == null) { if (BankAccountServices.IsNotNull(NewTicket.TicketHolder)) { DbAccessHandler.DbContext.Entry(NewTicket.TicketHolder).State = EntityState.Unchanged; DbAccessHandler.DbContext.WaitingList.Add(NewTicket); DbAccessHandler.DbContext.SaveChanges(); } } } } }
public ActionResult FindAMatch() { var UserId = User.Identity.GetUserId(); ApplicationUser AppUser; using (var db = new ApplicationDbContext()) { AppUser = db.Users.Find(UserId); BankAccount donor = (from ba in db.BankAccounts where ba.BankAccountOwnerId == AppUser.Id select ba).FirstOrDefault(); string AdminUid = (from r in db.Roles where r.Name == "Administrator" select r).FirstOrDefault().Users.FirstOrDefault().UserId; WaitingTicket Ticket = (from t in db.WaitingList where t.Donations.Count < 2 && t.IsValid == true && t.TicketHolderId == AdminUid orderby t.EntryDate select t).FirstOrDefault(); if (Ticket == null) { Ticket = (from t in db.WaitingList where t.Donations.Count < 2 & t.IsValid == true orderby t.EntryDate select t).FirstOrDefault(); } if (Ticket != null) { Donation NewDonation = new Donation { Donor = donor, DonorId = donor.Id, IsOpen = false, Ticket = Ticket, TicketId = Ticket.Id, CreationDate = DateTime.Now }; db.Donations.Add(NewDonation); db.SaveChanges(); DonationDetails DonDetails = new DonationDetails { DonationId = NewDonation.Id, RecipientFullName = NewDonation.Ticket.TicketHolder.AccountTitle, RecipientAccountNumber = NewDonation.Ticket.TicketHolder.AccountNumber, RecipientBankName = NewDonation.Ticket.TicketHolder.Bank, }; return(PartialView("_FindAMatch", DonDetails)); } else { return(HttpNotFound()); } } }
public JsonResult Activate(String Id) { BankAccountDetails bd = null; using (var db = new ApplicationDbContext()) { var acct = (from a in db.BankAccounts where a.Id == Id select a).FirstOrDefault(); if (acct != null && acct.IsReceiver == false) { acct.IsReceiver = true; //create an open ticket for the account WaitingTicket adminTicket = new WaitingTicket { EntryDate = DateTime.Now, IsValid = true, TicketHolderId = acct.Id }; db.WaitingList.Add(adminTicket); db.SaveChanges(); bd = CreateBankAccountDetails(acct); } } return(Json("Done")); }
public static bool ExistInRecord(WaitingTicket ticket) { var testaccount = DbAccessHandler.DbContext.WaitingList.Find(ticket.Id); return(IsNotNull(testaccount)); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, PhoneNumber = model.ContactNumber }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { // Create user claims - the user's first name. if (user.FirstName != "Admin") { UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, user.FirstName)); } else { UserManager.AddToRole(user.Id, "Administrator"); } using (var db = new ApplicationDbContext()) { //create user's bank account. var NewbankAccount = new BankAccount { AccountNumber = model.AccountNumber, AccountTitle = model.AccountTitle, Bank = model.BankName, IsReceiver = false, BankAccountOwner = user }; // BankAccountServices.AddBankAccount(NewbankAccount); ** db.Entry(user).State = System.Data.Entity.EntityState.Unchanged; db.BankAccounts.Add(NewbankAccount); db.SaveChanges(); //Check to see if this is the first account in the record int noAvailableTickets = (from t in db.WaitingList where (t.Donations.Count() < 2) select t).Count(); // if this is the first account, then create a ticket for it // so it is available for matching if (noAvailableTickets == 0) { NewbankAccount.IsReceiver = true; //Create its ticket WaitingTicket Ticket = new WaitingTicket { TicketHolder = NewbankAccount, EntryDate = DateTime.Now, IsValid = true }; db.WaitingList.Add(Ticket); db.Entry(NewbankAccount).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); //TicketServices.AddTicket(Ticket); ** //BankAccountServices.UpdateBankAccount(NewbankAccount); ** } } await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToLocal(null)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }