Exemple #1
0
        public ActionResult RedeemPoints()
        {
            if (Convert.ToInt32(Session["Rewards"]) < 10)
            {
                Session["message"]      = "Not Enough Points To Redeem, Spend Some More Money";
                Session["messageState"] = -1;
            }
            var repObj = new AmigoWalletRepository();
            var status = repObj.RedeemPoints(Session["email"].ToString());

            // Calculate rewards points and pass it to the view
            ViewBag.ViewRewards = repObj.GetRewardPoints(Session["email"].ToString());
            Session["Rewards"]  = repObj.GetRewardPoints(Session["email"].ToString());
            if (status == 1)
            {
                return(RedirectToAction("Home", "Account"));
            }
            return(RedirectToAction("Home", "Account"));
        }
Exemple #2
0
        /// <summary>
        /// Generates the account homepage with transactions, balance, cards, merchants, and utilities
        /// </summary>
        /// <param name="from">from date for the transactions to be fetched</param>
        /// <param name="from">to date for the transactions to be fetched</param>
        /// <returns></returns>
        public ActionResult Home(DateTime?from = null, DateTime?to = null)
        {
            try
            {
                // Data access layer object
                AmigoWalletRepository repObj = new AmigoWalletRepository();

                // Calculate rewards points and pass it to the view
                ViewBag.ViewRewards = repObj.GetRewardPoints(Session["email"].ToString());
                Session["Rewards"]  = repObj.GetRewardPoints(Session["email"].ToString());

                // Calculate balance points and pass it to the view
                ViewBag.ViewBalance = repObj.ViewBalance(Session["email"].ToString());


                //------- Get cards -------
                // Mapper for UserCard model to DAL
                AmigoWalletMapper <UserCard, Models.UserCard> map = new AmigoWalletMapper <UserCard, Models.UserCard>();

                // Get the list of all cards current user has, and add to a model list via mapping
                List <UserCard>        lstCards = repObj.getCardsBySessionEmail(Session["email"].ToString());
                List <Models.UserCard> cards    = new List <Models.UserCard>();
                foreach (var card in lstCards)
                {
                    cards.Add(map.Translate(card));
                }
                // Pass cards to the view
                ViewBag.UserCards = cards;


                //------- Get transactions -------
                // Mapper for the UserTransaction DAL to model
                var mapObj = new AmigoWalletMapper <UserTransaction, Models.UserTransaction>();

                // Create non-nullable DateTime objects for from and to and set them to the required range if passed in as null
                var f = from ?? DateTime.Today.AddMonths(-1);
                var t = to ?? DateTime.Today.AddDays(2);  // added two days to compensate for time difference

                // Get user's list of transactions
                var transList      = repObj.ViewUserTransaction(Session["email"].ToString(), f, t);
                var transModelList = new List <Models.UserTransaction>();

                // Pass date range as passed in to display on the view's date range selectors
                ViewBag.fromDate = f.ToString("yyyy-MM-dd");
                ViewBag.toDate   = t.ToString("yyyy-MM-dd");

                // Fill the model list with mapper and pass it to the view for display

                foreach (var transaction in transList)
                {
                    transModelList.Add(mapObj.Translate(transaction));
                }
                ViewBag.Transactions = transModelList;


                //------- Pay bill utility list -------
                // Fill list with the available service/utility types
                var utilList        = new List <SelectListItem>();
                var serviceTypeList = repObj.GetServiceTypes();

                // Create a list of selection options for the utility list dropdown and pass it to the view
                utilList.Add(new SelectListItem {
                    Text = "Please select a utility type", Value = "0"
                });
                for (int i = 0; i < serviceTypeList.Count; i++)
                {
                    utilList.Add(new SelectListItem {
                        Text = serviceTypeList[i].ServiceType, Value = (i + 1).ToString()
                    });
                }
                ViewData["utilities"] = utilList;

                // Draw the account homepage
                return(View());
            }
            catch (Exception)
            {
                // Show session expiration page and allow re-log
                return(View("_SessionExpired"));
            }
        }