public bool SaveOrder()
        {
            // get cart in session
            Cart cart = null;
            List <KeyValuePair <Toy, int> > toyList = null;
            var cartJson = HttpContext.Session.GetString("CART");

            if (string.IsNullOrEmpty(cartJson))
            {
                return(false);
            }
            else
            {
                toyList = JsonConvert.DeserializeObject <List <KeyValuePair <Toy, int> > >(cartJson);
                cart    = new Cart(toyList.ToDictionary(item => item.Key, item => item.Value));
            }

            // get login user
            var username = HttpContext.Session.GetString("USERNAME");

            try {
                var result = _ordersDao.CreateOrder(username, cart);
                Debug.WriteLine("==> save order result: " + result);
                if (result)
                {
                    HttpContext.Session.Remove("CART"); // delete cart
                }

                return(result);
            } catch (Exception ex) {
                return(false);
            }
        }
Example #2
0
        public ActionResult ConfirmOrder(Order form)
        {
            //Prepare the model to be viewed.
            //Do not call on the DAO
            ActionResult response;
            long         PCID = (int)Session["PcID"];

            try
            {
                long   userId   = (long)Session["UserId"];
                string Username = (string)Session["Username"];
                //Map User
                UserDO userDO = userDao.ViewUserByID(userId);
                User   user   = userMapper.MapDOtoPO(userDO);

                PcDO pc = pcDAO.ViewDetails(form.PcID);

                PC mappedPc = pcMapper.MapDoToPO(pc);
                if (ModelState.IsValid)
                {
                    OrderDO OrderObject = new OrderDO()
                    {
                        pcID    = mappedPc.PcID,
                        pcName  = mappedPc.PcName,
                        Address = form.Address,
                        Country = form.Country,

                        price    = mappedPc.Price,
                        userID   = pc.UserID,
                        userName = pc.Username
                    };
                    ordersDAO.CreateOrder(OrderObject);
                    response = RedirectToAction("Store", "PC");
                }
                else
                {
                    response = RedirectToAction("Store", "Pc");
                }
            }
            catch
            {
                response = View(form);
            }
            return(response);
        }
Example #3
0
        private void btnCheckOut_Click(object sender, EventArgs e)
        {
            Dictionary <Toy, int> OrderCart = frmDisplayToy.OrderCart;

            OrdersDAO dao = new OrdersDAO();

            try
            {
                bool result = dao.CreateOrder(frmLogin.AuthorizedUser.Username, OrderCart);

                if (result)
                {
                    MessageBox.Show("Order Complete!");
                    this.Close();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }