예제 #1
0
        public ActionResult ViewDonationsbyUserID(long UserID)
        {
            ActionResult oResponse = null;

            if (Session["Username"] == null) //Guest
            {
                oResponse = RedirectToAction("Index", "Home");
            }
            else //Everyone else
            {
                DonationVM newVM = new DonationVM();//Creating new instance
                try
                {
                    //Uses method form DAL then assigns to variable
                    List <IDonationDO> userDonationInfo = UserAccess.ViewDonationsbyUserID(UserID);
                    //Mapping assigned to a variable
                    newVM.DonationList = DonationMap.MapDOtoPO(userDonationInfo);
                    //Return view
                    oResponse = View(newVM);
                }
                catch (Exception e)
                {
                    newVM.ErrorMessage = "Sorry we cannot process your request at this time";
                    ErrorLog.LogError(e);
                    oResponse = View(newVM);
                }
                finally
                {
                    //Onshore standards
                }
            }
            return(oResponse);
        }
예제 #2
0
        public ActionResult ViewDonations()
        {
            ActionResult oResponse = null;

            DonationVM newVM = new DonationVM();

            if (Session["Username"] == null || (Int16)Session["Role"] != 1)
            {
                //Power User & User are redirected
                oResponse = RedirectToAction("Index", "Home");
            }
            else
            {
                try
                {
                    //Call method from DAL to be put into variable
                    List <IDonationDO> donationInfo = DonationAccess.ViewAllDonations();
                    //put mapping into a variable
                    newVM.DonationList = DonationMap.MapDOtoPO(donationInfo);
                    //Return view
                    oResponse = View(newVM);
                }
                catch (Exception e)
                {
                    newVM.ErrorMessage = "Sorry, We couldn't obtain the list of donations list";
                    ErrorLog.LogError(e); //log error
                }
                finally
                {
                    //Onshore standards
                }
            }

            return(oResponse);
        }
예제 #3
0
        ItemBusinessLogicLayer ItemTotal       = new ItemBusinessLogicLayer();  //use of BLL

        public ActionResult Index()
        {
            //define variable
            decimal average = 0;


            //assigned method into variable
            List <IDonationDO> donationInfo = DonationAccess.ViewAllDonations();
            //assigned mapping into variable
            List <IDonationBO> DonationList = DonationMap.MapDOtoBO(donationInfo);

            //use BLL method assigned into variable
            average = DonationAverage.AverageDonation(DonationList);
            //setting average to a Viewbag to be able to see on view
            ViewBag.AverageDonation = average;



            return(View());
        }
예제 #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);
        }
예제 #5
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);
        }
예제 #6
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);
        }