Beispiel #1
0
        public ContentResult Edit(simpleSystem.ViewModels.OrderEditViewModels order)
        {
            OrderService orderService = new OrderService();

            Models.Order ModelOrder = new Models.Order
            {
                OrderID        = order.OrderID,
                CustomerID     = order.CustID,
                EmployeeID     = order.EmpId,
                Freight        = (decimal)order.Freight,
                OrderDate      = (DateTime)order.OrderDate,
                RequiredDate   = (DateTime)order.RequiredDate,
                ShipAddress    = order.ShipAddress,
                ShipCity       = order.ShipCity,
                ShipCountry    = order.ShipCountry,
                ShipName       = order.ShipName,
                ShippedDate    = order.ShippedDate,
                ShipperID      = order.ShipperId,
                ShipPostalCode = order.ShipPostalCode,
                ShipRegion     = order.ShipRegion,
                OrderDetails   = new HashSet <Models.OrderDetail>()
            };


            int sum = 0;

            foreach (var oneOrder in ModelOrder.OrderDetails)
            {
                oneOrder.OrderID   = order.OrderID;
                oneOrder.ProductID = order.ProductID[sum];
                oneOrder.Qty       = (short)order.Qty[sum];
                oneOrder.UnitPrice = (decimal)order.UnitPrice[sum];
                sum = sum + 1;
            }


            orderService.UpdateOrder(ModelOrder);
            ContentResult result = new ContentResult();

            result.Content = "更新成功";
            return(result);
        }
Beispiel #2
0
        public ActionResult Edit(int id)
        {
            OrderService orderService = new OrderService();

            ViewBag.Emps       = GetEmpSelect(orderService);
            ViewBag.ShipperIds = GetShipperSelect(orderService);
            ViewBag.Customers  = GetCustomerSelect(orderService);

            List <simpleSystem.ViewModels.OrderEditViewModels> models = orderService.GetOrderById(id);

            #region 加入detail
            List <Models.OrderDetail> orderDetailList = new List <Models.OrderDetail>();
            foreach (var tmp in models)
            {
                orderDetailList.Add(tmp.OrderDetail);
            }
            ViewBag.orderDetailList = orderDetailList;
            ViewBag.Products        = GetProductSelect(orderService);

            #endregion



            simpleSystem.ViewModels.OrderEditViewModels model = new simpleSystem.ViewModels.OrderEditViewModels()
            {
                CustID         = models[0].CustID,
                CustName       = models[0].CustName,
                EmpId          = models[0].EmpId,
                EmpName        = models[0].EmployeeFirstName + models[0].EmployeeLastName,
                Freight        = models[0].Freight,
                OrderDate      = models[0].OrderDate,
                OrderID        = models[0].OrderID,
                RequiredDate   = models[0].RequiredDate,
                ShipAddress    = models[0].ShipAddress,
                ShipCity       = models[0].ShipCity,
                ShipCountry    = models[0].ShipCountry,
                ShipName       = models[0].ShipName,
                ShippedDate    = models[0].ShippedDate,
                ShipperId      = models[0].ShipperId,
                ShipperName    = models[0].ShipperName,
                ShipPostalCode = models[0].ShipPostalCode,
                ShipRegion     = models[0].ShipRegion,
            };


            #region 處理date
            if (models[0].ShippedDate == null)
            {
                ViewBag.ShippedDateStr = "";
            }
            else
            {
                ViewBag.ShippedDateStr = ((DateTime)models[0].ShippedDate).ToString("yyyy-MM-dd");
            }

            ViewBag.OrderdateStr = ((DateTime)models[0].OrderDate).ToString("yyyy-MM-dd");

            ViewBag.RequiredDateStr = ((DateTime)models[0].RequiredDate).ToString("yyyy-MM-dd");
            #endregion

            return(View(model));
        }