//GIVE DONATION IF THE USER IS LOGGED IN public ActionResult UserDonate(FormCollection form) { try { if (ModelState.IsValid) { //FINDS AND HOLDS THE USER ACCOUNT north_shore_accounts nsa = new north_shore_accounts(); nsa.user_id = Convert.ToInt16(Session["userId"]); var user = db.north_shore_accounts.Where(n => n.user_id == nsa.user_id); foreach (var row in user) { nsa.id = row.id; } nsa = db.north_shore_accounts.Find(nsa.id); //FIND THE PAYMENT INFORMATION FOR THIS USER payment_information pi = new payment_information(); pi.credit_card = form["north_shore_accounts.payment_information.credit_card"]; pi.ccv = form["north_shore_accounts.payment_information.ccv"]; DateTime date = DateTime.Parse(form["north_shore_accounts.payment_information.exp_date"]); int year = date.Year; int day = date.Day; int month = date.Month; string exp_date = year.ToString() + "-" + month.ToString() + "-" + day.ToString(); DateTime convertedDate = Convert.ToDateTime(exp_date); pi.exp_date = date; pi.id = nsa.payment_info ?? default(int); ViewBag.UpRowsAffected = db.Database.ExecuteSqlCommand("UPDATE payment_information SET credit_card = @credit_card, ccv = @ccv, exp_date = @exp_date WHERE id = @id", new SqlParameter("@credit_card", pi.credit_card), new SqlParameter("@ccv", pi.ccv), new SqlParameter("@exp_date", pi.exp_date), new SqlParameter("@id", pi.id)); //SET THE DONATIONS ID TO USER ACCOUNT ID, THEN ADD THE AMOUNT TO IT donation donation = new donation(); donation.account_id = nsa.id; donation.amount = Convert.ToDecimal(form["amount"]); ViewBag.InRowsAffected = db.Database.ExecuteSqlCommand("INSERT INTO donations VALUES (@amount, @account_id)", new SqlParameter("@amount", donation.amount), new SqlParameter("@account_id", donation.account_id)); Session["donated"] = "true"; return(RedirectToAction("Index", "Navigate")); } } catch (DbUpdateException e) { ViewBag.DbExceptionMessage = e.Message; } catch (SqlException e) { ViewBag.SqlExceptionMessage = e.Message; } catch (Exception e) { ViewBag.GenericException = e.Message; } return(View("~/Views/Navigate/Errors.cshtml")); }
public ActionResult DelP(int?id) { if (Session["role"] != null && Session["role"].ToString() == "ADM") { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } try { payment_information pi = db.payment_information.Find(id); north_shore_accounts nsa = new north_shore_accounts(); donation d = new donation(); //find NSA id from pi payment_info var sel_nsa = db.north_shore_accounts.Where(n => n.payment_info == pi.id); foreach (var n in sel_nsa) { nsa = db.north_shore_accounts.Find(n.id); } //find donation from NSA account_id var sel_don = db.donations.Where(don => don.account_id == nsa.id); foreach (var don in sel_don) { d = db.donations.Find(don.id); } if (d == null) { return(HttpNotFound()); } return(View(nsa)); } catch (DbUpdateException e) { ViewBag.DbExceptionMessage = e.Message; } catch (SqlException e) { ViewBag.SqlExceptionMessage = e.Message; } catch (Exception e) { ViewBag.GenericException = e.Message; } return(View("~/Views/Navigate/Errors.cshtml")); } else { return(RedirectToAction("RestrictedAccess", "Navigate")); } }
public ActionResult DelP(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } try { payment_information pi = db.payment_information.Find(id); north_shore_accounts nsa = new north_shore_accounts(); donation d = new donation(); //find NSA id from pi payment_info var sel_nsa = db.north_shore_accounts.Where(n => n.payment_info == pi.id); foreach (var n in sel_nsa) { nsa = db.north_shore_accounts.Find(n.id); } //find donation from NSA account_id var sel_don = db.donations.Where(don => don.account_id == nsa.id); foreach (var don in sel_don) { d = db.donations.Find(don.id); } if (d == null) { return HttpNotFound(); } return View(nsa); } catch(DbUpdateException e) { ViewBag.DbExceptionMessage = e.Message; } catch(SqlException e) { ViewBag.SqlExceptionMessage = e.Message; } catch(Exception e) { ViewBag.GenericException = e.Message; } return View("~/Views/Navigate/Errors.cshtml"); }
public ActionResult DeleteDonorPay(int id) { try { north_shore_accounts nsa = new north_shore_accounts(); payment_information pi = new payment_information(); donation donation = new donation(); var donor = db.donations.Where(d => d.account_id == id); foreach (var d in donor) { donation = db.donations.Find(d.id); if (donation != null) { db.donations.Remove(donation); } } nsa = db.north_shore_accounts.Find(id); pi.id = nsa.payment_info ?? default(int); pi = db.payment_information.Find(pi.id); db.north_shore_accounts.Remove(nsa); db.payment_information.Remove(pi); db.SaveChanges(); return(RedirectToAction("AcctPayInfo")); } catch (DbUpdateException e) { ViewBag.DbExceptionMessage = e.Message; } catch (SqlException e) { ViewBag.SqlExceptionMessage = e.Message; } catch (Exception e) { ViewBag.GenericException = e.Message; } return(View("~/Views/Navigate/Errors.cshtml")); }