Esempio n. 1
0
        public OrderProductVM GetOrderProductDetail(int orderNumber,int productId)
        {
            mergedEntities db = new mergedEntities();
            OrderProductVM orderProductVM = new OrderProductVM();

            var query =

             from o in db.OrderDetails
             where (o.orderNumber == orderNumber)
             from op in o.OrderProducts
             where (op.productID == productId)

             select new OrderProductVM()
             //select new
             {
                 OrderNumber = o.orderNumber,
                 ProductId = op.productID,
                 ProductName = op.Product.productName,
                 Quantity = (decimal)op.quantity
             };

            foreach (var item in query)
            {

                orderProductVM.OrderNumber = item.OrderNumber;
                orderProductVM.ProductId = item.ProductId;
                orderProductVM.ProductName = item.ProductName;
                orderProductVM.Quantity = item.Quantity;                
            }


            return orderProductVM;
        }
Esempio n. 2
0
        public OrderProductVM UpdateOrderProduct(OrderProductVM orderProductVM)
        {
            mergedEntities db = new mergedEntities();
            OrderProduct orderProduct = db.OrderProducts.Where(o => o.orderNumber == orderProductVM.OrderNumber && 
                                                         o.productID == orderProductVM.ProductId).FirstOrDefault();
            orderProduct.productID = orderProductVM.ProductId;
            orderProduct.quantity = orderProductVM.Quantity;

            db.SaveChanges();            
            return orderProductVM;
        }
Esempio n. 3
0
        public ActionResult EditOrderProduct(OrderProductVM orderProductVM)
        {
            ProductRepo productRepo = new ProductRepo();
            OrderProductVM editedOrderProductVM = new OrderProductVM();

            if (ModelState.IsValid)
            {
                editedOrderProductVM = productRepo.UpdateOrderProduct(orderProductVM);
                return RedirectToAction("DetailsOrderProduct", new { id = orderProductVM.OrderNumber });
            }
            else
            {
                ViewBag.ErrorMessage = "This entry is invalid.";
                return View(orderProductVM);
            }

        }
Esempio n. 4
0
        public ActionResult EditOrderProduct(int id,int productId) // "id" is "id order number".
        {
            ProductRepo productRepo = new ProductRepo();
            OrderProductVM orderProductVM = new OrderProductVM();


            orderProductVM = productRepo.GetOrderProductDetail(id, productId);
            return View(orderProductVM);
        }