Exemple #1
0
 public ActionResult Delete(int?id)
 {
     if (id == 0)
     {
         return(RedirectToAction("Index"));
     }
     try
     {
         DonationContact donor = db.DonationContacts.SingleOrDefault(c => c.DonorId == id);
         if (donor == null)
         {
             return(RedirectToAction("Index"));
         }
         return(View(donor));
     }
     catch (SqlException sqlException)
     {
         ViewBag.SqlExceptionMessage = sqlException.Message;
     }
     catch (Exception genericException)
     {
         ViewBag.ExceptionMessage = genericException.Message;
     }
     return(View("~/Views/Errors/Details.cshtml"));
 }
Exemple #2
0
 public ActionResult Edit(DonationContact donor)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Entry(donor).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(donor));
     }
     catch (DbUpdateException uex)
     {
         ViewBag.DbExceptionMessage = ErrorHandler.DbUpdateHandler(uex);
         //ViewBag.DbExceptionMessage = uex.Message;
     }
     catch (SqlException sqlException)
     {
         ViewBag.SqlExceptionMessage = sqlException.Message;
     }
     catch (Exception genericException)
     {
         ViewBag.ExceptionMessage = genericException.Message;
     }
     return(View("~/Views/Errors/Details.cshtml"));
 }
Exemple #3
0
 public ActionResult Details(int id)
 {
     try
     {
         if (String.IsNullOrWhiteSpace(id.ToString()))
         {
             return(RedirectToAction("Index"));
         }
         // get data from db
         DonationContact donor = db.DonationContacts.SingleOrDefault(q => q.DonorId == id);
         return(View(donor));
     }
     catch (Exception e)
     {
         ViewBag.ExceptionMessage = e.Message;
     }
     return(View("~/Views/Errors/Details.cshtml"));
 }
Exemple #4
0
 public ActionResult Charge(string stripeEmail, string stripeToken, DonationContact donor)
 {
     try
     {
         if (ModelState.IsValid)
         {
             donor.DonationDate = DateTime.Now;
             int amount = Convert.ToInt32(donor.Amount * 100);
             ViewBag.Email = stripeEmail;
             ViewBag.Token = stripeToken;
             StripeCustomerService customers = new StripeCustomerService();
             StripeChargeService   charges   = new StripeChargeService();
             //create new customer
             StripeCustomer customer = customers.Create(new StripeCustomerCreateOptions
             {
                 Email       = stripeEmail,
                 SourceToken = stripeToken
             });
             ViewBag.customerId = customer.Id;
             //Create a charge
             StripeCharge charge = charges.Create(new StripeChargeCreateOptions
             {
                 Amount      = amount,
                 Description = "Sample charge",
                 Currency    = "usd",
                 CustomerId  = customer.Id
             });
             ViewBag.chargeId = charge.Id;
             donor.PaymentId  = ViewBag.chargeId;
             db.DonationContacts.Add(donor);
             db.SaveChanges();
             return(View(donor));
         }
         // return View(donor);
     }
     catch (Exception ex)
     {
         ViewBag.ExceptionMessage = ex.Message;
     }
     return(View("~/Views/Errors/Details.cshtml"));
 }
Exemple #5
0
 public ActionResult Create(DonationContact donor)
 {
     try
     {
         if (ModelState.IsValid)
         {
             donor.DonationDate = DateTime.Now;
             db.DonationContacts.Add(donor);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(donor));
     }
     catch (DbUpdateException uex)
     {
         ViewBag.DbExceptionMessage = ErrorHandler.DbUpdateHandler(uex);
     }
     catch (Exception ex)
     {
         ViewBag.ExceptionMessage = ex.Message;
     }
     return(View("~/Views/Errors/Details.cshtml"));
 }
Exemple #6
0
 public ActionResult Delete(FormCollection form)
 {
     try
     {
         int             id    = Convert.ToInt32(form["Donorid"]); //This is getting from an input inside <form> with Name="Id"
         DonationContact donor = db.DonationContacts.Find(id);
         db.DonationContacts.Remove(donor);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch (DbUpdateException dbException)
     {
         ViewBag.DbExceptionMessage = ErrorHandler.DbUpdateHandler(dbException);
     }
     catch (SqlException sqlException)
     {
         ViewBag.SqlExceptionMessage = sqlException.Message;
     }
     catch (Exception genericException)
     {
         ViewBag.ExceptionMessage = genericException.Message;
     }
     return(View("~/Views/Errors/Details.cshtml"));
 }