예제 #1
0
        public ActionResult CreateOrderDetail(int id, CreateOrderDetail orderDetail)
        {
            if (ModelState.IsValid)
            {
                using (MySqlConnection conn = DBUtils.GetConnection())
                {
                    OrderDetails orderdet = new OrderDetails();

                    orderdet.OrderID   = orderDetail.OrderID;
                    orderdet.ProductID = orderDetail.ProductID;
                    orderdet.Quantity  = orderDetail.Quantity;
                    orderdet.UnitPrice = orderDetail.UnitPrice;
                    orderdet.Discount  = 0;

                    OrderDetailsRepository orderRepo = new OrderDetailsRepository(conn);
                    orderRepo.Save(orderdet);
                }

                return(RedirectToAction("OrderDetails", new { id = orderDetail.OrderID }));
            }

            using (MySqlConnection conn = DBUtils.GetConnection())
            {
                DisplayProductRepository product = new DisplayProductRepository(conn);
                orderDetail.ProductList = product.GetAll().ToList <DisplayProduct>();
            }

            return(View(orderDetail));
        }
예제 #2
0
        // GET: Order/Create
        public ActionResult CreateOrderDetail(int id)
        {
            CreateOrderDetail order = new CreateOrderDetail();

            order.OrderID = id;
            using (MySqlConnection conn = DBUtils.GetConnection())
            {
                DisplayProductRepository product = new DisplayProductRepository(conn);
                order.ProductList = product.GetAll().ToList <DisplayProduct>();
            }

            return(View(order));
        }
        public HttpResponseMessage Products()
        {
            try
            {
                List <DisplayProduct> products = new List <DisplayProduct>();
                using (MySqlConnection conn = DBUtils.GetConnection())
                {
                    DisplayProductRepository repo = new DisplayProductRepository(conn);
                    products = repo.GetAll().ToList <DisplayProduct>();
                }

                return(Request.CreateResponse(HttpStatusCode.OK, products));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, ex.Message));
            }
        }