Example #1
0
        public static DonationBO MapDOtoBO(IDonationDO iFrom)
        {
            DonationBO oTo = new DonationBO(); //creating new instance PO

            //BO                //DO
            oTo.DonationID = iFrom.DonationID;
            oTo.UserID     = iFrom.UserID;
            oTo.Amount     = iFrom.Amount;
            oTo.CardNumber = iFrom.CardNumber;
            oTo.Rendered   = iFrom.Rendered;

            return(oTo); //returning object
        }
        public void UpdateDonation(IDonationDO iDonation)
        {
            try
            {
                using (SqlConnection connectionToSql = new SqlConnection(_ConnectionString))
                {
                    using (SqlCommand command = new SqlCommand("UPDATE_DONATIONS", connectionToSql))
                    {
                        try
                        {
                            command.CommandType    = CommandType.StoredProcedure;
                            command.CommandTimeout = 30;

                            //Passing parameters from sql
                            command.Parameters.AddWithValue("@DonationID", iDonation.DonationID);
                            command.Parameters.AddWithValue("@UserID", iDonation.UserID);
                            command.Parameters.AddWithValue("@Amount", iDonation.Amount);
                            command.Parameters.AddWithValue("@CardNumber", iDonation.CardNumber);
                            command.Parameters.AddWithValue("@Rendered", iDonation.Rendered);


                            connectionToSql.Open();
                            command.ExecuteNonQuery();
                        }
                        catch (Exception e)
                        {
                            throw (e);
                        }
                        finally
                        {
                            connectionToSql.Close();
                            connectionToSql.Dispose();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw (e);
            }
            finally
            {
                //Onshore standards
            }
        }
Example #3
0
        public ActionResult UpdateDonation(DonationVM iDonation)
        {
            ActionResult oResponse = null;

            if (Session["Username"] == null || (Int16)Session["Role"] != 1)
            {
                //Power User & User redirected
                oResponse = RedirectToAction("Index", "Home");
            }
            else //Admin
            {
                if (ModelState.IsValid) //Info correct
                {
                    try
                    {
                        //put mapping into a variable
                        IDonationDO update = DonationMap.MapPOtoDO(iDonation.Donation);
                        //Use of method from DAL
                        DonationAccess.UpdateDonation(update);
                        //Return the list of donations
                        oResponse = RedirectToAction("ViewDonations", "Donation");
                    }
                    catch (Exception e)
                    {
                        iDonation.ErrorMessage = "Sorry we are unable to handle your request";
                        ErrorLog.LogError(e); //Log into file
                        oResponse = RedirectToAction("UpdateDonation", "Donation");
                    }
                    finally
                    {
                        //Onshore standards
                    }
                }
                else //Info incorrect
                {
                    oResponse = View(iDonation);
                }
            }
            return(oResponse);
        }
Example #4
0
        public ActionResult CreateDonations(DonationVM iDonation)
        {
            ActionResult oResponse = null;   //defining our varivale

            if (Session["Username"] == null) //Guest
            {
                oResponse = RedirectToAction("Index", "Home");
            }

            else  //Users,Power User, Admin
            {
                if (ModelState.IsValid)//If info was entered correctly
                {
                    try
                    {
                        //set mapping to a variable to be used to convert POtoDO
                        IDonationDO DonationForm = DonationMap.MapPOtoDO(iDonation.Donation);
                        //Use the method from DAL to preform action
                        DonationAccess.CreateDonation(DonationForm);
                        //Redirect to view using UserID from database
                        oResponse = RedirectToAction("ViewDonationsbyUserID", "User", new { UserID = (long)Session["UserID"] });
                    }
                    catch (Exception e) //If problem with sql connection
                    {
                        iDonation.ErrorMessage = "We are sorry, We cannot process your request at this time";
                        ErrorLog.LogError(e);        //Log to file
                        oResponse = View(iDonation); //return view
                    }
                    finally
                    {
                        //Onshore standards
                    }
                }
                else //If info was incorrect
                {
                    oResponse = View(iDonation);
                }
            }
            return(oResponse);
        }
Example #5
0
        public ActionResult UpdateDonation(long DonationID)
        {
            ActionResult oResponse = null;

            if (Session["Username"] == null || (Int16)Session["Role"] != 1)
            {
                //Power User & User redirected
                oResponse = RedirectToAction("Index", "Home");
            }
            else //Admin
            {
                //Create a new instance of the object
                DonationVM newVM = new DonationVM();
                //set the method to a variable to be used
                IDonationDO donation = DonationAccess.ViewDonationsByID(DonationID);
                //set mapping to a variable
                newVM.Donation = DonationMap.MapDOtoPO(donation);
                //return view
                oResponse = View(newVM);
            }

            return(oResponse);
        }