public List <IDonationDO> ViewDonationsbyUserID(long UserID) { List <IDonationDO> userDonation = new List <IDonationDO>(); //create new instance of list try //Catch Exceptions { //Create connection using (SqlConnection connectionToSql = new SqlConnection(_ConnectionString)) { //Create command using (SqlCommand storedCommand = new SqlCommand("VIEW_DONATIONS_BY_USER_ID", connectionToSql)) { try { //Command properties storedCommand.CommandType = CommandType.StoredProcedure; storedCommand.CommandTimeout = 30; //pull only that users info storedCommand.Parameters.AddWithValue("@UserID", UserID); connectionToSql.Open(); SqlDataReader commandReader = storedCommand.ExecuteReader(); while (commandReader.Read()) { //Read all properties DonationDO donate = new DonationDO() //Create new instance { DonationID = commandReader.GetInt64(0), UserID = commandReader.GetInt64(1), Amount = commandReader.GetDecimal(2), CardNumber = commandReader.GetInt64(3), Rendered = commandReader.GetBoolean(4), }; userDonation.Add(donate); //Add all properites to list } } catch (Exception e) { throw (e); //throw to outer try catch } finally { connectionToSql.Close(); //Saftey connectionToSql.Dispose(); } } } } catch (Exception e) { LogError.Log(e); throw (e); //throw to controller } finally { //Onshore standards } return(userDonation); //Return List }
public List <IDonationDO> ViewAllDonations() { //Creating new instance of a list List <IDonationDO> viewDonations = new List <IDonationDO>(); try { using (SqlConnection connectionToSql = new SqlConnection(_ConnectionString)) { using (SqlCommand storedCommand = new SqlCommand("VIEW_DONATIONS", connectionToSql)) { try { storedCommand.CommandType = CommandType.StoredProcedure; storedCommand.CommandTimeout = 30; connectionToSql.Open(); SqlDataReader commandReader = storedCommand.ExecuteReader(); while (commandReader.Read()) { IDonationDO donation = new DonationDO() //new instance of and object { //properties DonationID = commandReader.GetInt64(0), UserID = commandReader.GetInt64(1), Amount = commandReader.GetDecimal(2), CardNumber = commandReader.GetInt64(3), Rendered = commandReader.GetBoolean(4) }; viewDonations.Add(donation); //Add each property one by one with reader } } catch (Exception e) { throw (e); //throw to outer try catch } finally { connectionToSql.Close(); //Saftey connectionToSql.Dispose(); } } } } catch (Exception e) { throw (e); //throw exception to the student controller } finally { //Onshore standards } return(viewDonations); //return the list }
public IDonationDO ViewDonationsByID(long DonationID) { IDonationDO viewDonations = new DonationDO(); try { using (SqlConnection connectionToSql = new SqlConnection(_ConnectionString)) { using (SqlCommand command = new SqlCommand("VIEW_DONATIONS_BY_ID", connectionToSql)) { try { command.CommandType = CommandType.StoredProcedure; command.CommandTimeout = 30; command.Parameters.AddWithValue("@DonationID", DonationID); connectionToSql.Open(); using (SqlDataReader commandReader = command.ExecuteReader()) { while (commandReader.Read()) { viewDonations.DonationID = commandReader.GetInt64(0); viewDonations.UserID = commandReader.GetInt64(1); viewDonations.Amount = commandReader.GetDecimal(2); viewDonations.CardNumber = commandReader.GetInt64(3); viewDonations.Rendered = commandReader.GetBoolean(4); } } } catch (Exception e) { throw (e); } finally { connectionToSql.Close(); connectionToSql.Dispose(); } } } } catch (Exception e) { throw (e); } finally { //Onshore standards } return(viewDonations); }
public static IDonationDO MapPOtoDO(DonationPO iFrom) { IDonationDO oTo = new DonationDO(); //creating instance of an object //DO //PO oTo.DonationID = iFrom.DonationID; oTo.UserID = iFrom.UserID; oTo.Amount = iFrom.Amount; oTo.CardNumber = iFrom.CardNumber; oTo.Rendered = iFrom.Rendered; return(oTo); //returning that object }