Example #1
0
        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 Customers()
        {
            try
            {
                List <DisplayCustomer> customers = new List <DisplayCustomer>();
                using (MySqlConnection conn = DBUtils.GetConnection())
                {
                    DisplayCustomerRepository repo = new DisplayCustomerRepository(conn);
                    customers = repo.GetAll().ToList <DisplayCustomer>();
                }

                return(Request.CreateResponse(HttpStatusCode.OK, customers));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, ex.Message));
            }
        }
Example #3
0
        // 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));
        }