Пример #1
0
        public void CreateOrderDetail(OrderDetail orderDetail)
        {
            OrderDetailDAO orderDetailDAO = new OrderDetailDAO();

            orderDetailDAO.CreateOrderDetail(orderDetail);
        }
Пример #2
0
        public ActionResult Confirm()
        {
            bool       errorQuantity = false;
            ProductDAO dao           = new ProductDAO();
            CartItem   c             = (CartItem)Session["CART"];

            string[,] listErrorQuantity = new string[c.Cart.Count, 1];
            for (int i = 0; i < c.Cart.Count; i++)
            {
                int quantityAtCart     = c.Cart[i].Quantity;
                int quantityInDatabase = dao.GetProductQuantity(c.Cart[i].Product.ID);
                if (quantityAtCart > quantityInDatabase)
                {
                    listErrorQuantity.SetValue("Max : " + quantityInDatabase, i, 0);
                    errorQuantity = true;
                }
            }
            if (errorQuantity == false)
            {
                for (int i = 0; i < c.Cart.Count; i++)
                {
                    dao.UpdateQuantitty(c.Cart[i].Product.ID, c.Cart[i].Quantity);
                }


                float       totalPrice = float.Parse(Request["TotalPrice"]);
                CustomerDAO daoCus     = new CustomerDAO();
                CustomerDTO cus        = (CustomerDTO)Session["CUSTOMER"];
                bool        result     = daoCus.CheckOut(totalPrice, cus.Username);

                //check point and maybe update rank

                string newRank = "";

                float  point       = daoCus.GetPointOfCus(cus.Username);
                string currentRank = cus.Rank;
                if (currentRank == null)
                {
                    currentRank = "";
                }

                if (point >= 500 && point < 2000 && currentRank.Equals("bronze") == false)
                {
                    newRank = "bronze";
                    daoCus.UpdateRank(cus.Username, newRank);
                    ViewBag.Congrats = "Congratulations!!! Your rank is Bronze now. Thank you for choosing our service.";
                }
                if (point >= 2000 && point < 5000 && currentRank.Equals("silver") == false)
                {
                    newRank = "silver";
                    daoCus.UpdateRank(cus.Username, newRank);
                    ViewBag.Congrats = "Congratulations!!! Your rank is Silver now. Thank you for choosing our service.";
                }
                if (point >= 5000 && point < 15000 && currentRank.Equals("gold") == false)
                {
                    newRank = "gold";
                    daoCus.UpdateRank(cus.Username, newRank);
                    ViewBag.Congrats = "Congratulations!!! Your rank is Gold now. Thank you for choosing our service.";
                }
                if (point >= 15000 && currentRank.Equals("platinum") == false)
                {
                    newRank = "platinum";
                    daoCus.UpdateRank(cus.Username, newRank);
                    ViewBag.Congrats = "Congratulations!!! Your rank is Platinum now. Thank you for choosing our service.";
                }

                //when checkout done
                if (result)
                {
                    // create order
                    DateTime createDate = DateTime.Now;
                    string   cusID      = cus.Username;
                    int      state      = 0;// start order

                    float discount = 0;
                    if (Session["Discount"] != null) // neu moi mua lan dau thi ko co discount
                    {
                        discount = (float)Session["Discount"];
                    }

                    BillDTO order       = new BillDTO(createDate, cusID, state, totalPrice, discount);
                    BillDAO daoOrder    = new BillDAO();
                    bool    resultOrder = daoOrder.CreateOrder(order);// create order
                    if (resultOrder)
                    {
                        OrderDetailDAO daoOrderDetail = new OrderDetailDAO();
                        int            orderID        = daoOrder.GetOrderID(); // get orderID has created
                        for (int i = 0; i < c.Cart.Count; i++)
                        {
                            OrderDetailDTO orderDetail = new OrderDetailDTO(orderID, c.Cart[i].Product.ID,
                                                                            c.Cart[i].Quantity, c.Cart[i].Product.Price, c.Cart[i].Product.NameProduct);
                            daoOrderDetail.CreateOrderDetail(orderDetail);
                        }

                        Session.Remove("CART");

                        Session.Remove("txtSearchValue");
                    }
                }
            }
            else
            {
                ViewBag.ErrorQuantity = listErrorQuantity;
                return(View("ViewCart"));
            }



            return(View("ViewOrdercomplete"));
        }