Ejemplo n.º 1
0
        public ActionResult AddOrder(OrderNew model)
        {
            //TODO: Kiểm tra tính hợp lệ của dữ liệu được nhập
            if (string.IsNullOrEmpty(model.CustomerID))
            {
                ModelState.AddModelError("CustomerID", "CustomerID Expected");
            }
            if (model.EmployeeID == 0)
            {
                ModelState.AddModelError("EmployeeID", "EmployeeID Expected");
            }
            if (model.ShipperID == 0)
            {
                ModelState.AddModelError("ShipperID", "ShipperID Expected");
            }
            if (string.IsNullOrEmpty(model.ShipCountry))
            {
                ModelState.AddModelError("ShipCountry", "ShipCountry Expected");
            }

            if (model.OrderDate == null)
            {
                ModelState.AddModelError("OrderDate", "OrderDate Expected");
            }
            if (model.RequiredDate == null)
            {
                ModelState.AddModelError("RequiredDate", "RequiredDate Expected");
            }
            if (model.ShippedDate == null)
            {
                ModelState.AddModelError("ShippedDate", "ShippedDate Expected");
            }

            if (string.IsNullOrEmpty(model.Freight.ToString()))
            {
                model.Freight = 0;
            }
            if (string.IsNullOrEmpty(model.ShipAddress))
            {
                model.ShipAddress = "";
            }
            if (string.IsNullOrEmpty(model.ShipCity))
            {
                model.ShipCity = "";
            }

            if (!ModelState.IsValid)
            {
                ViewBag.Title = model.OrderID == 0 ? "Create new Order" : "Edit Order";
                return(View(model));
            }
            //TODO: Lưu dữ liệu vao DB


            if (model.OrderID == 0)
            {
                CatalogBLL.AddOrderNew(model);
            }

            return(RedirectToAction("Create"));
        }