public ActionResult Create(CreateOrder order) { if (ModelState.IsValid) { Orders newOrder = new Orders(); Int32 newOrderID = 0; using (MySqlConnection conn = DBUtils.GetConnection()) { CustomerRepository custRepo = new CustomerRepository(conn); Customer cust = custRepo.GetById(order.CustomerID); Users user = (Users)Session["User"]; newOrder.CustomerID = order.CustomerID; newOrder.ShipperID = order.ShipperID; newOrder.OrderDate = order.OrderDate; newOrder.RequiredDate = order.RequiredDate; newOrder.Freight = order.Freight; newOrder.UserID = user.UserID; newOrder.ShippedName = cust.CompanyName; newOrder.ShippedAddress = cust.Address; newOrder.ShippedCity = cust.City; newOrder.ShippedRegion = cust.Region; newOrder.ShippedPostalCode = cust.PostalCode; newOrder.ShippedCountry = cust.Country; OrderRepository orderRepo = new OrderRepository(conn); newOrderID = orderRepo.Save(newOrder); } return(RedirectToAction("Details", new { id = newOrderID })); } using (MySqlConnection conn = DBUtils.GetConnection()) { DisplayCustomerRepository cust = new DisplayCustomerRepository(conn); order.CustomerList = cust.GetAll().ToList <DisplayCustomer>(); DisplayShipperRepository shipper = new DisplayShipperRepository(conn); order.ShipperList = shipper.GetAll().ToList <DisplayShipper>(); //DisplayProductRepository product = new DisplayProductRepository(conn); //order.ProductList = product.GetAll().ToList<DisplayProduct>(); } return(View("Create", order)); }
public HttpResponseMessage Shippers() { try { List <DisplayShipper> shippers = new List <DisplayShipper>(); using (MySqlConnection conn = DBUtils.GetConnection()) { DisplayShipperRepository repo = new DisplayShipperRepository(conn); shippers = repo.GetAll().ToList <DisplayShipper>(); } return(Request.CreateResponse(HttpStatusCode.OK, shippers)); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.OK, ex.Message)); } }
// GET: Order/Create public ActionResult Create() { CreateOrder order = new CreateOrder(); using (MySqlConnection conn = DBUtils.GetConnection()) { DisplayCustomerRepository cust = new DisplayCustomerRepository(conn); order.CustomerList = cust.GetAll().ToList <DisplayCustomer>(); DisplayShipperRepository shipper = new DisplayShipperRepository(conn); order.ShipperList = shipper.GetAll().ToList <DisplayShipper>(); //DisplayProductRepository product = new DisplayProductRepository(conn); //order.ProductList = product.GetAll().ToList<DisplayProduct>(); } return(View(order)); }