public ActionResult NewRecurringDonation(RecurringDonationVM recurringDonation) { int result = 0; ApplicationUserManager userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); var user = userManager.FindById(User.Identity.GetUserId()); recurringDonation.UserName = user.Email; if (ModelState.IsValid) { try { result = _donationManager.CreateNewRecurringDonation(recurringDonation); if (result == 1) { return(RedirectToAction("Index")); } } catch { return(View()); } } return(View()); }
/// <summary> /// CREATOR: Ryan Morganti /// CREATED: 2020/04/16 /// APPROVER: Derek Taylor /// /// Fake Donation Accessor Method to test inserting a new recurring /// donation record. /// </summary> /// <remarks> /// UPDATER: NA /// UPDATED: NA /// UPDATE: NA /// /// </remarks> public int InsertNewRecurringDonation(RecurringDonationVM donation) { List <RecurringDonationVM> rds = new List <RecurringDonationVM>(); foreach (var r in _recurring) { rds.Add(r); } rds.Add(donation); return(rds.Count()); }
/// <summary> /// CREATOR: Ryan Morganti /// CREATED: 2020/04/16 /// APPROVER: Derek Taylor /// /// Donation Manager method used creating a newly scheduled RecurringDonation. /// Method will pass data on to the data store access layer and return a successful or failed result. /// </summary> /// <remarks> /// UPDATER: NA /// UPDATED: NA /// UPDATE: NA /// /// </remarks> public int CreateNewRecurringDonation(RecurringDonationVM donation) { int result = 0; try { result = _donationAccessor.InsertNewRecurringDonation(donation); } catch (Exception ex) { throw new ApplicationException("Could not schedule a new Recurring Donation", ex); } return(result); }
public void TestInsertNewRecurringDonation() { // Arrange int result = 0; RecurringDonationVM donation = new RecurringDonationVM() { RecurringDonationID = 1, UserName = "******" }; // Act result = _donationAccessor.InsertNewRecurringDonation(donation); // Assert Assert.AreEqual(4, result); }
/// <summary> /// CREATOR: Ryan Morganti /// CREATED: 2020/04/29 /// APPROVER: Derek Taylor /// /// Access layer method to SELECT a collection of RecurringDonationInfo records /// by their associated UserName /// </summary> /// <remarks> /// UPDATER: NA /// UPDATED: NA /// UPDATE: NA /// /// </remarks> public List <RecurringDonationVM> SelectRecurringDonationsByUser(string username) { List <RecurringDonationVM> donations = new List <RecurringDonationVM>(); var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_select_recurring_donations_by_user", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserName", username); try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { RecurringDonationVM newDonation = new RecurringDonationVM(); newDonation.RecurringDonationID = reader.GetInt32(0); newDonation.DonorID = reader.GetInt32(1); newDonation.DonationAmount = reader.GetDecimal(2); newDonation.StartDate = reader.GetDateTime(3); newDonation.Interval = reader.GetInt32(4); newDonation.Active = reader.GetBoolean(5); donations.Add(newDonation); } } reader.Close(); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(donations); }
/// <summary> /// CREATOR: Ryan Morganti /// CREATED: 2020/04/29 /// APPROVER: Derek Taylor /// /// Access layer method to SELECT and individual RecurringDonationInfo record /// by its ID. /// </summary> /// <remarks> /// UPDATER: NA /// UPDATED: NA /// UPDATE: NA /// /// </remarks> public RecurringDonationVM SelectRecurringDonationByID(int id) { RecurringDonationVM donation = new RecurringDonationVM(); var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_select_recurring_donation_by_id", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@RecurringDonationID", id); try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { donation.RecurringDonationID = id; donation.UserName = reader.GetString(0); donation.DonorID = reader.GetInt32(1); donation.DonationAmount = reader.GetDecimal(2); donation.StartDate = reader.GetDateTime(3); donation.Interval = reader.GetInt32(4); donation.Active = reader.GetBoolean(5); } } reader.Close(); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(donation); }
/// <summary> /// CREATOR: Ryan Morganti /// CREATED: 2020/04/16 /// APPROVER: Derek Taylor /// /// Access layer method to insert new recurring donation records into the database. /// This method will create a new donorID before linking it to the RecurringDonationInfo table. /// Then will make the first donation, tying it to the RecurringDonationInfo in the RecurringDonation table. /// </summary> /// <remarks> /// UPDATER: NA /// UPDATED: NA /// UPDATE: NA /// /// </remarks> public int InsertNewRecurringDonation(RecurringDonationVM donation) { int donorID; int result; int recurringDonationID; int donationID; string firstName = ""; string lastName = ""; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_select_name_by_username", conn); var cmd2 = new SqlCommand("sp_insert_new_donor", conn); var cmd3 = new SqlCommand("sp_insert_new_recurring_donation_info", conn); var cmd4 = new SqlCommand("sp_insert_new_monetary_donation", conn); var cmd5 = new SqlCommand("sp_insert_new_recurring_donation", conn); cmd.CommandType = CommandType.StoredProcedure; cmd2.CommandType = CommandType.StoredProcedure; cmd3.CommandType = CommandType.StoredProcedure; cmd4.CommandType = CommandType.StoredProcedure; cmd5.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserName", donation.UserName); try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { firstName = reader.GetString(0); lastName = reader.GetString(1); } } reader.Close(); cmd2.Parameters.AddWithValue("@FirstName", firstName); cmd2.Parameters.AddWithValue("@LastName", lastName); donorID = Convert.ToInt32(cmd2.ExecuteScalar()); cmd3.Parameters.AddWithValue("@UserName", donation.UserName); cmd3.Parameters.AddWithValue("@DonorID", donorID); cmd3.Parameters.AddWithValue("@DonationAmount", donation.DonationAmount); cmd3.Parameters.AddWithValue("@Interval", donation.Interval); recurringDonationID = Convert.ToInt32(cmd3.ExecuteScalar()); cmd4.Parameters.AddWithValue("@DonorID", donorID); cmd4.Parameters.AddWithValue("@TypeOfDonation", "Monetary - Recurring"); cmd4.Parameters.AddWithValue("@DonationAmount", donation.DonationAmount); donationID = Convert.ToInt32(cmd4.ExecuteScalar()); cmd5.Parameters.AddWithValue("@RecurringDonationID", recurringDonationID); cmd5.Parameters.AddWithValue("@DonationID", donationID); result = cmd5.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(result); }