public string AddToCart(string paramList)
        {
            //"CartError"
            //"LoginPrompt"
            //cartItem
            JavaScriptSerializer jsonObj = new JavaScriptSerializer();
            string[] parameters = paramList.Split(',');
            int itemId = -1;
            var category = "";
            var userID = -1;
            var status = false;
            CartItem cartItem = new CartItem();

            if (Session["UserID"] != null) //already logged in
            {
                if (Session["Role"].Equals("admin") || Session["Role"].Equals("member"))
                {
                    userID = (int)Session["UserID"];
                }
            }
            else
            {
                return jsonObj.Serialize(new CartItem { ItemCategory = "LoginPrompt" });
            }
            if (parameters.Length > 0 && parameters[0].Length > 0)
            {
                itemId = Convert.ToInt32(parameters[0]);
            }
            if (parameters.Length > 1)
            {
                category = parameters[1];
            }
            try
            {
                var cartDAL = new UserCartDAL(userID);
                cartItem.ItemID = itemId;
                cartItem.ItemCategory = category;
                status = cartDAL.AddToCart(cartItem);
                if (false == status)
                {
                    return jsonObj.Serialize(new CartItem { ItemCategory = "CartError" });
                }
            }
            catch (Exception)
            {

            }
            return (jsonObj.Serialize(cartItem));
        }
        public string AddToPayment(CartItem paymentItem)
        {
            //"CartError"
            //"LoginPrompt"
            //cartItem
            JavaScriptSerializer jsonObj = new JavaScriptSerializer();
            //string[] parameters = paramList.Split(',');
            //int itemId = -1;
            //var category = "";

            if (Session["UserID"] != null) //already logged in
            {
                if (Session["Role"].Equals("admin") || Session["Role"].Equals("member"))
                {
                    UserID = (int)Session["UserID"];
                }
            }
            else
            {
                return jsonObj.Serialize(new CartItem { ItemCategory = "LoginPrompt" });
            }
            //if (parameters.Length > 0 && parameters[0].Length > 0)
            //{
            //    itemId = Convert.ToInt32(parameters[0]);
            //}
            //if (parameters.Length > 1)
            //{
            //    category = parameters[1];
            //}
            try
            {
                var cartDAL = new UserCartDAL(UserID);
                //cartItem.ItemID = itemId;
                //cartItem.ItemCategory = category;
                var status = cartDAL.AddToPayment(paymentItem);
                if (false == status)
                {
                    // return jsonObj.Serialize(new CartItem { ItemCategory = "CartError" });
                }
            }
            catch (Exception)
            {

            }
            return (jsonObj.Serialize(paymentItem));
        }
        public string Update(string paramList)
        {
            string[] parameters = paramList.Split(',');
            int itemId = -1;
            var category = "";
            var noOfCopies = -1;
            var userID = -1;
            var status = false;
            JavaScriptSerializer jsonObj = new JavaScriptSerializer();
            var cartItem = new CartItem();
            //only assign item id, and category field

            if (Session["UserID"] != null) //already logged in
            {
                if (Session["Role"].Equals("admin") || Session["Role"].Equals("member"))
                {
                    userID = (int)Session["UserID"];
                }
            }
            else
            {
                return jsonObj.Serialize(new CartItem { ItemCategory = "LoginPrompt" });
            }
            if (parameters.Length > 0 && parameters[0].Length > 0)
            {
                itemId = Convert.ToInt32(parameters[0]);
            }
            //do not use if-else
            if (parameters.Length > 1)
            {
                category = parameters[1];
            }
            if (parameters.Length > 2)
            {
                noOfCopies = Convert.ToInt32(parameters[2]);
            }

            try
            {
                var cartDAL = new UserCartDAL(userID);
                cartItem.ItemID = itemId;
                cartItem.ItemCategory = category;
                cartItem.NoOfCopies = noOfCopies;
                status = cartDAL.UpdateCart(cartItem);
                if (false == status)
                {
                    return jsonObj.Serialize(new CartItem { ItemCategory = "CartError" });
                }
            }
            catch (Exception)
            {

            }
            return (jsonObj.Serialize(cartItem));
        }
        public string ProceedPayment(string paramList)
        {
            List<CartItem> cartItemList = new List<CartItem>();
            List<CartItem> userPaymentPool = new List<CartItem>();
            JavaScriptSerializer jsonObj = new JavaScriptSerializer();
            int TotalAmount = 0, DiscountAmount = 0, NetAmount = 0;

            if (null == UserID) UserID = -1;
            try
            {
                if (Session["UserID"] != null) //already logged in
                {
                    if (Session["Role"].Equals("admin") || Session["Role"].Equals("member"))
                    {
                        UserID = (int)Session["UserID"];
                    }
                }
                else
                {

                    return jsonObj.Serialize(userPaymentPool);
                    //return RedirectToAction("Login", "Account", new { ReturnToUrl = "/ProceedPayment/" });//RedirectToAction("Login","Account");
                }
                var userCartDAL = new UserCartDAL(UserID);
                string[] parameters = paramList.Split(',');
                int itemId = -1;
                for (var i = 0; i + 2 <= parameters.Length; i += 2)
                {
                    string category;
                    if (parameters[i].Length > 0)
                    {
                        itemId = Convert.ToInt32(parameters[i]);
                        if (itemId <= 0)
                        {
                            return jsonObj.Serialize(userPaymentPool);
                        }
                    }
                    else
                    {
                        return jsonObj.Serialize(userPaymentPool);
                    }
                    if (parameters[i + 1].Length > 1)
                    {
                        category = parameters[i + 1];
                    }
                    else
                    {
                        return jsonObj.Serialize(userPaymentPool);
                    }
                    //var bestPossibleCartItem = userCartDAL.getCartItemNoOfCopiesPossibleAndCostDiscountPossible(category, itemId);

                    var proceedCartItem = userCartDAL.GetCartItem(itemId, category);
                    if (proceedCartItem == null)
                    {
                        continue; //skip this item, cannot be added to purchase.
                    }
                    var noOfCopies = proceedCartItem.NoOfCopies;
                    var cost = proceedCartItem.Cost;
                    var paymentItem = new CartItem
                    {
                        UserID = proceedCartItem.UserID,
                        ItemID = itemId,
                        ItemCategory = category,
                        NoOfCopies = noOfCopies, //quantity required
                        Cost = noOfCopies * cost,//Total amount
                        Discount = proceedCartItem.Discount
                    };
                    TotalAmount += paymentItem.Cost;
                    DiscountAmount = (int)(TotalAmount * paymentItem.Discount / 100.0);
                    userPaymentPool.Add(paymentItem);
                    //cartItemList = userCartDAL.ProceedPayment(cartItem);

                }
                userCartDAL.ClearPaymentPool();
                foreach (CartItem paymentItem in userPaymentPool)
                {
                    AddToPayment(paymentItem);
                }
            }
            catch (Exception)
            {
                //return RedirectToAction("Index", "Home");
            }
            NetAmount = TotalAmount - DiscountAmount;

            Session["TotalAmount"] = TotalAmount;
            Session["NetAmount"] = NetAmount;
            Session["Discount"] = DiscountAmount;

            return jsonObj.Serialize(userPaymentPool);
        }
 public ActionResult Index()
 {
     if (null == UserID) UserID = -1;
     List<CartItem> cartItemList = new List<CartItem>();
     try
     {
         if (Session["UserID"] != null) //already logged in
         {
             if (Session["Role"].Equals("admin") || Session["Role"].Equals("member"))
             {
                 UserID = (int)Session["UserID"];
             }
         }
         else
         {
             //return
             return RedirectToAction("Login", "Account", new { ReturnToUrl = "/Cart/" });//RedirectToAction("Login","Account");
         }
         var userCartDAL = new UserCartDAL(UserID);
         cartItemList = userCartDAL.getCartItems();
     }
     catch (Exception)
     {
         return RedirectToAction("Index", "Home");
     }
     return View(new BankCart());
 }
        public string GetCart()
        {
            List<CartItem> cartItemList = new List<CartItem>();
            JavaScriptSerializer jsonObj = new JavaScriptSerializer();
            if (null == UserID) UserID = -1;
            try
            {
                if (Session["UserID"] != null) //already logged in
                {
                    if (Session["Role"].Equals("admin") || Session["Role"].Equals("member"))
                    {
                        UserID = (int)Session["UserID"];
                    }
                }

                else
                {
                    return jsonObj.Serialize(new CartItem { ItemCategory = "LoginPrompt" });
                }
                //else
                //{
                //    //return
                //    return jsonObj.Serialize(cartItemList);//RedirectToAction("Login","Account");
                //}
                var userCartDAL = new UserCartDAL(UserID);
                cartItemList = userCartDAL.getCartItems();
            }
            catch (Exception)
            {
                return jsonObj.Serialize(new CartItem { ItemCategory = "CartError" });
            }
            return jsonObj.Serialize(cartItemList);
        }
        public string BankPayment(string paramList)
        {
            string[] parameters = paramList.Split(',');
            JavaScriptSerializer jsonObj = new JavaScriptSerializer();
            try
            {
                if (Session["UserID"] != null) //already logged in
                {
                    if (Session["Role"].Equals("admin") || Session["Role"].Equals("member"))
                    {
                        UserID = (int)Session["UserID"];
                    }
                }
                else
                {
                    return jsonObj.Serialize("LoginPrompt");//RedirectToAction("Login","Account");
                }
                var userCartDAL = new UserCartDAL(UserID);

                var validateTrans = UserDAL.AuthenticateTransaction(UserID, parameters[0], parameters[1], parameters[2]);

                if (validateTrans)
                {
                    if (userCartDAL.SaveTransaction(parameters[1]))
                    {
                        return jsonObj.Serialize("success");
                    }
                }
            }
            catch (Exception)
            {
            }
            return jsonObj.Serialize("failure");
        }
Exemplo n.º 8
0
        public ActionResult Index(BankCart model)
        {
            if (null == UserID) UserID = -1;
            List<CartItem> cartItemList = new List<CartItem>();
            try
            {
                if (Session["UserID"] != null) //already logged in
                {
                    if (Session["Role"].Equals("admin") || Session["Role"].Equals("member"))
                    {
                        UserID = (int)Session["UserID"];
                    }
                }
                else
                {
                    //return
                    return RedirectToAction("Login", "Account", new { ReturnToUrl = "/Cart/" });//RedirectToAction("Login","Account");
                }
                var userCartDAL = new UserCartDAL(UserID);

                var validateTrans = true;// UserDAL.AuthenticateTransaction(UserID, model.BankName, model.AccountNo, model.TransactionPassword);

                if (validateTrans)
                {
                    if (userCartDAL.SaveTransaction(model.AccountNo))
                    {
                        return RedirectToAction("Member", "Transaction");
                    }
                }
            }
            catch (Exception)
            {

            }
            ModelState.AddModelError("", "Incorrect bank details are entered.");
            return View(model);
        }