Example #1
0
 public bool InsertOrderDetail(ORDERS_DETAIL newOrderDetail)
 {
     using (OrderGraberDBEntities dbContext = new OrderGraberDBEntities())
     {
         dbContext.ORDERS_DETAIL.Add(newOrderDetail);
         dbContext.SaveChanges();
     }
     return(true);
 }
Example #2
0
        public ORDERS_DETAIL GetOrderDetailsById(int id)
        {
            var orderDetails = new ORDERS_DETAIL();

            using (OrderGraberDBEntities dbContext = new OrderGraberDBEntities())
            {
                orderDetails = dbContext.ORDERS_DETAIL.FirstOrDefault(x => x.line_id == id);
            }
            return(orderDetails);
        }
Example #3
0
        public bool UpdateOrderDetail(ORDERS_DETAIL editOrderDetail)
        {
            bool result = false;

            using (OrderGraberDBEntities dbContext = new OrderGraberDBEntities())
            {
                var recordToEdit = dbContext.ORDERS_DETAIL.FirstOrDefault(x => x.line_id == editOrderDetail.line_id);
                recordToEdit.order_id   = editOrderDetail.order_id;
                recordToEdit.product_id = editOrderDetail.product_id;
                recordToEdit.quantity   = editOrderDetail.quantity;
                recordToEdit.total_line = editOrderDetail.total_line;
            }
            return(result);
        }
Example #4
0
        public ActionResult AddNewOrder(FormCollection form)
        {
            CUSTOMER cus   = (CUSTOMER)Session["Customers"];
            ORDER    order = new ORDER();
            DateTime d     = DateTime.Now;

            order.Orders_Date    = d;
            order.Customers_ID   = cus.Customers_ID;
            order.Status         = 0;
            order.Note           = form["Note"];
            order.Payment_Method = byte.Parse(form["Payment_Method"]);
            order.Payment_Status = 0;
            db.ORDERS.Add(order);
            db.SaveChanges();

            List <Cart> listCart = (List <Cart>)Session["Cart"];

            foreach (var item in listCart)
            {
                ORDERS_DETAIL od = new ORDERS_DETAIL();
                od.Orders_ID   = order.Orders_ID;
                od.Product_ID  = item.Product.Product_ID;
                od.Product_Num = item.Amount;
                db.ORDERS_DETAIL.Add(od);
                var pro = (from p in db.PRODUCTs
                           where p.Product_ID == item.Product.Product_ID
                           select p).FirstOrDefault();
                pro.Product_Stock_Quantity = pro.Product_Stock_Quantity - item.Amount;
            }
            db.SaveChanges();

            if (form["Payment_Method"].CompareTo("1") == 0)
            {
                return(View("PaymentGuide", order));
            }

            ViewBag.Message = "<div class=\"alert alert-success\" role=\"alert\"><i class=\"fas fa-check\"></i>&nbsp;Đặt hàng thành công !</div>";
            Session.Remove("Cart");
            var listProduct = (from pro in db.PRODUCTs
                               where pro.Product_Status == 1
                               select pro).ToList();

            return(View("~/Views/Home/Index.cshtml", listProduct));
        }