Пример #1
0
        public void CreateOrder(OrderDto OrderDto)
        {
            var Order = OrderDto.ConvertToOrder();

            _unitOfWork.Orders.Add(Order);

            _unitOfWork.Complete();
        }
Пример #2
0
        //them order
        public void AddOrder(string currentusername, OrderDto Order, List <Item> cart, OrderDetailDto OrderDetail)
        {
            int customerid = _unitOfWork.Orders.GetIdCurrentUser(currentusername);

            Order.OrderCustomerId = customerid;


            Order.OrderDate = DateTime.Now;

            //add Order
            var Orders = Order.ConvertToOrder();  //chuyen orderdto sang order

            _unitOfWork.Orders.Add(Orders);

            _unitOfWork.Complete(); //save

            //add item
            int orderid = _unitOfWork.Orders.GetOrderId(customerid);

            for (var i = 0; i < cart.Count; i++)
            {
                //them vao bang OrderDetail
                var OrderDetails = OrderDetail.ConvertToOrderDetail();
                OrderDetails = new OrderDetail();

                OrderDetails.DetailProductId = cart[i].Product.ProductId;
                OrderDetails.DetailOrderId   = orderid; //orderid
                OrderDetails.Quantity        = cart[i].Quantity;



                _unitOfWork.OrderDetails.Add(OrderDetails);
                _unitOfWork.Complete();//luu database
            }

            cart.Clear(); //xoa gio hang



            //HttpContext.Session.Remove("cart");//xoa session gio hang
        }